Question

I want to use the Ubunut/Linux Library libglfw (Glfw) with a Standard C++ Project, that uses CMake in Qt Creator. How do I do that? How do I have to include the Linked Library?

Edit: Actually I Include the libglfw (/usr/lib/lglfw.so) like

#include "GL/glfw.h" //That line works
int main(void) {
 GLFWwindow* window; //Just like in the GLFW-Example
 ...
}

And I get the error "GLFWwindow was not declared in this scope" and similar errors for each glfw-call

Was it helpful?

Solution

You just edit the CMakeLists.txt of your project like you would with any other CMake project. Qt Creator doesn't add any complexity on top of it.

For Glfw you should only have to add

FIND_PACKAGE (glfw REQUIRED)
INCLUDE_DIRECTORIES (${GLFW_INCLUDE_DIR})
TARGET_LINK_LIBRARIES (${PROJECT_NAME} ${GLFW_LIBRARY})

Note that that ${PROJECT_NAME} is the default that is added in Qt Creator, it just needs to be whatever the first parameter of the add_executable() call is (of course of the executable that you want to link glfw to).

after that you should be able to just grab the code example at the end of the getting started page of glfw and compile that within your project without a problem to test if it worked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top