當我從OpenGL的OpenGL超級第五版編譯三角項目我有這個代碼中的錯誤未定義的引用編譯的OpenGL
> /home/fpointbin/projects/Triangle/build> make
[ 7%] Building CXX object CMakeFiles/gltools.dir/src/GLBatch.cpp.o
[ 15%] Building CXX object CMakeFiles/gltools.dir/src/GLShaderManager.cpp.o
[ 23%] Building CXX object CMakeFiles/gltools.dir/src/GLTools.cpp.o
[ 30%] Building CXX object CMakeFiles/gltools.dir/src/GLTriangleBatch.cpp.o
[ 38%] Building CXX object CMakeFiles/gltools.dir/src/math3d.cpp.o
[ 46%] Building C object CMakeFiles/gltools.dir/src/glew.c.o
Linking CXX shared library libgltools.so
[ 46%] Built target gltools
Scanning dependencies of target gltools-static
[ 53%] Building CXX object CMakeFiles/gltools-static.dir/src/GLBatch.cpp.o
[ 61%] Building CXX object CMakeFiles/gltools-static.dir/src/GLShaderManager.cpp.o
[ 69%] Building CXX object CMakeFiles/gltools-static.dir/src/GLTools.cpp.o
[ 76%] Building CXX object CMakeFiles/gltools-static.dir/src/GLTriangleBatch.cpp.o
[ 84%] Building CXX object CMakeFiles/gltools-static.dir/src/math3d.cpp.o
[ 92%] Building C object CMakeFiles/gltools-static.dir/src/glew.c.o
Linking CXX static library libgltools.a
[ 92%] Built target gltools-static
Linking CXX executable triangle
CMakeFiles/triangle.dir/main.cpp.o: In function `ChangeSize(int, int)':
/home/fpointbin/projects/Triangle/main.cpp:22: undefined reference to `glViewport'
CMakeFiles/triangle.dir/main.cpp.o: In function `SetupRC()':
/home/fpointbin/projects/Triangle/main.cpp:32: undefined reference to `glClearColor'
/home/fpointbin/projects/Triangle/main.cpp:34: undefined reference to `GLShaderManager::InitializeStockShaders()'
/home/fpointbin/projects/Triangle/main.cpp:41: undefined reference to `GLBatch::Begin(unsigned int, unsigned int, unsigned int)'
/home/fpointbin/projects/Triangle/main.cpp:43: undefined reference to `GLBatch::End()'
CMakeFiles/triangle.dir/main.cpp.o: In function `RenderScene()':
/home/fpointbin/projects/Triangle/main.cpp:53: undefined reference to `glClear'
/home/fpointbin/projects/Triangle/main.cpp:56: undefined reference to `GLShaderManager::UseStockShader(GLT_STOCK_SHADER, ...)'
/home/fpointbin/projects/Triangle/main.cpp:57: undefined reference to `GLBatch::Draw()'
/home/fpointbin/projects/Triangle/main.cpp:60: undefined reference to `glutSwapBuffers'
CMakeFiles/triangle.dir/main.cpp.o: In function `main':
/home/fpointbin/projects/Triangle/main.cpp:68: undefined reference to `gltSetWorkingDirectory(char const*)'
/home/fpointbin/projects/Triangle/main.cpp:70: undefined reference to `glutInit'
/home/fpointbin/projects/Triangle/main.cpp:71: undefined reference to `glutInitDisplayMode'
/home/fpointbin/projects/Triangle/main.cpp:72: undefined reference to `glutInitWindowSize'
/home/fpointbin/projects/Triangle/main.cpp:73: undefined reference to `glutCreateWindow'
/home/fpointbin/projects/Triangle/main.cpp:74: undefined reference to `glutReshapeFunc'
/home/fpointbin/projects/Triangle/main.cpp:75: undefined reference to `glutDisplayFunc'
/home/fpointbin/projects/Triangle/main.cpp:77: undefined reference to `glewInit'
/home/fpointbin/projects/Triangle/main.cpp:79: undefined reference to `glewGetErrorString'
/home/fpointbin/projects/Triangle/main.cpp:85: undefined reference to `glutMainLoop'
CMakeFiles/triangle.dir/main.cpp.o: In function `__static_initialization_and_destruction_0':
/home/fpointbin/projects/Triangle/main.cpp:14: undefined reference to `GLBatch::GLBatch()'
/home/fpointbin/projects/Triangle/main.cpp:14: undefined reference to `GLBatch::~GLBatch()'
/home/fpointbin/projects/Triangle/main.cpp:15: undefined reference to `GLShaderManager::GLShaderManager()'
/home/fpointbin/projects/Triangle/main.cpp:15: undefined reference to `GLShaderManager::~GLShaderManager()'
CMakeFiles/triangle.dir/main.cpp.o: In function `GLBatch::CopyVertexData3f(float*)':
/home/fpointbin/projects/Triangle/include/GLBatch.h:89: undefined reference to `GLBatch::CopyVertexData3f(float (*) [3])'
collect2: ld returned 1 exit status
make[2]: *** [triangle] Error 1
make[1]: *** [CMakeFiles/triangle.dir/all] Error 2
make: *** [all] Error 2
*** Failed ***
這是我Cmakelist.txt:
cmake_minimum_required (VERSION 2.6)
project(triangle)
find_package(X11)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
find_library(M_LIBRARY m)
find_library(GLEW_LIBRARY GLEW)
set (INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/include"
${INCLUDE_DIRS}
)
include_directories (
${INCLUDE_DIRS}
)
if(UNIX)
set (INCLUDE_DIRS
"/usr/include"
"/usr/local/include"
"/usr/include/GL"
${INCLUDE_DIRS}
)
endif(UNIX)
set (GLTOOLS_HDRS
"${CMAKE_SOURCE_DIR}/include/GLBatchBase.h"
"${CMAKE_SOURCE_DIR}/include/GLBatch.h"
"${CMAKE_SOURCE_DIR}/include/GLFrame.h"
"${CMAKE_SOURCE_DIR}/include/GLFrustum.h"
"${CMAKE_SOURCE_DIR}/include/GLGeometryTransform.h"
"${CMAKE_SOURCE_DIR}/include/GLMatrixStack.h"
"${CMAKE_SOURCE_DIR}/include/GLShaderManager.h"
"${CMAKE_SOURCE_DIR}/include/GLTools.h"
"${CMAKE_SOURCE_DIR}/include/GLTriangleBatch.h"
"${CMAKE_SOURCE_DIR}/include/math3d.h"
"${CMAKE_SOURCE_DIR}/include/StopWatch.h"
"${CMAKE_SOURCE_DIR}/include/glew.h"
)
set (GLTOOLS_SRCS
"${CMAKE_SOURCE_DIR}/src/GLBatch.cpp"
"${CMAKE_SOURCE_DIR}/src/GLShaderManager.cpp"
"${CMAKE_SOURCE_DIR}/src/GLTools.cpp"
"${CMAKE_SOURCE_DIR}/src/GLTriangleBatch.cpp"
"${CMAKE_SOURCE_DIR}/src/math3d.cpp"
"${CMAKE_SOURCE_DIR}/src/glew.c"
)
add_library (gltools-static ${GLTOOLS_SRCS})
add_library (gltools SHARED ${GLTOOLS_SRCS})
target_link_libraries (gltools ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${GLEW_LIBRARY} ${M_LIBRARY} ${X11_LIBRARIES})
target_link_libraries (gltools-static ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${GLEW_LIBRARY} ${M_LIBRARY} ${X11_LIBRARIES})
set_target_properties(gltools-static PROPERTIES OUTPUT_NAME gltools)
add_executable(triangle main.cpp)
有什麼問題?
那些不是編譯器錯誤。 –