tôi có mã đơn giản này:cờ cmake cho OpenGL sử dụng glew và glfw
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glfw.h>
int main(int argc, char const* argv[])
{
if(!glfwInit()){
fprintf(stderr, "failed\n");
}
return 0;
}
và trong CmakeLists.txt tôi:
PROJECT(test C)
find_package(OpenGL)
ADD_DEFINITIONS(
-std=c99
-lGL
-lGLU
-lGLEW
-lglfw
)
SET(SRC test)
ADD_EXECUTABLE(test ${SRC})
chạy "cmake." không tạo ra bất kỳ lỗi, nhưng chạy chắc sẽ nói:
test.c:(.text+0x10): undefined reference to `glfwInit'
collect2: ld returned 1 exit status
make[2]: *** [tut1] Error 1
khi chạy:
gcc -o test test.c -std=c99 -lGL -lGLU -lGLEW -lglfw
biên dịch thành công mã không có lỗi. Làm thế nào để tôi làm cho cmake chạy với mã của tôi?
cũng có, nếu tôi thêm những dòng này để các chức năng chính:
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
thậm chí chạy gcc với những lá cờ cùng sẽ tạo ra lỗi:
test.c: In function ‘main’:
test.c:14: error: ‘GLFW_OPENGL_VERSION_MAJOR’ undeclared (first use in this function)
test.c:14: error: (Each undeclared identifier is reported only once
test.c:14: error: for each function it appears in.)
test.c:15: error: ‘GLFW_OPENGL_VERSION_MINOR’ undeclared (first use in this function)
test.c:16: error: ‘GLFW_OPENGL_PROFILE’ undeclared (first use in this function)
test.c:16: error: ‘GLFW_OPENGL_CORE_PROFILE’ undeclared (first use in this function)
tôi đang chạy bạc hà linux dựa trên kubuntu 10.04, cmake v2.8, libglfw-dev, libglfw2, libglew1.5, libglew1.5-dev, glew-utils.
Tôi mới tham gia cmake, glew và glfw. Cảm ơn sự giúp đỡ của các bạn!
cổ vũ!
P
cảm ơn lời giải thích. sẽ cung cấp cho nó một thử – pixelblender