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
Related
I am working on some parts of a fairly large project that involves using GraphViz on C++, but I can't seem to use the GraphViz functions. My code is intended to generate a .png from .dot files automatically, but I keep getting "undefined reference" to 'functionName' (all functions that are related to the gvc.h include) when I try to compile it. I highly suspect that something is not linking during compilation, but I can't figure out what to do with the CMakeLists.txt and what I should link in the first place. I did, however, notice that there was a gv.cpp file in my /usr/include/graphviz folder, but I don't know if I'm supposed to somehow link that file or if it's something completely different.
/usr/bin/ld: CMakeFiles/ag_gen.dir/src/main.cpp.o: in function `save_image_gv(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
main.cpp:(.text+0xf07): undefined reference to `gvContext'
/usr/bin/ld: main.cpp:(.text+0xf27): undefined reference to `agread'
/usr/bin/ld: main.cpp:(.text+0xf3c): undefined reference to `gvLayout'
/usr/bin/ld: main.cpp:(.text+0xfc8): undefined reference to `gvRender'
/usr/bin/ld: main.cpp:(.text+0xfef): undefined reference to `gvFreeLayout'
/usr/bin/ld: main.cpp:(.text+0xff7): undefined reference to `agclose'
/usr/bin/ld: main.cpp:(.text+0xfff): undefined reference to `gvFreeContext'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/ag_gen.dir/build.make:460: ag_gen] Error 1
make[2]: *** [CMakeFiles/Makefile2:156: CMakeFiles/ag_gen.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:163: CMakeFiles/ag_gen.dir/rule] Error 2
make: *** [Makefile:164: ag_gen] Error 2
Here is the problematic part of my code in main.cpp:
#include <graphviz/gvc.h>
bool save_image_gv(std::string filename){
GVC_t *gvc;
Agraph_t *g;
FILE *fp;
gvc = gvContext();
fp = fopen((filename).c_str(), "r");
g = agread(fp, 0);
gvLayout(gvc, g, "dot");
gvRender(gvc, g, "png", fopen((filename+".png").c_str(), "w"));
gvFreeLayout(gvc, g);
agclose(g);
return (gvFreeContext(gvc));
}
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
# Uncomment for gcc
# set(CMAKE_C_COMPILER "gcc-8")
# set(CMAKE_CXX_COMPILER "g++-8")
project(ag_gen)
set_source_files_properties(
mem.c
PROPERTIES
COMPILE_DEFINITIONS UNIT_TEST=1
)
# Common compiler options among built types
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
# Specific compiler options for Debug or Release builds
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -ggdb -Wall -fopenmp -pedantic")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -g -Wall -fopenmp -pedantic -O1")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O1 -fopenmp")
set(PostgreSQL_TYPE_INCLUDE_DIR "9.5")
set(PostgreSQL_ADDITIONAL_VERSIONS "10.1" "10" "9.5")
find_program(LSB_RELEASE lsb_release)
execute_process(COMMAND ${LSB_RELEASE} -is
OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
include_directories("/usr/include/postgresql")
# Apple has a different openssl directory when using brew
if(APPLE)
set(BISON_EXECUTABLE "/usr/local/opt/bison/bin/bison")
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
endif()
set(ENV{PKG_CONFIG_PATH} "/usr/local/lib/pkgconfig")
find_package(PkgConfig REQUIRED)
find_package(PostgreSQL REQUIRED)
find_package(OpenMP)
find_package(BISON 2.4 REQUIRED)
find_package(FLEX REQUIRED)
find_package(Boost REQUIRED)
find_package(OpenSSL)
find_package(Doxygen)
pkg_check_modules(CMOCKA cmocka)
pkg_check_modules(CPPREDIS cpp_redis)
if(OpenSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIR})
endif()
# Enable thread-level parallelization if OpenMP is found.
if(OpenMP_CXX_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile #ONLY)
add_custom_target(doc ALL ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
endif(DOXYGEN_FOUND)
include_directories("${CMAKE_SOURCE_DIR}/src/")
file(GLOB ag_gen_src "${CMAKE_SOURCE_DIR}/src/ag_gen/*.cpp")
file(GLOB utils_src "${CMAKE_SOURCE_DIR}/src/util/*.c" "${CMAKE_SOURCE_DIR}/src/util/*.cpp")
########################
### Network Model Parser
########################
BISON_TARGET(nm_parser "${CMAKE_SOURCE_DIR}/src/parser/nm-parser/nm_parser.yy"
"${CMAKE_CURRENT_BINARY_DIR}/nm_parser.c"
DEFINES_FILE "${CMAKE_CURRENT_BINARY_DIR}/nm_parser.tab.h")
FLEX_TARGET(nm_scanner "${CMAKE_SOURCE_DIR}/src/parser/nm-parser/nm_scanner.l"
"${CMAKE_CURRENT_BINARY_DIR}/nm_scanner.c"
COMPILE_FLAGS "-Pnm")
ADD_FLEX_BISON_DEPENDENCY(nm_scanner nm_parser)
#add_executable(nm_test ${FLEX_nm_scanner_OUTPUTS} ${BISON_nm_parser_OUTPUTS} ${utils_src})
#target_include_directories(nm_test PRIVATE ${CMAKE_CURRENT_BINARY_DIR} "${CMAKE_SOURCE_DIR}/src/compiler/nm-parser")
##########################
### Exploit Pattern Parser
##########################
BISON_TARGET(xp_parser "${CMAKE_SOURCE_DIR}/src/parser/xp-parser/xp_parser.yy"
"${CMAKE_CURRENT_BINARY_DIR}/xp_parser.c"
DEFINES_FILE "${CMAKE_CURRENT_BINARY_DIR}/xp_parser.tab.h")
FLEX_TARGET(xp_scanner "${CMAKE_SOURCE_DIR}/src/parser/xp-parser/xp_scanner.l"
"${CMAKE_CURRENT_BINARY_DIR}/xp_scanner.c"
COMPILE_FLAGS "-Pxp")
ADD_FLEX_BISON_DEPENDENCY(xp_scanner xp_parser)
#add_executable(xp_test ${FLEX_xp_scanner_OUTPUTS} ${BISON_xp_parser_OUTPUTS} ${utils_src})
#target_include_directories(xp_test PRIVATE ${CMAKE_CURRENT_BINARY_DIR} "${CMAKE_SOURCE_DIR}/src/compiler/xp-parser")
####################
### Main application
####################
add_executable(ag_gen "${CMAKE_SOURCE_DIR}/src/main.cpp"
${FLEX_nm_scanner_OUTPUTS} ${BISON_nm_parser_OUTPUTS}
${FLEX_xp_scanner_OUTPUTS} ${BISON_xp_parser_OUTPUTS}
${ag_gen_src} ${utils_src})
target_link_libraries(ag_gen ${PostgreSQL_LIBRARIES})
add_executable(decode "${CMAKE_SOURCE_DIR}/src/tools/decode.cpp"
${ag_gen_src} ${utils_src})
target_link_libraries(decode ${PostgreSQL_LIBRARIES})
if(CPPREDIS_FOUND)
#include_directories("${CPPREDIS_INCLUDE_DIRS}")
link_directories("${CPPREDIS_LIBRARY_DIRS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DREDIS")
target_link_libraries(ag_gen cpp_redis tacopie)
target_link_libraries(decode cpp_redis tacopie)
endif()
################
### Unit Testing
################
if(CMOCKA_FOUND)
add_executable(dynstr_test ${CMAKE_SOURCE_DIR}/src/util/mem.c ${CMAKE_SOURCE_DIR}/src/tests/mem_test.c)
target_link_libraries(dynstr_test ${CMOCKA_LIBRARIES})
endif()
# Files to be added to build directory
configure_file("config.ini" "config.ini" COPYONLY)
if(CPPREDIS_FOUND)
add_custom_command(TARGET ag_gen PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/redis_scripts $<TARGET_FILE_DIR:ag_gen>/redis_scripts)
endif()
Link libgvc.so with your binary as follows:
target_link_libraries(ag_gen PUBLIC gvc)
Using Botje's answer and this Stack Overflow question, I was able to solve the problem. Here's what I did to my CMakeLists.txt:
I added cgraph and gvc in target_link_libraries.
target_link_libraries(ag_gen ${PostgreSQL_LIBRARIES} cgraph gvc)
And, voila! After this simple change, compilation was a success!
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.
I'm quite new to work with cmake, and there is a problem I can't find the solution to:
I use the vtk library and specify this in the CMakeLists.txt file:
cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
cmake_policy(SET CMP0053 OLD)
project (pcl-visualizer)
find_package (Qt4 REQUIRED)
find_package (VTK REQUIRED)
find_package (PCL 1.7.1 REQUIRED)
include_directories (${PCL_INCLUDE_DIRS})
link_directories (${PCL_LIBRARY_DIRS})
add_definitions (${PCL_DEFINITIONS})
set (project_SOURCES main.cpp pclviewer.cpp)
set (project_HEADERS pclviewer.h)
set (project_FORMS pclviewer.ui)
set (VTK_LIBRARIES vtkRendering vtkGraphics vtkHybrid QVTK)
QT4_WRAP_CPP (project_HEADERS_MOC ${project_HEADERS})
QT4_WRAP_UI (project_FORMS_HEADERS ${project_FORMS})
INCLUDE (${QT_USE_FILE})
ADD_DEFINITIONS (${QT_DEFINITIONS})
ADD_EXECUTABLE (pcl_visualizer ${project_SOURCES}
${project_FORMS_HEADERS}
${project_HEADERS_MOC})
TARGET_LINK_LIBRARIES (pcl_visualizer ${QT_LIBRARIES} ${PCL_LIBRARIES} ${VTK_LIBRARIES})
cmake also runs fine. It gives no error so I assume it can find all libraries, including the vtk library?
When I run make though, I get this error message:
[ 16%] Linking CXX executable pcl_visualizer
/usr/bin/ld: cannot find -lvtkRendering
/usr/bin/ld: cannot find -lvtkGraphics
/usr/bin/ld: cannot find -lvtkHybrid
/usr/bin/ld: cannot find -lQVTK
/usr/bin/ld: cannot find -lvtkRendering
/usr/bin/ld: cannot find -lvtkGraphics
/usr/bin/ld: cannot find -lvtkHybrid
/usr/bin/ld: cannot find -lQVTK
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/pcl_visualizer.dir/build.make:410: pcl_visualizer] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/pcl_visualizer.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I installed the vtk library via the package manager (pacman, I run arch linux), so it should be in one of the standard directories?
I checked if the right libraries are installed via pacman -Q vtk and it lists all needed libraries in the `/usr/lib/`` directory.
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?
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})