将库导入 QTCreator

Importing Libraries into QTCreator

我正在 QT Creator 中创建一个 OpenGL 项目,并希望稍后导入 GLFW 和可能的其他库。 我编译并导入了 GLFW,并能够通过 #include <GLFW/glfw3.h>

Qt Creator 甚至能够自动填充 glfw 方法。但是,当我试图调用其中之一时(例如 glfwInit();,编译器向我抛出以下错误:

 Undefined symbols for architecture x86_64:
  "_CFArrayAppendValue", referenced from:
      _addJoystickElement in libglfw3.a(iokit_joystick.m.o)
  "_CFArrayApplyFunction", referenced from:
      __glfwInitJoysticks in libglfw3.a(iokit_joystick.m.o)
      _addJoystickElement in libglfw3.a(iokit_joystick.m.o)
  "_CFArrayCreateMutable", referenced from: 

...等等

我假设它无法找到这些方法的实现。

我通过以下过程导入了 GLFW:

1。我使用 CMake 构建了一个 Unix 脚本。
2。我在终端上 运行 "make" 生成的 makefile。这创建了一个名为 "libglfw3.a"
3 的文件。我通过QT将库导入到项目中,将库设置为libglfw3.a并包含路径为"mypath/include/"(此文件夹包含另一个名为GLFW的文件夹,其中包含glfw3.h)。

QT Creator 然后将以下内容输入到 QT 项目文件中。

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/glfw-3.1.1/src/release/ -lglfw3
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/glfw-3.1.1/src/debug/ -lglfw3
else:unix: LIBS += -L$$PWD/glfw-3.1.1/src/ -lglfw3
INCLUDEPATH += $$PWD/glfw-3.1.1/include
DEPENDPATH += $$PWD/glfw-3.1.1/include
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/release/libglfw3.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/debug/libglfw3.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/release/glfw3.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/debug/glfw3.lib
else:unix: PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/libglfw3.a

将不胜感激。我花了至少 10 个小时试图弄清楚如何将 GL 库导入 QT Creator,但我能找到的只有 XCode、Visual Studio 等的 CMake 教程。

理想情况下,我希望通过修改 QT .pro 文件来实现这一点,因为我没有使用 CMake 的经验,但如果没有其他选择,那也没关系。 我正在 Mac 10.10.15.

上使用 QT creator 进行开发

如果有人好奇,我想通了。

我按照这里的程序操作:Compiling with GLFW3, linker errors 'undefined reference'

起初我不认为这有什么关系,因为它专门指的是在 XCode 上构建,但事实证明您必须使用 QT Creator 做完全相同的事情。 右键单击项目,导入库 -> System/Library/Frameworks -> 并导入 Cocoa、CoreVideo 和 IOKit。

我的 .pro 文件在我完成所有操作后添加了以下行

mac: LIBS += -framework Cocoa
else:unix|win32: LIBS += -lCocoa

mac: LIBS += -framework IOKit
else:unix|win32: LIBS += -lIOKit

mac: LIBS += -framework CoreVideo else:unix|win32: LIBS += -lCoreVideo