2016-02-03 98 views
0

我試圖用GLFW和GLEW編寫一個簡單的程序,雖然我可以成功地添加所需的GLFW庫,我不能做與GLEW的相同。 我對CMAKE完全陌生,所以我不知道我應該做什麼不同。我使用CLion btw。提前致謝!GLEW將不能與CMAKE

cmake_minimum_required(VERSION 3.3) 
project(OpenGLHelloWorld) 

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 

set(SOURCE_FILES main.cpp) 
add_executable(OpenGLHelloWorld ${SOURCE_FILES}) 

add_subdirectory(../glfw-3.1.2 ${CMAKE_CURRENT_BINARY_DIR}/glfw_bin) 
include_directories(../glfw-3.1.2/include) 
target_link_libraries(OpenGLHelloWorld glfw ${GLFW_LIBRARIES}) 

ADD_DEFINITIONS(-DGLEW_STATIC) 
include_directories(../glew-1.13.0/include) 
link_libraries(../glew-1.13.0/lib) 

而且cpp文件:

#include <GL/glew.h> 
#include <GLFW/glfw3.h> 
#include <stdio.h> 

using namespace std; 

int main() { 
    if(!glewInit()) { 
     fprintf(stderr, "Could not start GLFW3\n"); 
    } 

    return 0; 
} 

和錯誤:

undefined reference to `[email protected]' 
collect2.exe: error: ld returned 1 exit status 
CMakeFiles\OpenGLHelloWorld.dir\build.make:97: recipe for target 'OpenGLHelloWorld.exe' failed 
mingw32-make.exe[3]: *** [OpenGLHelloWorld.exe] Error 1 
mingw32-make.exe[2]: *** [CMakeFiles/OpenGLHelloWorld.dir/all] Error 2 
mingw32-make.exe[1]: *** [CMakeFiles/OpenGLHelloWorld.dir/rule] Error 2 
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/OpenGLHelloWorld.dir/all' failed 
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/OpenGLHelloWorld.dir/rule' failed 
Makefile:161: recipe for target 'OpenGLHelloWorld' failed 
mingw32-make.exe: *** [OpenGLHelloWorld] Error 2 

回答

0

你沒有鏈接已編譯的代碼GLEW。

target_link_libraries(OpenGLHelloWorld glfw ${GLFW_LIBRARIES} GLEW) 

這應該修復glew lib鏈接到您的可執行文件。

HTH。