Link SDL and Glut in CMake - c++

I have a project (on linux) where I require glut and SDL.
I already managed to properly link glut, but I still cant get SDL linked.
My CMake file looks like this:
cmake_minimum_required(VERSION 3.7)
project(ObjLoader)
add_executable(testas main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} )
target_link_libraries(testas ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
When building the following exception is error occurs:
/opt/JetBrains/apps/CLion/ch-0/181.4668.70/bin/cmake/bin/cmake --build /home/void/Documents/Projects/ObjLoader/cmake-build-debug --target testas -- -j 2
[ 50%] Linking CXX executable testas
CMakeFiles/testas.dir/main.cpp.o: In function `main':
/home/user/Documents/Projects/ObjLoader/main.cpp:165: undefined reference to `SDL_Init'
/home/user/Documents/Projects/ObjLoader/main.cpp:166: undefined reference to `SDL_SetVideoMode'
/home/user/Documents/Projects/ObjLoader/main.cpp:173: undefined reference to `SDL_GetTicks'
/home/user/Documents/Projects/ObjLoader/main.cpp:174: undefined reference to `SDL_PollEvent'
/home/user/Documents/Projects/ObjLoader/main.cpp:184: undefined reference to `SDL_GL_SwapBuffers'
/home/user/Documents/Projects/ObjLoader/main.cpp:188: undefined reference to `SDL_GetTicks'
/home/user/Documents/Projects/ObjLoader/main.cpp:189: undefined reference to `SDL_GetTicks'
/home/user/Documents/Projects/ObjLoader/main.cpp:189: undefined reference to `SDL_Delay'
/home/user/Documents/Projects/ObjLoader/main.cpp:191: undefined reference to `SDL_Quit'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/testas.dir/build.make:100: testas] Error 1
make[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/testas.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/testas.dir/rule] Error 2
make: *** [Makefile:118: testas] Error 2
but the same problem persists,
When I try to link it as described here: How to use SDL2 and SDL_image with cmake
the same problem persists. How can I properly include and link SDL in the CMake file above?
My attempt was this:
cmake_minimum_required(VERSION 3.7)
project(ObjLoader)
add_executable(testas main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
find_package(SDL2 REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} ${SDL2_INCLUDE_DIRS})
target_link_libraries(testas ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${SDL2_LIBRARIES})
Doesnt change anything, same problem.

Related

CMAKE C++ MXE(x86_64-w64-mingw32.static-g++) Cross Compile libCURL from Ubuntu to Windows

I am working on trying to get a cross compile setup for making windows applications using ubuntu as a development platform.
I have WxWidgets working with help of a previous post. I am now trying to get libCURL working. I need to get CMAKE to find the linker options for CURL.
I CAN cross compile simple CURL code using: ~/mxe/usr/bin/x86_64-w64-mingw32.static-g++ -DCURL_STATICLIB main.cpp -o winmain $(~/mxe/usr/bin/x86_64-w64-mingw32.static-curl-config --cflags) $(~/mxe/usr/bin/x86_64-w64-mingw32.static-curl-config --libs)
This is great! I can compile a single file! But, now how to do this with CMAKE?
I have attempted this:
cmake_minimum_required(VERSION 3.11)
SET (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
SET(PROJECT_NAME "WxWidgets")
SET(CMAKE_C_COMPILER x86_64-w64-mingw32.static)
SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32.static-g++)
project(
${PROJECT_NAME}
VERSION 1.0)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lstdc++ -static")
file(GLOB all_SRCS
"${PROJECT_SOURCE_DIR}/src/*.h"
"${PROJECT_SOURCE_DIR}/src/*.hpp"
"${PROJECT_SOURCE_DIR}/src/*.c"
"${PROJECT_SOURCE_DIR}/src/*.cpp"
"${PROJECT_SOURCE_DIR}/src/**/*.c"
"${PROJECT_SOURCE_DIR}/src/**/*.cpp"
"${PROJECT_SOURCE_DIR}/src/**/*.hpp"
)
add_executable(${PROJECT_NAME} ${all_SRCS})
set(CMAKE_C_FLAGS "~/mxe/usr/bin/x86_64-w64-mingw32.static-curl-config")
include( "${wxWidgets_USE_FILE}" )
find_package(wxWidgets REQUIRED)
target_include_directories(${PROJECT_NAME} PUBLIC ~/mxe/usr/i686-w64-mingw32.static/lib/ /home/kevin/mxe/usr/i686-w64-mingw32.static/include/wx-3.1/ /home/kevin/mxe/usr/i686-w64-mingw32.static/lib/wx/include/i686-w64-mingw32.static-msw-unicode-static-3.1/)
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES} ~/mxe/usr/bin/x86_64-w64-mingw32.static-curl-config)
However, still get the linker errors:
[ 25%] Linking CXX executable WxWidgets.exe
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x541): undefined reference to `_imp__curl_global_init'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x547): undefined reference to `_imp__curl_easy_init'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x551): undefined reference to `_imp__curl_easy_setopt'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x593): undefined reference to `_imp__curl_easy_perform'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x5ae): undefined reference to `_imp__curl_easy_cleanup'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x5bb): undefined reference to `_imp__curl_global_cleanup'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x635): undefined reference to `_imp__curl_easy_strerror'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/WxWidgets.dir/build.make:141: WxWidgets.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/WxWidgets.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
kevin#kevin-CF-33S-1:~/source/repos/cpp/aiCamCPPClientApp/build$ make
[ 25%] Linking CXX executable WxWidgets.exe
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x541): undefined reference to `_imp__curl_global_init'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x547): undefined reference to `_imp__curl_easy_init'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x551): undefined reference to `_imp__curl_easy_setopt'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x593): undefined reference to `_imp__curl_easy_perform'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x5ae): undefined reference to `_imp__curl_easy_cleanup'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x5bb): undefined reference to `_imp__curl_global_cleanup'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x635): undefined reference to `_imp__curl_easy_strerror'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/WxWidgets.dir/build.make:141: WxWidgets.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/WxWidgets.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
And here another attempt (possibly closer?):
cmake_minimum_required(VERSION 3.11)
SET (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
SET(PROJECT_NAME "WxWidgets")
SET(CMAKE_C_COMPILER i686-w64-mingw32.static)
SET(CMAKE_CXX_COMPILER i686-w64-mingw32.static-g++)
project(
${PROJECT_NAME}
VERSION 1.0)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lstdc++ -DCURL_STATICLIB -static")
file(GLOB all_SRCS
"${PROJECT_SOURCE_DIR}/src/*.h"
"${PROJECT_SOURCE_DIR}/src/*.hpp"
"${PROJECT_SOURCE_DIR}/src/*.c"
"${PROJECT_SOURCE_DIR}/src/*.cpp"
"${PROJECT_SOURCE_DIR}/src/**/*.c"
"${PROJECT_SOURCE_DIR}/src/**/*.cpp"
"${PROJECT_SOURCE_DIR}/src/**/*.hpp"
)
add_executable(${PROJECT_NAME} ${all_SRCS})
include( "${wxWidgets_USE_FILE}" )
find_package(wxWidgets REQUIRED)
find_package(CURL REQUIRED)
include_directories("~/mxe/usr/i686-w64-mingw32.static/lib/")
target_include_directories(${PROJECT_NAME} PUBLIC ~/mxe/usr/i686-w64-mingw32.static/lib/ /home/kevin/mxe/usr/i686-w64-mingw32.static/include/wx-3.1/ /home/kevin/mxe/usr/i686-w64-mingw32.static/lib/wx/include/i686-w64-mingw32.static-msw-unicode-static-3.1/)
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
this results in a smaller error set:
[ 25%] Building CXX object CMakeFiles/WxWidgets.dir/src/GUIFrame.cpp.obj
[ 50%] Building CXX object CMakeFiles/WxWidgets.dir/src/aiCamClientAppApp.cpp.obj
[ 75%] Building CXX object CMakeFiles/WxWidgets.dir/src/aiCamClientAppMain.cpp.obj
[100%] Linking CXX executable WxWidgets.exe
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x540): undefined reference to `curl_global_init'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x545): undefined reference to `curl_easy_init'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x564): undefined reference to `curl_easy_setopt'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x57f): undefined reference to `curl_easy_setopt'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x58a): undefined reference to `curl_easy_perform'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x5a4): undefined reference to `curl_easy_cleanup'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x5b0): undefined reference to `curl_global_cleanup'
/home/kevin/mxe/usr/bin/i686-w64-mingw32.static-ld: CMakeFiles/WxWidgets.dir/objects.a(aiCamClientAppApp.cpp.obj):aiCamClientAppApp.cpp:(.text+0x624): undefined reference to `curl_easy_strerror'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/WxWidgets.dir/build.make:141: WxWidgets.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/WxWidgets.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
I am now wondering if my problems stem from hardcoding my directories, and if my paths aren't correctly setup and this may be causing issues with CMAKE being able to resolve the files for linking?
If anyone has any ideas about how to implement this in CMAKE correctly, it would greatly appreciate the help!
Thanks you very much!
-Kevin

Can not link yaml-cpp with my cmake project

My CMakeLists.txt
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(test_includes)
#find_package(Boost COMPONENTS system filesystem REQUIRED)
#include_directories( ${Boost_INCLUDE_DIRS} )
set(Torch_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libtorch/share/cmake/Torch")
find_package(Boost COMPONENTS system filesystem REQUIRED)
find_package(Threads REQUIRED)
find_package(Torch REQUIRED)
find_package(yaml-cpp REQUIRED)
include_directories( ${Boost_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
${yaml-cpp_INCLUDE_DIR}
${Torch_INCLUDE_DIRS}
include)
set(CMAKE_CXX_FLAGS_DEBUG "-g3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g3 -gdwarf -fno-omit-frame-pointer -DNDEBUG")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
add_subdirectory(include)
#link_directories(libraries)
set( LIBS_TO_LINK
Domains
Agents
Planning
yaml-cpp
${TORCH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT})# -llapack)
add_executable(testWarehouse testWarehouse.cpp)
target_link_libraries(testWarehouse ${LIBS_TO_LINK})
The error message i am getting:
...
[100%] Linking CXX executable testWarehouse
/usr/bin/ld: CMakeFiles/testWarehouse.dir/testWarehouse.cpp.o: in function `WarehouseSimulation(std::string const&, unsigned long)':
testWarehouse.cpp:(.text+0x13af): undefined reference to `YAML::LoadFile(std::string const&)'
/usr/bin/ld: CMakeFiles/testWarehouse.dir/testWarehouse.cpp.o: in function `YAML::detail::node_ref::set_scalar(std::string const&)':
testWarehouse.cpp:(.text._ZN4YAML6detail8node_ref10set_scalarERKSs[_ZN4YAML6detail8node_ref10set_scalarERKSs]+0x2a): undefined reference to `YAML::detail::node_data::set_scalar(std::string const&)'
/usr/bin/ld: CMakeFiles/testWarehouse.dir/testWarehouse.cpp.o: in function `YAML::Node::Scalar() const':
testWarehouse.cpp:(.text._ZNK4YAML4Node6ScalarEv[_ZNK4YAML4Node6ScalarEv]+0x79): undefined reference to `YAML::detail::node_data::empty_scalar()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/testWarehouse.dir/build.make:109: testWarehouse] Error 1
make[1]: *** [CMakeFiles/Makefile2:152: CMakeFiles/testWarehouse.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
note: i do have yamp-cpp installed
my full project:
i have tried manually adding -lyaml-cpp to the compile commands, with no effect.
can someone please check my CMakeLists.txt and tell my if am linking yaml-cpp properly, Thanks. (i am 99% sure that it is correct)
i have tried yaml-cpp versions 7.0, 6.3, 5.3 all with the same result
looking at .../build/CMakeCache.txt it includes:
//The directory containing a CMake configuration file for yaml-cpp.
yaml-cpp_DIR:PATH=/usr/share/cmake/yaml-cpp
which looks correct to me
if you need any more info please ask
Thank you
it was pre C++11 ABI issue
the solution can be found at:
https://github.com/pytorch/pytorch/issues/19353#issuecomment-652314883

CMake & CodeSynthesis Header-only library not compiling

I have been trying to implement the runtime library which is a header-only library of CodeSynthesis. But I only get a linking compiling error whenever I try to run the generated files which are made by the XSD executable.
Here is the error to show you that I have a linking problem with the runtime library:
[100%] Linking CXX executable XercesGebeuren.exe
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\XercesGebeuren.dir/objects.a(hello.cxx.obj): in function `xsd::cxx::xml::initialize()':
C:/Users/husey/Desktop/XercesGebeuren/xsd-4.0.0-i686-windows/libxsd/xsd/cxx/xml/elements.hxx:84: undefined reference to `xercesc_3_2::XMLPlatformUtils::Initialize(char const*, char const*, xercesc_3_2::PanicHandler*, xercesc_3_2::MemoryManager*)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\XercesGebeuren.dir/objects.a(hello.cxx.obj): in function `xsd::cxx::xml::terminate()':
C:/Users/husey/Desktop/XercesGebeuren/xsd-4.0.0-i686-windows/libxsd/xsd/cxx/xml/elements.hxx:90: undefined reference to `xercesc_3_2::XMLPlatformUtils::Terminate()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\XercesGebeuren.dir/objects.a(hello.cxx.obj): in function `xsd::cxx::xml::sax::std_input_stream::std_input_stream(std::istream&)':
C:/Users/husey/Desktop/XercesGebeuren/xsd-4.0.0-i686-windows/libxsd/xsd/cxx/xml/sax/std-input-source.hxx:27: undefined reference to `xercesc_3_2::BinInputStream::BinInputStream()'
---- [And so on] ----
collect2.exe: error: ld returned 1 exit status
mingw32-make[3]: *** [CMakeFiles\XercesGebeuren.dir\build.make:122: XercesGebeuren.exe] Error 1
mingw32-make[2]: *** [CMakeFiles\Makefile2:95: CMakeFiles/XercesGebeuren.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:102: CMakeFiles/XercesGebeuren.dir/rule] Error 2
mingw32-make: *** [Makefile:137: XercesGebeuren] Error 2
I have followed the guide given by CodeSynthesis to generate my hello.cxx & hello.hxx files with the command: xsd cxx-tree --std c++11 hello.xsd
CMake
cmake_minimum_required(VERSION 3.17)
project(XercesGebeuren)
set(CMAKE_CXX_STANDARD 20)
set(Xsd_DIR ./cmake)
find_package(XercesC REQUIRED)
find_package(Xsd REQUIRED)
add_executable(XercesGebeuren main.cpp src/hello.cxx)
add_library(mylib INTERFACE)
target_include_directories(mylib PUBLIC INTERFACE "./libxsd/")
target_include_directories(XercesGebeuren PUBLIC ${XSD_INCLUDE_DIR})
target_link_libraries(XercesGebeuren PUBLIC mylib)
Thanks to 'Asteroids With Wings' I figured out that a header-only library should not be added as a library in CMake.
Including the library and linking the XercesC library was enough.
CMake solution
cmake_minimum_required(VERSION 3.17)
project(XercesGebeuren)
set(CMAKE_CXX_STANDARD 20)
set(Xsd_DIR ./cmake)
find_package(XercesC REQUIRED)
find_package(Xsd REQUIRED)
add_executable(XercesGebeuren main.cpp src/hello.cxx )
target_include_directories(XercesGebeuren PUBLIC ${XSD_INCLUDE_DIR})
target_link_libraries(XercesGebeuren PUBLIC XercesC::XercesC)

linking to a custom library using cmake

I have two cmake files that build a directory and then try to compile an example that uses that library. The content of the first CMakeLists.txt file stored at the project root ${CMAKE_SOURCE_DIR} is:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project("lsd_point_pair")
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
#Note: Eclipse automatically picks up include paths with this on!
SET(CMAKE_VERBOSE_MAKEFILE ON)
SET(CMAKE_CXX_FLAGS "-g")
find_package(PCL 1.7 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
set(BOOST_LIBS program_options)
find_package(Boost COMPONENTS ${BOOST_LIBS} REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
MESSAGE(" Boost_LIBRARIES: ${Boost_LIBRARIES}")
include_directories(${PROJECT_BINARY_DIR})
link_directories(${PROJECT_BINARY_DIR}/lib})
add_library(lsd_obj_rec_ransac lsd_obj_rec_ransac.cpp lsd_obj_rec_ransac.h lsd_point_pair_model_library.cpp lsd_point_pair_model_library.h ndim_voxel_structure.h orr_octree_cloud.h orr_octree_cloud.cpp)
target_link_libraries(lsd_obj_rec_ransac ${PCL_LIBRARIES} ${Boost_LIBRARIES})
######## subdirectories #########
add_subdirectory(examples)
In ${CMAKE_SOURCE_DIR}/examples I have the following CMakeLists.txt file:
add_executable(example_pcl_lsd_point_pair example_pcl_lsd_point_pair.cpp)
target_link_libraries(example_pcl_lsd_point_pair lsd_obj_rec_ransac ${Boost_LIBRARIES} ${PCL_LIBRARIES})
After successfully running cmake I run make and I get the linking errors:
CMakeFiles/example_pcl_lsd_point_pair.dir/example_pcl_lsd_point_pair.cpp.o: In function `~LSDObjRecRANSAC':
make[2]: Leaving directory `/media/Data/Documents/Grad/research/Projects/LSDPointPairs/qtcreator-build'
make[1]: Leaving directory `/media/Data/Documents/Grad/research/Projects/LSDPointPairs/qtcreator-build'
/home/mustafa/projects/LSDPointPairs/examples/../lsd_obj_rec_ransac.h:44: undefined reference to `pcl::recognition::ORROctreeCloud::~ORROctreeCloud()'
/home/mustafa/projects/LSDPointPairs/examples/../lsd_obj_rec_ransac.h:44: undefined reference to `pcl::recognition::ORROctreeCloud::~ORROctreeCloud()'
../lib/liblsd_obj_rec_ransac.a(lsd_obj_rec_ransac.cpp.o): In function `LSDObjRecRANSAC':
/home/mustafa/projects/LSDPointPairs/lsd_obj_rec_ransac.cpp:18: undefined reference to `pcl::recognition::LSDPointPairModelLibrary::LSDPointPairModelLibrary(float, float, float)'
/home/mustafa/projects/LSDPointPairs/lsd_obj_rec_ransac.cpp:18: undefined reference to `pcl::recognition::ORROctreeCloud::ORROctreeCloud()'
/home/mustafa/projects/LSDPointPairs/lsd_obj_rec_ransac.cpp:18: undefined reference to `pcl::recognition::ORROctreeCloud::~ORROctreeCloud()'
../lib/liblsd_obj_rec_ransac.a(lsd_point_pair_model_library.cpp.o): In function `LSDPointPairModel':
/home/mustafa/projects/LSDPointPairs/lsd_point_pair_model_library.h:36: undefined reference to `pcl::recognition::ORROctreeCloud::ORROctreeCloud()'
/home/mustafa/projects/LSDPointPairs/lsd_point_pair_model_library.h:36: undefined reference to `pcl::recognition::ORROctreeCloud::~ORROctreeCloud()'
../lib/liblsd_obj_rec_ransac.a(lsd_point_pair_model_library.cpp.o): In function `~LSDPointPairModel':
/home/mustafa/projects/LSDPointPairs/lsd_point_pair_model_library.h:27: undefined reference to `pcl::recognition::ORROctreeCloud::~ORROctreeCloud()'
/home/mustafa/projects/LSDPointPairs/lsd_point_pair_model_library.h:27: undefined reference to `pcl::recognition::ORROctreeCloud::~ORROctreeCloud()'
collect2: ld returned 1 exit status
make[2]: *** [bin/example_pcl_lsd_point_pair] Error 1
make[1]: *** [examples/CMakeFiles/example_pcl_lsd_point_pair.dir/all] Error 2
make: *** [all] Error 2
The library successfully gets built because I see the liblsd_obj_rec_ransac.a file gets generated. But the problem happens when trying to compile the example. What am I doing wrong?

OpenGL hello.c fails to build using CMake

I am trying to build the hello.c example from http://www.glprogramming.com/red/chapter01.html (look for "Example 1-2").
My CMakeLists.txt is as follows:
cmake_minimum_required (VERSION 2.8)
project (GLUTEX)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories(${GLUT_INCLUDE_DIRS})
include_directories(${OpenGL_INCLUDE_DIRS})
add_executable (glutex glutex.c)
target_link_libraries (glutex ${OpenGL_LIBRARIES})
target_link_libraries (glutex ${GLUT_LIBRARIES})
The CMake call succeeds in generating the required Makefile. But when I call make, I encounter the following:
Scanning dependencies of target glutex
[100%] Building C object CMakeFiles/glutex.dir/glutex.c.o
Linking C executable glutex
/usr/bin/ld: CMakeFiles/glutex.dir/glutex.c.o: undefined reference to symbol 'glOrtho'
/usr/bin/ld: note: 'glOrtho' is defined in DSO /usr/lib64/libGL.so.1 so try adding it to the linker command line
/usr/lib64/libGL.so.1: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
make[2]: *** [glutex] Error 1
make[1]: *** [CMakeFiles/glutex.dir/all] Error 2
make: *** [all] Error 2
How do I fix this?
Try changing
target_link_libraries (glutex ${OpenGL_LIBRARIES})
to
target_link_libraries (glutex ${OPENGL_LIBRARIES})