1

我用 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&#41;

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 。但仍然出现“未定义的引用”错误。

我很高兴听到你们的任何反馈。干杯。

4

2 回答 2

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})
于 2013-07-22T12:29:45.997 回答
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
于 2013-07-22T20:22:38.457 回答