c++ - 在 GCC 和 OS X 中使用 SFML 时遇到问题

标签 c++ linker sfml

我一直在尝试让 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’

所以我认为这可能是由于没有使用 include,所以我将 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**

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

最佳答案

简答

添加 -arch i386(在 mac 上)或 -m32(在 linux 上)标志

长答案

您的 sfml-system 库是在 32 位中构建的,而您正试图在 64 位中编译您的程序。所以你的程序无法链接到库。

如果可能,在 64 位中重新编译 SFML,您应该能够在 64 位中编译您的程序。

关于c++ - 在 GCC 和 OS X 中使用 SFML 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10111680/

相关文章:

c++ - 在 std::map 中使用 std::auto_ptr 安全吗?

c - C 文件(库)与 clang 链接器的基本使用

c++ - C++ 中不熟悉的符号 [=]

c++ - 保存工作区 MFC C++ MDI

C++(Switch 语句中的类型错误)

c++ - 如何编写 Lambda 包装具有可选返回值的函数

c++ - 无法链接 mysql5.1.39\bin\libmySQL.dll

c++ - 从 Windows 上的 lib 文件中删除符号

opengl - 为什么具有 Opengl 3.0 上下文的 SFML 会绘制两次?

c++ - SFML RenderWindow 奇数字符