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.
Related
I couldn't compile my program which uses MagickWand with CMake. I'm getting this error:
[ 33%] Linking CXX executable bin/ScreenRecorder
/usr/bin/ld: CMakeFiles/ScreenRecorder.dir/source/main.cpp.o: in function `std::thread::thread<void (&)(), , void>(void (&)())':
main.cpp:(.text._ZNSt6threadC2IRFvvEJEvEEOT_DpOT0_[_ZNSt6threadC5IRFvvEJEvEEOT_DpOT0_]+0x20): undefined reference to `pthread_create'
/usr/bin/ld: CMakeFiles/ScreenRecorder.dir/source/screenshot.cpp.o: in function `printScrn(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
screenshot.cpp:(.text+0xd): undefined reference to `MagickWandGenesis'
/usr/bin/ld: screenshot.cpp:(.text+0x1a): undefined reference to `NewMagickWand'
/usr/bin/ld: screenshot.cpp:(.text+0x31): undefined reference to `MagickReadImage'
/usr/bin/ld: screenshot.cpp:(.text+0x4f): undefined reference to `MagickWriteImage'
/usr/bin/ld: screenshot.cpp:(.text+0x62): undefined reference to `DestroyMagickWand'
/usr/bin/ld: screenshot.cpp:(.text+0x6b): undefined reference to `MagickWandTerminus'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/ScreenRecorder.dir/build.make:99: bin/ScreenRecorder] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/ScreenRecorder.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
This is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(ScreenRecorder)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall")
set(source_dir "${PROJECT_SOURCE_DIR}/source/")
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/bin/")
find_package(ImageMagick REQUIRED)
include_directories(
"/usr/include/ImageMagick-6/"
)
link_libraries(
"/usr/lib/x86_64-linux-gnu/"
)
file (GLOB src_files "${source_dir}*.cpp")
add_executable(ScreenRecorder ${src_files})
I tried using variables such as ${ImageMagick_MagickWand_INCLUDE_DIR} and ${ImageMagick_MagickWand_LIBS_DIR} but it says that "wand/MagickWand.h" not found.
Thanks for your answers.
I was able to resolve a similar issue by enclosing the auto-generated variables in quotes:
INCLUDE_DIRECTORIES(
"${ImageMagick_INCLUDE_DIRS}"
)
TARGET_LINK_LIBRARIES(MyProject
"${ImageMagick_LIBRARIES}"
)
The reason that this resolved the issue is that the variables are CMake lists.
Without quotes, they are concatenated to a long string:
MESSAGE(${ImageMagick_INCLUDE_DIRS})
MESSAGE(${ImageMagick_LIBRARIES})
->
1> [CMake] /usr/include/ImageMagick-6/usr/include/x86_64-linux-gnu/ImageMagick-6
1> [CMake] /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.so
However, with quotes, the different elements of the list are separated using a semicolon:
MESSAGE("${ImageMagick_INCLUDE_DIRS}")
MESSAGE("${ImageMagick_LIBRARIES}")
->
1> [CMake] /usr/include/ImageMagick-6;/usr/include/x86_64-linux-gnu/ImageMagick-6
1> [CMake] /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.so
Hi i wanted to compile restbed as a static lib with examples but I have a linker error.
using : ubuntu 16.04 gcc-5.4
What i did:
cd dependency/openssl
./config
*long text*
Configured for linux-x86_64.
*** Because of configuration changes, you MUST do the following before
*** building:
make depend
so i did make depend and make. It made libcrypto.a and libssl.a
So i think this part is ok??
Next
cd build
cmake -DBUILD_TESTS=YES -DBUILD_EXAMPLES=YES -DBUILD_SSL=YES -DBUILD_SHARED=NO -DCMAKE_INSTALL_PREFIX=static ..
Copyright 2013-2017, Corvusoft Ltd, All Rights Reserved.
-- Found ASIO include at: /home/jova/git/restbed/dependency/asio/asio/include
-- Found Kashmir include at: /home/jova/git/restbed/dependency/kashmir
-- Found OpenSSL library at: /home/jova/git/restbed/dependency/openssl/libssl.a
-- Found OpenSSL include at: /home/jova/git/restbed/dependency/openssl/include
-- Found Crypto library at: /home/jova/git/restbed/dependency/openssl/libcrypto.a
-- Failed to locate PAM, skipping example.
-- Found Syslog include at: /usr/include
-- Found Catch include at: /home/jova/git/restbed/dependency/catch/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jova/git/restbed/build-static
jova:~/git/restbed/build-static$ make -j4 install
[ 0%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/uri.cpp.o
[ 0%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/rule.cpp.o
[ 0%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/string.cpp.o
[ 1%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/http.cpp.o
[ 1%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/request.cpp.o
[ 2%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/service.cpp.o
[ 2%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/session.cpp.o
[ 2%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/resource.cpp.o
[ 2%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/response.cpp.o
[ 3%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/settings.cpp.o
[ 3%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/web_socket.cpp.o
[ 3%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/ssl_settings.cpp.o
[ 4%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/session_manager.cpp.o
[ 4%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/detail/http_impl.cpp.o
[ 4%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/web_socket_message.cpp.o
[ 5%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/detail/socket_impl.cpp.o
[ 5%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/detail/service_impl.cpp.o
[ 5%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/detail/session_impl.cpp.o
[ 6%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/detail/web_socket_impl.cpp.o
[ 6%] Building CXX object CMakeFiles/restbed.dir/source/corvusoft/restbed/detail/web_socket_manager_impl.cpp.o
[ 6%] Linking CXX static library librestbed.a
[ 6%] Built target restbed
[ 6%] Building CXX object example/CMakeFiles/https_client_verify_peer.dir/https_client/source/verify_peer.cpp.o
[ 6%] Building CXX object example/CMakeFiles/web_socket.dir/web_socket/source/example.cpp.o
[ 7%] Building CXX object example/CMakeFiles/https_service.dir/https_service/source/example.cpp.o
[ 7%] Building CXX object example/CMakeFiles/signal_handling.dir/signal_handling/source/example.cpp.o
[ 7%] Linking CXX executable example/signal_handling
[ 7%] Linking CXX executable example/https_client_verify_peer
[ 7%] Linking CXX executable example/https_service
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x11): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x2f): undefined reference to `dlclose'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x334): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x3db): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x454): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x4fb): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x569): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x5cb): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x603): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x69f): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0x709): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x762): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
example/CMakeFiles/signal_handling.dir/build.make:97: recipe for target 'example/example/signal_handling' failed
make[2]: *** [example/example/signal_handling] Error 1
CMakeFiles/Makefile2:297: recipe for target 'example/CMakeFiles/signal_handling.dir/all' failed
make[1]: *** [example/CMakeFiles/signal_handling.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x11): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x2f): undefined reference to `dlclose'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x334): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x3db): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x454): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x4fb): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x569): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x5cb): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x603): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x69f): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0x709): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x762): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
example/CMakeFiles/https_client_verify_peer.dir/build.make:97: recipe for target 'example/example/https_client_verify_peer' failed
make[2]: *** [example/example/https_client_verify_peer] Error 1
CMakeFiles/Makefile2:223: recipe for target 'example/CMakeFiles/https_client_verify_peer.dir/all' failed
make[1]: *** [example/CMakeFiles/https_client_verify_peer.dir/all] Error 2
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x11): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x2f): undefined reference to `dlclose'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x334): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x3db): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x454): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x4fb): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x569): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x5cb): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x603): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x69f): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0x709): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x762): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
example/CMakeFiles/https_service.dir/build.make:97: recipe for target 'example/example/https_service' failed
make[2]: *** [example/example/https_service] Error 1
CMakeFiles/Makefile2:260: recipe for target 'example/CMakeFiles/https_service.dir/all' failed
make[1]: *** [example/CMakeFiles/https_service.dir/all] Error 2
[ 8%] Linking CXX executable example/web_socket
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x11): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x2f): undefined reference to `dlclose'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x334): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x3db): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x454): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x4fb): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x569): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x5cb): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x603): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x69f): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0x709): undefined reference to `dlerror'
../../dependency/openssl/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x762): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
example/CMakeFiles/web_socket.dir/build.make:97: recipe for target 'example/example/web_socket' failed
make[2]: *** [example/example/web_socket] Error 1
CMakeFiles/Makefile2:186: recipe for target 'example/CMakeFiles/web_socket.dir/all' failed
make[1]: *** [example/CMakeFiles/web_socket.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
It finds the libs so I dont know how to fix the problem.
Update : i installed ssl and crypto libs with
sudo apt-get install libssl-dev
cmake -DBUILD_TESTS=YES -DBUILD_EXAMPLES=YES -DBUILD_SSL=YES -DCMAKE_INSTALL_PREFIX=static ..
Now it works, but when i want to compile an example with https support i still need to link it with -lssl and -lcrypto but that is probably because the ssl and crypto are shared libs.
g++ -std=c++11 -I/home/jova/git/restbed/build/static/include https_service.cpp -L/home/jova/git/restbed/build/static/library -lrestbed -lssl -lcrypto -pthread
How can i get ssl support into the restbed.a static library? Or will i always have to link with ssl and crypto?
I'm confused what does this option -DBUILD_SSL=YES/NO do?
Your issue looks to be a linking problem. Try adding -ldl.
dlopen and friends
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 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.
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.