-1
我嘗試編譯一個在Ubuntu 16.04 x86_64上使用GLFW3庫的程序。我安裝了libglfw3
和libglfw3-dev
包。接下來,我寫CMakeLists.txt
:找不到GLFW函數
cmake_minimum_required (VERSION 2.6)
project (Test)
set (CMAKE_CXX_FLAGS "-lGL -lGLEW")
set (CMAKE_EXE_LINKER_FLAGS -lglfw)
add_executable(Test src/main.cpp)
而且main.cpp中:
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main() {
if (!glfwInit()) {
return -1;
}
glfwTerminate();
return 0;
}
但我從make
命令得到一個錯誤:
main.cpp:(.text+0x5): undefined reference to `glfwInit'
main.cpp:(.text+0x1a): undefined reference to `glfwTerminate'
collect2: error: ld returned 1 exit status
CMakeFiles/Test.dir/build.make:94: recipe for target 'Test' failed
make[2]: *** [Test] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Test.dir/all' failed
make[1]: *** [CMakeFiles/Test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
什麼我做錯了嗎?爲什麼找不到GLFW3?在CMake的與庫鏈接
你鏈接到GLEW庫嗎? – Zebrafish
我以爲這個字符串'set(CMAKE_EXE_LINKER_FLAGS -lglfw)'必須鏈接這個庫,它不是?只是我只學習CMake。我在Windows上使用了Visual Studio項目系統及其編譯器。 –
您在Ubuntu上編譯了GLFW庫,但您試圖在Windows Visual Studio中運行該程序? – Zebrafish