【问题标题】:Can't link GLFW in qtcreator无法在 qtcreator 中链接 GLFW
【发布时间】:2014-12-17 22:54:32
【问题描述】:

我想链接 GLFW。我已经安装了: sudo apt-get install cmake make g++ libx11-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxrandr-dev libxext-dev 然后我用 2 个子目录 build(cmake out source build)和 libs(用于外部库)创建目录。 从构建目录中,我使用命令“cmake ..”运行 cmake

主目录中的CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
project(MyProject) # project name

#version number
set(MyProject_Version_Major 1) #numer wersji glowny
set(MyProject_Version_Minor 0) #numer wydania

find_package(OpenGL REQUIRED)#when not found skip script

# add external subdirectory with another cmake file
add_subdirectory (libs)

include_directories(
libs/glfw-3.0.4/include/GLFW/
)

set(allLibs
${OPENGL_LIBRARY}
${GLFW_LIBRARIES}
)

add_executable(Manipulator main.cpp)

target_link_libraries(Manipulator ${allLibs})

libs 目录中的 CMakeLists.txt

GLFW

add_subdirectory (glfw-3.0.4)

include_directories(
glfw-3.0.4/include/GLFW/
)

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(OPENGL_LIBRARY
${OPENGL_LIBRARY}
${GLFW_LIBRARIES}
)

从官方文档中我得到了信息:

add_subdirectory(path/to/glfw) - 完成,主目录 CMakeList.txt

为了能够在您的代码中包含 GLFW 标头,您需要告诉 编译器在哪里找到它。

include_directories(path/to/glfw/include) 完成,主目录CMakeList.txt

将 GLFW 添加到项目后,GLFW_LIBRARIES 缓存 变量包含 GLFW 的所有链接时依赖项,因为它是 当前配置。要链接到 GLFW,链接到他们和 glfw 目标。

target_link_libraries(myapp glfw ${GLFW_LIBRARIES}) 完成,主目录 CMakeList.txt

请注意,GLFW_LIBRARIES 不包括 GLU,因为 GLFW 不使用 它。如果您的应用程序需要 GLU,您可以将其添加到 与 OPENGL_glu_LIBRARY 缓存变量的依赖关系,即 当 GLFW CMake 文件查找 OpenGL 时隐式创建。

target_link_libraries(myapp glfw ${OPENGL_glu_LIBRARY} 完成,主目录 CMakeList.txt ${GLFW_LIBRARIES})

仍然无法正常工作,出现以下错误:

错误:GLFW/glfw3.h:没有这样的文件或目录#include

我正在使用 QTCreator 3.0.1,Ubuntu 14.02 Ubuntu 14.04 lts。

在 QTCreator 中,我指定了主 CMakeLists.txt 目录,构建目录(与源不同) 构建目录 - 构建目录主目录/构建的路径 工作目录 - 主 CMakeLists.txt 目录的路径 运行配置:机械手

仍然无法正常工作。我在互联网上找到了工作示例,但我不理解它们(即他们创建了一些不知道为什么的指令)。

【问题讨论】:

  • 这是因为您已经包含了GLFW/ 前缀:include_directories(libs/glfw-3.0.4/include/GLFW/)。尝试使用include_directories(libs/glfw-3.0.4/include)

标签: opengl cmake qt-creator glfw


【解决方案1】:

现在可以了。

主 CMakeLists.txt

cmake_minimum_required(VERSION 2.6) #minimum CMake version
project(MyProject) #project name


set(MyProject_Version_Major 1) #project version
set(MyProject_Version_Minor 0) 


find_package(OpenGL REQUIRED) #find opengl library - stops when not found


add_subdirectory (libs) # add another directory to project(contain glfw library)

#include glfw
include_directories(
libs/glfw-3.0.4/include
)

# create variable to store all libraries
set(allLibs
${GLFW_LIBRARIES}
)


#create Manipulator executable from main.cpp file
add_executable(Manipulator main.cpp)


#links alllibs variable with my executable
target_link_libraries(Manipulator glfw ${allLibs})

libs 子目录中的 CMakeLists.txt。

### GLFW ###

add_subdirectory (glfw-3.0.4)

include_directories(
glfw-3.0.4/include/GLFW/
)

tl;博士-

我用这个: target_link_libraries(操纵器 ${allLibs}) 而不是这个: target_link_libraries(操纵器 glfw ${allLibs}) 忘记了 glfw 变量

【讨论】:

  • 像魅力一样工作!感谢您的自我回答。
猜你喜欢
  • 1970-01-01
  • 2013-05-06
  • 2021-09-01
  • 2013-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多