I'm running into a linking error from cmake when I attempt to build my project in CLion. I've tried what the other threads said: Putting opengl last and glu first, changing the order of my includes and setting the cmake option GLEW_STATIC but none of them have fixed it or even given different errors.
I have used glew specifically compiled for mingw32 (From https://julianibarz.wordpress.com/2010/05/12/glew-1-5-4-mingw32/) and I have compiled GLEW myself but I still have the same problems..
Here is my CMake file:
cmake_minimum_required(VERSION 3.2)
project(3D_prototyping)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package (OpenGL REQUIRED)
if (WIN32)
else (WIN32)
find_package (glfw3 REQUIRED)
endif (WIN32)
set(SOURCE_FILES main.cpp)
add_executable(3D_prototyping ${SOURCE_FILES})
target_link_libraries (3D_prototyping
${GLFW3_LIBRARY}
${OPENGL_LIBRARIES}
${GLEW_LIBRARY}
${COCOA_LIBRARY} ${COREVID_LIBRARY} ${IOKIT_LIBRARY})
if (WIN32)
target_link_libraries (3D_prototyping
${OPENGL_LIBRARIES} glfw3 glu32 opengl32)
endif (WIN32)
This is the error I'm getting:
"C:\Program Files (x86)\JetBrains\CLion 1.0.3\bin\cmake\bin\cmake.exe" --build C:\Users\Max\.clion10\system\cmake\generated\1d24224\1d24224\Debug --target 3D_prototyping -- -j 4
Linking CXX executable 3D_prototyping.exe
CMakeFiles\3D_prototyping.dir/objects.a(main.cpp.obj): In function `Z9getShaderPKcj':
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:27: undefined reference to `_imp____glewCreateShader'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:30: undefined reference to `_imp____glewShaderSource'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:31: undefined reference to `_imp____glewCompileShader'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:35: undefined reference to `_imp____glewGetShaderiv'
CMakeFiles\3D_prototyping.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:75: undefined reference to `_imp____glewCreateProgram'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:76: undefined reference to `_imp____glewAttachShader'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:77: undefined reference to `_imp____glewAttachShader'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:78: undefined reference to `_imp____glewBindFragDataLocation'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:79: undefined reference to `_imp____glewLinkProgram'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:80: undefined reference to `_imp____glewUseProgram'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:83: undefined reference to `_imp____glewGetAttribLocation'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:84: undefined reference to `_imp____glewVertexAttribPointer'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:85: undefined reference to `_imp____glewEnableVertexAttribArray'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:89: undefined reference to `_imp____glewGenVertexArrays'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:90: undefined reference to `_imp____glewBindVertexArray'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:101: undefined reference to `_imp____glewGenBuffers'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:102: undefined reference to `_imp____glewBindBuffer'
C:/Users/Max/ClionProjects/3D prototyping/main.cpp:103: undefined reference to `_imp____glewBufferData'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [3D_prototyping.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/3D_prototyping.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/3D_prototyping.dir/rule] Error 2
mingw32-make.exe: *** [3D_prototyping] Error 2
CMakeFiles\3D_prototyping.dir\build.make:86: recipe for target '3D_prototyping.exe' failed
CMakeFiles\Makefile2:59: recipe for target 'CMakeFiles/3D_prototyping.dir/all' failed
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/3D_prototyping.dir/rule' failed
Makefile:108: recipe for target '3D_prototyping' failed
Fixed it.
Somewhere along the lines I had got glu32 which glew was using instead of the windows ones I compiled. Added a reference to glew32 and it worked fine.
Related
I'm just starting around with messing around with vulkan, and GLFW, but when I try to compile a test program, it gives me a bunch of linker errors:
/usr/bin/ld: CMakeFiles/vulkan_test.dir/loops.cpp.o: in function `Loops::Init()':
loops.cpp:(.text+0xd): undefined reference to `glfwInit'
/usr/bin/ld: loops.cpp:(.text+0x1c): undefined reference to `glfwWindowHint'
/usr/bin/ld: loops.cpp:(.text+0x2b): undefined reference to `glfwWindowHint'
/usr/bin/ld: loops.cpp:(.text+0x4f): undefined reference to `glfwCreateWindow'
/usr/bin/ld: CMakeFiles/vulkan_test.dir/loops.cpp.o: in function `Loops::Update()':
loops.cpp:(.text+0xa3): undefined reference to `glfwPollEvents'
/usr/bin/ld: CMakeFiles/vulkan_test.dir/loops.cpp.o: in function `Loops::DeInit()':
loops.cpp:(.text+0xcd): undefined reference to `glfwDestroyWindow'
/usr/bin/ld: loops.cpp:(.text+0xd2): undefined reference to `glfwTerminate'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/vulkan_test.dir/build.make:113: vulkan_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/vulkan_test.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
This is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.22)
project(vulkan_test)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH /home/headass/CMake_Modules/)
find_package(GLFW REQUIRED)
find_package(Vulkan REQUIRED)
include_directories(${GLFW_INCLUDE_DIRS} ${VULKAN_INCLUDE_DIRS})
add_executable(vulkan_test main.cpp loops.cpp)
target_link_libraries(vulkan_test ${GLFW_LIBRARIES} ${VULKAN_LIBRARIES})
Any idea why this is happening? I have both vulkan and GLFW installed, libglfw.so is in my /usr/lib/ directory, and clangd doesn't see anything wrong with it, but it still fails to link properly.
And yes, I HAVE tried googling this, to no avail.
Changing:
target_link_libraries(vulkan_test ${GLFW_LIBRARIES} ${VULKAN_LIBRARIES})
to:
target_link_libraries(vulkan_test glfw ${GLFW_LIBRARIES} ${VULKAN_LIBRARIES})
worked flawlessly
I have a project I want to build with CMake and compile with MinGW. The project uses Zlib. When I build with CMake I get no errors but then when I run MinGW Make it gives the following output:
C:\Projects\MultiMCBuild>C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe
.
.
.
[ 50%] Linking CXX shared library ..\libMultiMC_logic.dll
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x1f6c): undefined reference to 'z_inflateEnd'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x29e2): undefined reference to 'z_inflateInit2_'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x2a6d): undefined reference to 'z_get_crc_table'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x2ca7): undefined reference to 'z_inflateEnd'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x2f52): undefined reference to 'z_inflateInit2_'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x2f77): undefined reference to 'z_inflateEnd'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x3239): undefined reference to 'z_inflateInit2_'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x3317): undefined reference to 'z_inflateEnd'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x3626): undefined reference to 'z_crc32'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x371f): undefined reference to 'z_inflate'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x376a): undefined reference to 'z_crc32'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x3a57): undefined reference to 'z_inflateEnd'
C:/Qt/Tools/mingw492_32/bin/../lib/gcc/i686-w64- mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj): bad reloc address 0x20 in section `.eh_frame'
collect2.exe: error: ld returned 1 exit status
logic\CMakeFiles\MultiMC_logic.dir\build.make:3186: recipe for target 'libMultiMC_logic.dll' failed
mingw32-make[2]: * * * [libMultiMC_logic.dll] Error 1
CMakeFiles\Makefile2:1806: recipe for target 'logic/CMakeFiles/MultiMC_logic.dir/all' failed
mingw32-make[1]: * * * [logic/CMakeFiles/MultiMC_logic.dir/all] Error 2
makefile:159: recipe for target 'all' failed
mingw32-make: * * * [all] Error 2
Anyone have a clue what I can do to fix this? I read that the code can't find the ZLib library, how do I link it?
EDIT here is my CMakeLists.txt. I got this from the Git project.
I just tried to generate a small example to reproduce your errors. I took my test file from the home page of zlib http://zlib.net/zpipe.c
My initial CMakeLists.txt was
cmake_minimum_required(VERSION 3.4)
project(zlib_test)
set(ZLIB_TEST_SOURCES zpipe.c)
add_executable(${PROJECT_NAME} ${ZLIB_TEST_SOURCES})
And I got the same errors
[ 50%] Building C object CMakeFiles/zlib_test.dir/zpipe.c.o
[100%] Linking C executable zlib_test
CMakeFiles/zlib_test.dir/zpipe.c.o: In function `def':
zpipe.c:(.text+0x65): undefined reference to `deflateInit_'
zpipe.c:(.text+0xcd): undefined reference to `deflateEnd'
zpipe.c:(.text+0x135): undefined reference to `deflate'
zpipe.c:(.text+0x1cf): undefined reference to `deflateEnd'
zpipe.c:(.text+0x25d): undefined reference to `deflateEnd'
CMakeFiles/zlib_test.dir/zpipe.c.o: In function `inf':
zpipe.c:(.text+0x2eb): undefined reference to `inflateInit_'
zpipe.c:(.text+0x353): undefined reference to `inflateEnd'
zpipe.c:(.text+0x3a4): undefined reference to `inflate'
zpipe.c:(.text+0x404): undefined reference to `inflateEnd'
zpipe.c:(.text+0x476): undefined reference to `inflateEnd'
zpipe.c:(.text+0x4a6): undefined reference to `inflateEnd'
collect2: error: ld returned 1 exit status
make[2]: *** [zlib_test] Error 1
make[1]: *** [CMakeFiles/zlib_test.dir/all] Error 2
make: *** [all] Error 2
After changing CMakeLists.txt to this form
cmake_minimum_required(VERSION 3.4)
project(zlib_test)
find_package(ZLIB REQUIRED)
if (ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIRS})
endif()
set(ZLIB_TEST_SOURCES zpipe.c)
add_executable(${PROJECT_NAME} ${ZLIB_TEST_SOURCES})
target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES})
I could compile the program.
So your problem is: Where is ZLIB added in your CMakeLists.txt? At least, you need the line find_package(ZLIB REQUIRED).
I'm trying to build the SOCI library to run with PostgreSQL. I followed these steps:
Install PostgreSQL in Ubutu 15.10
Download SOCI source code
Extract SOCI code
I then run the following commands:
mkdir build
cd build
cmake -G "Unix Makefiles" -DWITH_BOOST=OFF -DWITH_POSTGRESQL=ON -DPOSTGRESQL_INCLUDE_DIR=/usr/local/pgsql/include -DPOSTGRESQL_LIBRARIES=/usr/local/pgsql/lib ../soci
At this point, CMake gave the following warnings:
WARNING: Target "soci_postgresql" requests linking to directory "/usr/local/pgsql/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "soci_postgresql_static" requests linking to directory "/usr/local/pgsql/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "soci_postgresql_test" requests linking to directory "/usr/local/pgsql/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "soci_postgresql_test" requests linking to directory "/usr/local/pgsql/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "soci_postgresql_test_static" requests linking to directory "/usr/local/pgsql/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "soci_postgresql_test_static" requests linking to directory "/usr/local/pgsql/lib". Targets may link only to libraries. CMake is dropping the item.
Persisting with the build, I then ran make, which fails with the following error:
[ 98%] Building CXX object tests/postgresql/CMakeFiles/soci_postgresql_test.dir/test-postgresql.cpp.o
Linking CXX executable ../../bin/soci_postgresql_test
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQresultStatus'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQgetvalue'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQclear'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQserverVersion'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQresultErrorMessage'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQexec'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_lseek'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQfsize'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQgetisnull'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQerrorMessage'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_open'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQexecPrepared'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQftype'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_close'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQexecParams'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQfname'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQconnectdb'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQstatus'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQntuples'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQresultErrorField'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQfformat'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_read'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQfinish'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQprepare'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_write'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQcmdTuples'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQnfields'
collect2: error: ld returned 1 exit status
tests/postgresql/CMakeFiles/soci_postgresql_test.dir/build.make:89: recipe for target 'bin/soci_postgresql_test' failed
make[2]: *** [bin/soci_postgresql_test] Error 1
CMakeFiles/Makefile2:609: recipe for target 'tests/postgresql/CMakeFiles/soci_postgresql_test.dir/all' failed
make[1]: *** [tests/postgresql/CMakeFiles/soci_postgresql_test.dir/all] Error 2
Makefile:126: recipe for target 'all' failed
make: *** [all] Error 2
Any idea what the cause of the CMake warnings and build error might be?
Try to call cmake with slightly different options
cmake -G "Unix Makefiles" -DWITH_BOOST=OFF -DWITH_POSTGRESQL=ON \
-DPOSTGRESQL_INCLUDE_DIR:STRING="/usr/local/pgsql/include" \
-DPOSTGRESQL_LIBRARIES:STRING="/usr/local/pgsql/lib" ../soci
I got the right answer from the github, here is link.
The following reply is largely taken from there, but repeated here for convenience (with cleanup and clarification):
-DPOSTGRESQL_LIBRARIES=/usr/local/psql/lib should point to the libraries, not directories.
This is what the following warning already highlights:
WARNING: Target "soci_postgresql" requests linking to directory
"/usr/local/postgresql/lib"
Try the following command instead (you may need to delete your CMakeCache.txt from the build directory first as well):
cmake -G "Unix Makefiles" -DWITH_BOOST=OFF -DWITH_POSTGRESQL=ON ../soci
On Linux systems where "postgresql-devel.x86_64 : PostgreSQL development header files and libraries" is installed, this command should be enough.
I am trying to build my project using CMake but I am having error linking required libraries. I have this CMakeLists.txt in the root folder of my project:
cmake_minimum_required(VERSION 2.6)
project(test)
add_subdirectory(src)
And in my src folder, alongside my source files I have this CMakeLists.txt:
set (CMAKE_CXX_FLAGS "Wall -std=c++11" )
set (CMAKE_EXE_LINKER_FLAGS "-lSDL2 -lGL" )
file (GLOB SRCS *.cpp *.h )
add_executable(engine ${SRCS} )
I then go into the build folder and do cmake .. and it runs without any errors. When I do make, the compilation runs without any errors as well, but when it gets to the linking part, I get these errors:
CMakeFiles/test.dir/Application.cpp.o: In function `Application::onExecute()':
Application.cpp:(.text+0x41): undefined reference to `SDL_GetTicks'
Application.cpp:(.text+0x4e): undefined reference to `SDL_GetTicks'
Application.cpp:(.text+0xd7): undefined reference to `SDL_PollEvent'
CMakeFiles/test.dir/Application.cpp.o: In function `Application::render()':
Application.cpp:(.text+0x17b): undefined reference to `glClearColor'
Application.cpp:(.text+0x185): undefined reference to `glClear'
Application.cpp:(.text+0x194): undefined reference to `SDL_GL_SwapWindow'
CMakeFiles/test.dir/Application.cpp.o: In function `Application::cleanUp()':
Application.cpp:(.text+0x1b2): undefined reference to `SDL_GL_DeleteContext'
Application.cpp:(.text+0x1c1): undefined reference to `SDL_DestroyWindow'
Application.cpp:(.text+0x1c6): undefined reference to `SDL_Quit'
CMakeFiles/test.dir/Application.cpp.o: In function `Application::initialize()':
Application.cpp:(.text+0x1de): undefined reference to `SDL_Init'
Application.cpp:(.text+0x1ea): undefined reference to `SDL_GetError'
Application.cpp:(.text+0x22b): undefined reference to `SDL_CreateWindow'
Application.cpp:(.text+0x243): undefined reference to `SDL_GetError'
Application.cpp:(.text+0x25a): undefined reference to `SDL_Quit'
Application.cpp:(.text+0x270): undefined reference to `SDL_GL_SetAttribute'
Application.cpp:(.text+0x27f): undefined reference to `SDL_GL_SetAttribute'
Application.cpp:(.text+0x28e): undefined reference to `SDL_GL_SetAttribute'
Application.cpp:(.text+0x29d): undefined reference to `SDL_GL_CreateContext'
Application.cpp:(.text+0x2af): undefined reference to `glGetString'
collect2: error: ld returned 1 exit status
make[2]: *** [src/test] Error 1
make[1]: *** [src/CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
I have the correct includes in my header files and I was able to compile and run using only make so I think the linker flags I tell CMake aren't being passed to the compiler. How can I fix this?
You have to use the cmake command target_link_libraries to reference SDL libs.
When I'm compiling the Triangle project from the opengl superbible 5th ed I've this code errors
> /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 ***
This is my 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)
What's the problem?
You are right, the errors are not from the compiler, they are from the linker. Since a lot of the undefined references are about glut functions, first verify that you can link glut properly. Have a look at this link - how to set up Glut.
Most likely you didn't include a header or the include directive in the makefile is wrong because the errors are pretty clear to me: the compiler can't find the core function of OpenGL which are included in the OpenGL headers.