G++警告:针对不受支持的文件格式构建,该文件格式不是正在链接的体系结构

发布于 2024-10-07 17:19:31 字数 810 浏览 0 评论 0原文

每当我尝试编译我的项目(使用命令行 g++ *.hpp *.cpp 2> log.txt)时,我都会得到:

log.txt:

ld: warning: in configfile.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in erase.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in filehandler.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in insert.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in operation.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)

Any为什么会发生这种情况?我使用的是 OSX 10.6(使用最新的开发人员工具)

Whenever I try to compile my project (with the command line g++ *.hpp *.cpp 2> log.txt), that's what I get:

log.txt:

ld: warning: in configfile.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in erase.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in filehandler.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in insert.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in operation.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)

Any ideas of why this is happening? I'm under OSX 10.6 (using latest Developer Tools)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌逼全场 2024-10-14 17:19:31

您正在编译头文件 (.hpp),但您还不应该这样做。仅编译源文件 (.cpp)

与其编译所有 .cpp 文件,不如一次编译一个文件,然后适当地链接它们。

g++ -c x.cpp
g++ -c y.cpp
g++ -c z.cpp

g++ -o tst x.o y.o z.o

请注意,只有一个 .cpp 文件可以具有 main() 函数 - 否则操作系统将不知道入口点在哪里。

You're compiling header files (.hpp) which you shouldn't do yet. Only compile source files (.cpp)

Rather than compiling all .cpp files, compile them one at a time and then link them appropriately.

g++ -c x.cpp
g++ -c y.cpp
g++ -c z.cpp

g++ -o tst x.o y.o z.o

Note that only one of your .cpp files can have a main() function - otherwise the OS won't know where the entry point is.

飘过的浮云 2024-10-14 17:19:31

我没有 Mac,所以我会向您提供 Linux 版本,告诉您发生这种情况时该怎么做。

查找 gcc 的 multilib 版本并使用 -m32 开关重新编译

g++ *.hpp *.cpp -m32

试试这个。您可以使用 gcc 编译头文件以生成预编译头。

I do not own a Mac so I'm kind of giving you the Linux version of what to do when this happens.

Look for a multilib version of gcc and recompile with the -m32 switch

g++ *.hpp *.cpp -m32

Try this. You CAN compile header files with gcc to produce pre-compiled headers.

罪#恶を代价 2024-10-14 17:19:31

g++ 参数 -arch i386 应该可以满足您的要求:

g++ *.hpp *.cpp -m32 -arch i386

这是正确的吗?

The g++ parameter -arch i386 should do the trick for you:

g++ *.hpp *.cpp -m32 -arch i386

Is that correct?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文