Error connecting with g ++

I am trying to compile and link my application in 2 steps:

Compilation:

g ++ -c -o file1.o file1.cc general_header.h
g ++ -c -o file2.o file2.cc general_header.h
g ++ -c -o file3.o file3.cc general_header.h

Linking:

g ++ -o myApp file1.o file2.o file3.o

I am getting the error:

file1.o: file not recognized: file format not recognized
collect2: ld returned 1 exit status

Am I doing something wrong?

thanks

+2


a source to share


2 answers


No need to include header files in the list of input files



g++ -c -o file1.o file1.cc

+2


a source


You don't have to mention your header file on the command line - you don't want to compile it directly, but only if it's included in your source files. also, I would give the compiler the name of the object files, since it is too easy to make a typo explicitly. So your compilation commands should look like this:

g++ -c file1.cc 

      



and you can also say:

g++ -c file1.cc file2.cc file3.cc

      

+3


a source







All Articles