ld:找不到框架SFML

时间:2018-11-02 17:13:13

标签: compiler-errors g++ sfml

我将Frameworks的内容从SFML复制到〜/ Library / Frameworks,并尝试在SFML中运行第一个教程示例。 我在g ++中使用了它:

g++ -o sfml-test.cpp -framework SFML -lsfml-window

并收到此错误:

ld: framework not found SFML

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

首先,本教程指定/Library/Frameworks不是 ~/Library/Frameworks~指向用户主目录(/Users/name/),而/指向文件系统的最低点。

此外,despite the documentation/Library/Frameworks也不是标准框架目录,因此您必须在搜索路径中进行设置。您可以通过运行gcc -Xlinker -v来查看标准框架目录:

@(#)PROGRAM:ld  PROJECT:ld64-409.12
BUILD 17:47:51 Sep 25 2018
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em arm64e arm64_32
Library search paths:
    /usr/local/lib
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib
Framework search paths:
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

请注意Framework search paths部分,其中不包含/Library/Frameworks

要将/Library/Frameworks添加到搜索路径,请使用-F/Library/Frameworks进行编译并使用-F/Library/Frameworks -framework SFML -framework sfml-x进行链接,x为systemwindowgraphicsaudionetwork

此外,-o选项指定输出文件名。您的命令将不输入任何文件并输出可执行文件sfml-test.cpp,因此使用-o sfml-test sfml-test.cppsfml-test.cpp用作输入,然后输出sfml-test

您的命令将是:

g++ -o sfml-test sfml-test.cpp -F/Library/Frameworks -framework SFML -framework sfml-window