g++: fatal error: cannot specify -o with -c, -S or -E with multiple files

前端 未结 2 901
灰色年华
灰色年华 2020-12-19 04:39

I am trying to compile a library file using other library files. I am using the following line in my makefile to create gameobject.o:

lib/gameobject.o: src/g         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-19 05:08

    You're not building a library file here. A .o file is an object file. Typically there is one object file per source file. When you use the compiler's -c option, it takes a single source file and compiles it into a single object file. You cannot add other object files into an existing object file, so adding both .o and .cpp files into the same compiler line with -c is not going to work.

    If you want to create a library, that would be something like libfoo.a (the "a" here stands for "archive"). If you want to create an executable you can do that as well.

    You need to be more clear about exactly what result you want before we can describe how to get it.

提交回复
热议问题