【问题标题】:Linker error with GLFW on OS 10.10OS 10.10 上 GLFW 的链接器错误
【发布时间】:2016-07-05 05:00:12
【问题描述】:

我正在尝试编译以下内容

#include <GLFW/glfw3.h>

int main()
{
    glfwInit();
    return 0;
}

只是为了验证我的 GLFW 安装是否正常。我使用终端与

clang++ -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo -I/opt/local/include/ test.c

但我收到 glfwInit 函数的链接器错误:

Undefined symbols for architecture x86_64:
  "_glfwInit", referenced from:
      _main in test-d8c21e.o
ld: symbol(s) not found for architecture x86_64

我已经使用sudo port install glfw 安装了 glfw,并按照我找到的所有可能的教程进行操作。我可以验证libglfw.dylib 文件是否可以在/opt/local/lib/ 上找到(我认为)。

有什么建议吗?

【问题讨论】:

    标签: opengl glfw


    【解决方案1】:

    您还需要与 GLFW[3] 链接,例如,添加: -L/opt/local/lib -lglfw3

    如果您安装了pkgconfig 端口,您还可以通过以下方式利用它:

    clang `pkg-config glfw3 --cflags` test.c -o test \
    `pkg-config glfw3 --static --libs`
    

    如果您有:libglfw3.dylib,则可能不需要--static 标志,而不是使用:libglfw3.a,但这并没有什么坏处。

    【讨论】:

    • 啊,我以为我试过了,但我使用了 -I/opt/local/lib 而不是 -L。干杯!
    【解决方案2】:

    如果您使用 Xcode,则在链接二进制文件时必须添加 libglfw3.a 库。

    这就是诀窍

    1. 显示隐藏文件夹。将此粘贴到终端:默认写入 com.apple.finder AppleShowAllFiles YES
    2. 重新启动查找器窗口并导航到 Macintosh HD\usr
    3. 将 usr 文件夹拖到终端的“收藏夹”一侧
    4. 在 xcode 中,单击添加“+”链接二进制文件,然后单击“添加其他”
    5. 导航到 libglfw3.a 并添加它!

    如果它仍然不起作用,这里有一些对我有帮助的说明。

    https://engineering-game-dev.com/2013/08/14/glfw-compiling-source-and-creating-an-xcode-project/comment-page-1/#comment-1400

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-26
      • 2014-08-12
      • 1970-01-01
      • 2014-03-27
      • 2017-06-12
      • 2015-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多