g++ output: file not recognized: File format not recognized

后端 未结 3 1402
名媛妹妹
名媛妹妹 2020-12-10 10:12

I am trying to build program with multiple files for the first time. I have never had any problem with compliling program with main.cpp only. With following commands, this i

3条回答
  •  醉酒成梦
    2020-12-10 10:48

    This is wrong:

     g++ -c src/CNumber.cpp src/CNumber.h -o src/CNumber.o
    

    You shouldn't "compile" .h files. Doing so will create precompiled header files, which are not used to create an executable. The above should simply be

     g++ -c src/CNumber.cpp -o src/CNumber.o
    

    Similar for compiling the other .cpp files

提交回复
热议问题