g++:致命错误:不能将 -o 与 -c、-S 或 -E 指定为多个文件 [英] g++: fatal error: cannot specify -o with -c, -S or -E with multiple files

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

问题描述

我正在尝试使用其他库文件编译库文件.我在我的 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/separating 编译还是有点陌生​​,所以我不太确定我应该做什么.我是否只需要编译它而不设置输出?我是否必须在不使用任何其他 .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++:致命错误:不能将 -o 与 -c、-S 或 -E 指定为多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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