我刚刚用MinGW和Cmake安装了Qt Creator。我正在尝试使用OpenGL。 到目前为止,我得到了这段代码:
#include <GLFW/glfw3.h>
int main()
{
if (!glfwInit()) {
return -1;
}
return 0;
}
我的CMakeLists.txt是这样的:
cmake_minimum_required(VERSION 2.8)
project(world_0)
aux_source_directory(. SRC_LIST)
file(GLOB SRC_LIST *.cpp)
find_package(GLFW3 REQUIRED)
include_directories(F:/u_qt/libs/glfw/glfw-3.0.1/include)
link_directories(F:/u_qt/libs/glfw/glfw-3.0.1/lib-mingw)
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} glfw3)
我已经从"FindGLFW3.make"添加了FindGLFW3.cmake。但仍然有'未定义的引用'错误。
我很高兴听到你们的任何反馈。欢呼声。
答案 0 :(得分:1)
从您链接到的FindGLFW3.cmake文件中,看起来CMakeLists.txt的后半部分应该更改为:
find_package(GLFW3 REQUIRED)
include_directories(${GLFW3_INCLUDE_PATH})
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${GLFW3_LIBRARY})
答案 1 :(得分:0)
有点不安:
Users with less than 10 reputation can't answer their own question for 8 hours after asking.
但它来了。我将CMakeLists.txt更改为:
cmake_minimum_required(VERSION 2.8)
project(world_0)
aux_source_directory(. SRC_LIST)
file(GLOB SRC_LIST *.cpp)
find_package(GLFW3 REQUIRED)
set(GLFW3_INCLUDE_PATH F:/u_qt/libs/glfw/glfw-3.0.1/include)
set(GLFW3_LIBRARY F:/u_qt/libs/glfw/glfw-3.0.1/lib-mingw/glfw3dll.a)
include_directories(${GLFW3_INCLUDE_PATH})
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${GLFW3_LIBRARY})
并使用代码:
#include <GLFW/glfw3.h>
int main()
{
if (!glfwInit()) {
return -1;
}
GLFWwindow* window = glfwCreateWindow(640, 480, "World", NULL, NULL);
if (!window) {
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window)) {
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
我得到了:
Starting F:\u_qt\projects\world_0-build\world_0.exe...
The program has unexpectedly finished.
F:\u_qt\projects\world_0-build\world_0.exe exited with code -1073741515