3

我一直在尝试让 SFML 工作一段时间,并且一直在尝试使用 GCC 让它工作。顺便说一句,我在 OS X 上。我遵循标准的 Linux 说明并使用 Linux 64 位下载,但是在编译时...

g++ -o testing main.cpp -lsfml-system

有时候是这样的:

main.cpp: In function ‘int main()’:
main.cpp:7: error: ‘class sf::Clock’ has no member named ‘GetElapsedTime’
main.cpp:9: error: ‘class sf::Clock’ has no member named ‘GetElapsedTime’
main.cpp:10: error: ‘Sleep’ is not a member of ‘sf’

所以我认为这可能是由于没有使用包含,所以我将我的 gcc 编译命令更改为:

 g++ -o testing main.cpp -I ~/SFML-1.6/include/ -lsfml-system

现在我收到了这个错误:

ld: warning: ignoring file /usr/local/lib/libsfml-system.so, file was built for     unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
  "sf::Clock::Clock()", referenced from:
      _main in ccZEiB7b.o
  "sf::Clock::GetElapsedTime() const", referenced from:
      _main in ccZEiB7b.o
  "sf::Sleep(float)", referenced from:
      _main in ccZEiB7b.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status**

而且我不知道该怎么做才能解决它。

4

2 回答 2

2

Short answer

Add the -arch i386 (on mac) or -m32 (on linux) flag

Long answer

Your sfml-system library was built in 32 bits whereas you are trying to compile your program in 64 bits. So your program cannot link to the library.

Recompile SFML in 64 bits if possible and you should be able to compile your program in 64 bits.

于 2012-04-11T18:25:50.623 回答
0

SFML 希望你在 OS X 上使用框架。打开 SFML 文件夹,将 lib64 下的所有文件夹复制到 /Library/Frameworks(即,将 SFML.framework、sfml-system.framework 等复制到 /Library/Frameworks)。

安装框架后,您可以通过将 -framework 命令传递给 g++ 来使用它们,如下所示:

g++ -o testing main.cpp -framework SFML -framework sfml-system
于 2012-04-11T23:25:40.703 回答