g ++:致命错误:无法使用-c,-S或-E来指定多个文件的-o [英] g++: fatal error: cannot specify -o with -c, -S or -E with multiple files

查看:1129
本文介绍了g ++:致命错误:无法使用-c,-S或-E来指定多个文件的-o的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用其他库文件来编译库文件.我在我的Makefile中使用以下行来创建gameobject.o:

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/gameobject.cpp src/vector.hpp lib/objectevent.o lib/sprite.o
g++ $^ -c -o $@ $(SFML_FLAGS)

所有依赖项都能正确编译,但是在尝试编译gameobject.o时出现以下错误:

All the dependencies comile correctly, but I get the following error when it tries to compile gameobject.o:

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

我对使用make/separation编译还是有点陌生​​,所以我不确定应该怎么做.我是否只需要编译而不设置输出?我是否必须不使用任何其他.o文件来编译gameobject.o?如果是这样,如果您不能与其他库一起编译库,那么对于大型对象而言,编译时间会不会变得很大?还是我只是读这个错误完全错误?

I'm still a bit new to using make/separating compilation, so I'm not quite sure what I should do. Do I just have to compile it without setting an output? Do I have to compile gameobject.o without using any of my other .o files? If that's true, wouldn't compile times get pretty big for large objects if you can't compile libraries with other libraries? Or am I just reading this error completely wrong?

推荐答案

您不是在此处构建库文件. .o文件是目标文件.通常,每个源文件只有一个目标文件.使用编译器的-c选项时,它将使用一个源文件并将其编译为一个目标文件.您不能将其他目标文件添加到现有目标文件中,因此将.o.cpp文件都添加到使用-c的同一编译器行中将无法正常工作.

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.

如果要创建库,则类似于libfoo.a(此处的"a"代表存档").如果要创建可执行文件,也可以这样做.

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.

这篇关于g ++:致命错误:无法使用-c,-S或-E来指定多个文件的-o的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆