G++警告:针对不受支持的文件格式构建,该文件格式不是正在链接的体系结构
每当我尝试编译我的项目(使用命令行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在编译头文件 (.hpp),但您还不应该这样做。仅编译源文件 (.cpp)
与其编译所有 .cpp 文件,不如一次编译一个文件,然后适当地链接它们。
请注意,只有一个 .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.
Note that only one of your .cpp files can have a main() function - otherwise the OS won't know where the entry point is.
我没有 Mac,所以我会向您提供 Linux 版本,告诉您发生这种情况时该怎么做。
查找 gcc 的 multilib 版本并使用 -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
Try this. You CAN compile header files with gcc to produce pre-compiled headers.
g++ 参数
-arch i386
应该可以满足您的要求:这是正确的吗?
The g++ parameter
-arch i386
should do the trick for you:Is that correct?