问题
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 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 in libs catalog
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}
)
From official documentation I got information:
add_subdirectory(path/to/glfw) - done, main catalog CMakeList.txt
To be able to include the GLFW header from your code, you need to tell the compiler where to find it.
include_directories(path/to/glfw/include) done, main catalog CMakeList.txt
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}) done, main catalog CMakeList.txt
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} done, main catalog CMakeList.txt ${GLFW_LIBRARIES})
Still don't working, got following error:
error: GLFW/glfw3.h: No such file or directory #include
I'm using QTCreator 3.0.1, Ubuntu 14.02 Ubuntu 14.04 lts.
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).
回答1:
Now it's works.
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})
CMakeLists.txt in libs subdirectory.
### GLFW ###
add_subdirectory (glfw-3.0.4)
include_directories(
glfw-3.0.4/include/GLFW/
)
tl;dr -
I use this: target_link_libraries(Manipulator ${allLibs}) instead of this: target_link_libraries(Manipulator glfw ${allLibs}) Forgot glfw variable
来源:https://stackoverflow.com/questions/27536364/cant-link-glfw-in-qtcreator