Thursday 15 August 2013

c++ - include class and compile with g++ -



c++ - include class and compile with g++ -

im beginner in c++ , working unix. here question.

i`ve written few lines in main-function, , needed function, defined in c_lib - library.

main.cpp:

#include <iostream> #include "c_lib.cpp" int main() { homecoming 0; }

i want execute on terminal, wrote

g++ -c c_lib.cpp g++ -c main.cpp g++ -o run c_lib.o main.o

until here, there no error report.

then

./run

i error

error: ./run: no such file or directory

what's wrong?

including .cpp not done, headers included. headers contain declarations define interface code in other .cpp can show source of c_lib? may help.

as source of c_lib #included, there no need compile seperately. in fact can/will cause errors (multiple definitions beingness first come mind). should need do:

g++ -o run main.cpp

to compile code in case. (when using header (.h), need compile implementation (.cpp) seperately)

compile warnings turned on:

g++ -wall -wextra -o run main.cpp

and more output if there problems code.

is run file beingness output gcc? can test calling ls in terminal (or ls run show executable if present).

if executable present, isn't marked runnable. i'll go if problem outside general scope of site (though still related)

c++

No comments:

Post a Comment