在 Mac OSX 10.7 上用 C++ 链接 WXWidgets 对象不起作用

在 Mac OSX 10.7 上用 C++ 链接 WXWidgets 对象不起作用

对于跨平台项目,我们使用 wxwidgets 在 c++ 中创建跨平台 GUI。WxWidgets 使用 macports 安装在 Mac OSX 10.7 上。我们在 Linux 和 Windows 上编译源代码没有任何问题。

在 Mac 上编译不同的类可以正常工作。但是,当我们尝试链接对象时,我们收到以下错误/警告:

ld: warning: ignoring file ../../obj/games.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file ../../obj/lobby.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file ../../obj/ConfigFile.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file ../../obj/net.o, file was built for unsupported file format which is not the architecture being linked (i386)
 ld: warning: ignoring file ../../obj/protocol.o, file was built for unsupported file format which is not the architecture being linked (i386)
Undefined symbols for architecture i386:
 "_main", referenced from:
    start in crt1.10.6.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

看起来 gcc 无法链接文件。当我们想一次编译和链接一个文件时,我们会得到一个可以运行的程序。由于我们现在有多个想要链接的文件,因此我们无法一次完成此操作。我们使用以下 makefile:

https://github.com/timvdalen/OGO-2.3/blob/master/src/lobby/Makefile

我们的源代码也包含在那里。我使用以下版本的 gcc:

gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

有人知道我们如何链接这些文件吗?

答案1

我已经自己找到了答案:你必须使用 进行编译g++ -arch i386。链接器似乎只想在 32 位模式下链接。

相关内容