G ++警告:为不受支持的文件格式构建,而不是链接的体系结构

时间:2010-12-17 05:11:51

标签: c++ architecture g++ x86-64 darwin

每当我尝试编译我的项目时(使用命令行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)

有关为何发生这种情况的任何想法?我在OSX 10.6下(使用最新的开发者工具)

3 个答案:

答案 0 :(得分:3)

你正在编译你不应该做的头文件(.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()函数 - 否则操作系统将无法知道入口点的位置。

答案 1 :(得分:0)

我没有Mac,所以当你发生这种情况时,我会向你提供Linux版本。

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

g++ *.hpp *.cpp -m32

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

答案 2 :(得分:0)

g ++参数-arch i386应该可以解决这个问题:

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

这是对的吗?