无法在Qtcreator中链接GLFW [英] Can't link GLFW in qtcreator

查看:393
本文介绍了无法在Qtcreator中链接GLFW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想链接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源代码生成)和libs(用于外部库)的目录. 从构建目录中,我使用命令"cmake .."运行cmake.

I want to link GLFW. I already installed: sudo apt-get install cmake make g++ libx11-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxrandr-dev libxext-dev Then I create catalog with 2 sub catalogs build(cmake out source build) and libs(for external libraries). from build catalog I run cmake with command "cmake .."

主目录中的CMakeLists.txt

CMakeLists.txt in main catalog

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})

库目录中的

CMakeLists.txt

CMakeLists.txt in libs catalog

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}
)

从官方文档中我可以获得信息:

From official documentation I got information:

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

add_subdirectory(path/to/glfw) - done, main catalog CMakeList.txt

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

To be able to include the GLFW header from your code, you need to tell the compiler where to find it.

include_directories(路径/到/glfw/include)已完成,主目录CMakeList.txt

include_directories(path/to/glfw/include) done, main catalog CMakeList.txt

一旦将GLFW添加到项目中,则GLFW_LIBRARIES缓存 变量按原样包含GLFW的所有链接时相关性 当前配置.要链接到GLFW,请链接到他们和 glfw目标.

Once GLFW has been added to the project, the GLFW_LIBRARIES cache variable contains all link-time dependencies of GLFW as it is currently configured. To link against GLFW, link against them and the glfw target.

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

target_link_libraries(myapp glfw ${GLFW_LIBRARIES}) done, main catalog CMakeList.txt

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

Note that GLFW_LIBRARIES does not include GLU, as GLFW does not use it. If your application needs GLU, you can add it to the list of dependencies with the OPENGL_glu_LIBRARY cache variable, which is implicitly created when the GLFW CMake files look for OpenGL.

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

target_link_libraries(myapp glfw ${OPENGL_glu_LIBRARY} done, main catalog CMakeList.txt ${GLFW_LIBRARIES})

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

Still don't working, got following error:

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

error: GLFW/glfw3.h: No such file or directory #include

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

I'm using QTCreator 3.0.1, Ubuntu 14.02 Ubuntu 14.04 lts.

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

In QTCreator I specified the main CMakeLists.txt directory, build directory (different then source) Build directory - path to build directory main catalog/build Working directory - path to main CMakeLists.txt directory Run configoration: Manipulator

仍然不起作用.我在互联网上找到了有效的示例,但我不理解它们(即它们创建了一些指令,不知道为什么).

And still don't working. I found working examples on internet but I don't understand them( i.e. they create some directives no idea why).

推荐答案

现在可以使用了.

主要CMakeLists.txt

Main 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.

CMakeLists.txt in libs subdirectory.

### GLFW ###

add_subdirectory (glfw-3.0.4)

include_directories(
glfw-3.0.4/include/GLFW/
)

tl; dr-

我用这个: target_link_libraries(机械手$ {allLibs}) 而不是这样: target_link_libraries(机械手glfw $ {allLibs}) 忘记了glfw变量

I use this: target_link_libraries(Manipulator ${allLibs}) instead of this: target_link_libraries(Manipulator glfw ${allLibs}) Forgot glfw variable

这篇关于无法在Qtcreator中链接GLFW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆