My build fails with the following message
ld: library not found for -lintl
From what I understand it's talking about libintl.a in the following directory:
I tried doing the following in my cmake file to no avail:
cmake_minimum_required(VERSION 3.8)
project(Visual)
file(GLOB SOURCES src/*.cpp)
file(GLOB HEADERS src/*.h)
add_executable(visual ${HEADERS} ${SOURCES})
find_package(PkgConfig REQUIRED)
[...]
# gettext
find_library(INTL
NAMES intl libintl
HINTS "/usr/local/opt/gettext/lib")
if (NOT INTL_FOUND)
message(WARNING "Did not find intl")
endif ()
target_link_libraries(visual ${INTL})
target_link_libraries(visual ${LIBS})
Related
I wrote some C++ files to create a shared library, and here is my Makefile
PYTHON_VERSION = 3.6
PYTHON_HOME_PATH = /Library/Frameworks/Python.framework/Versions
PYTHON_INCLUDE = $(PYTHON_HOME_PATH)/$(PYTHON_VERSION)
BOOST_INC = /usr/local/Cellar/boost/1.67.0_1/include
BOOST_LIB = /usr/local/Cellar/boost/1.67.0_1/lib
BOOST_PYTHON_LIB = /usr/local/Cellar/boost-python3/1.67.0_1/lib/
TARGET = main
EXTEND_FILE = main_ext
$(TARGET).so:$(TARGET).o
g++ -shared depend.o -L$(BOOST_LIB) -L$(BOOST_PYTHON_LIB) -lboost_python3 `python3.6m-config --libs --ldflags` -o depend_ext.so
g++ -shared depend.o $(TARGET).o -L$(BOOST_LIB) -L$(BOOST_PYTHON_LIB) -lboost_python3 `python3.6m-config --libs --ldflags` -o $(TARGET).so
mv $(TARGET).so $(EXTEND_FILE).so
depend.o:depend.cpp
g++ `python3.6m-config --include` -fPIC -c depend.cpp -O3 -std=c++11
$(TARGET).o:$(TARGET).cpp
g++ `python3.6m-config --include` -fPIC -c depend.cpp $(TARGET).cpp -O3 -std=c++11
clean:
rm *.so *.o
The Makefile can generate the .so file. And my CMakeLists.txt is
cmake_minimum_required(VERSION 3.8)
project(Simulator)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES depend.cpp depend.h main.cpp main.h)
add_executable(Simulator ${SOURCE_FILES})
set(Boost_INCLUDE_DIRS /usr/local/Cellar/boost/1.67.0_1/include)
set(Boost_LIBRARIES /usr/local/Cellar/boost/1.67.0_1/lib)
set(BOOST_PYTHON_LIB /usr/local/Cellar/boost-python3/1.67.0_1/lib/)
find_package(Boost COMPONENTS filesystem system date_time python REQUIRED)
message("--> Include dirs of boost: " ${Boost_INCLUDE_DIRS} )
message("--> Libs of boost: " ${Boost_LIBRARIES} )
find_package(PythonLibs 3.6 REQUIRED)
message("--> Include dirs of Python: " ${PYTHON_INCLUDE_DIRS} )
message("--> Libs of Python: " ${PYTHON_LIBRARIES} )
include_directories(
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
)
target_link_libraries(Simulator
${Boost_LIBRARIES}
${PYTHON_LIBRARIES}
${BOOST_PYTHON_LIB}
)
But running CMake gives the following errors
CMake Error at /usr/local/Cellar/cmake/3.10.2/share/cmake/Modules/FindBoost.cmake:1928 (message):
Unable to find the requested Boost libraries.
Boost version: 1.67.0
Boost include path: /usr/local/include
Could not find the following Boost libraries:
boost_python3
I want to build it with Python3 and I have already install boost.python3. How can I fix it?
I think the problem is that Homebrew installs boost_python under a separate directory (i.e. /usr/local/Cellar/boost-python3/1.67.0_1/) which is different from the rest of the Boost installation (i.e. /usr/local/Cellar/boost/1.67.0_1).
I'm not on a Mac, thus I'm not exactly certain of the actual directory structure and how much can be done with symlinks (symlinking the Boost Python component directories back into the main Boost installation dir).
So, I built and installed (on Ubuntu Linux) from source the latest Boost version (1.68) using
./bootstrap.sh --prefix=/bulk/workbench/boost/install --with-python=python3
All components ended up under the include and lib directories in /bulk/workbench/boost/install. Providing that during CMake configuration as in
cmake -DBoost_ROOT=/bulk/workbench/boost/install [path-to-my-project-source-dir]
and using this in my CMakeLists.txt
find_package(Boost COMPONENTS python REQUIRED)
it was able to find my boost_python module.
Basically, unless you're able to twist the Homebrew installation, it might be more straightforward to build your own Boost.
I am new to Cmake and I am trying to create a CMakeLists.txt to build my project. I can build my project from command line using g++ compiler but when it comes to Cmake I am confused.
The directory structure is like this :
Project_folder
|--> Source
|--> main.cpp
|--> file1.cpp
|--> file2.cpp
|--> Header
|--> header1.h
|--> header2.h
|--> build (from where I run cmake .. and make)
CMakeLists.txt (this is under Project_folder)
Dependencies
|--> utils
|--> Utils.cpp
|--> include (has many folders in here)
|--> build (this path is in LD_LIBRARY_PATH as well)
|--> sharedlib1.so
|--> sharedlib2.so
Now from within the Project_Folder I can successfully run :
g++ ./Source/main.cpp ./Source/file1.cpp ./Source/file2.cpp ../Dependencies/utils/Utils.cpp -I ../Dependencies -I ../Dependencies/include/ -I ./Header/ -L ../Dependencies/build -std=c++11 -lsharedlib1 -lsharedlib2 -o ./build/main `pkg-config opencv --cflags --libs`
and generate the executable file.
Now I want to configure a CMakeLists.txt and try to replicate what the above compiler line is doing but with no success (I can cmake .., but I cannot make). CMakeLists.txt looks like this :
cmake_minimum_required(VERSION 2.8.9)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
project(my_project)
#For the shared library:
set ( PROJECT_LINK_LIBS sharedlib1.so sharedlib2.so)
link_directories(${PROJECT_SOURCE_DIR}/../Dependencies/build/ )
include_directories(${PROJECT_SOURCE_DIR}/../Dependencies ${PROJECT_SOURCE_DIR}/../Dependencies/include ${PROJECT_SOURCE_DIR}/Header)
file(GLOB SOURCES "Source/*.cpp" )
set(CMAKE_CXX_FLAGS_RELEASE pkg-config opencv cflags libs)
## add_executable(name_of_output.o list_of_cpp_files)
add_executable(build ${SOURCES})
Running make after generating the makefile I get undefined reference to everything inside main.cpp. Is there anything obvious in the CMakeLists.txt that I should change?
Your call to g++ includes the ../Dependencies/utils/Utils.cpp file, but your call to add_executable is only using the files matched by Source/*.cpp. A quick solution would be to add ../Dependencies/Utils.cpp to the call to add_executable() making it
add_executable(build ${SOURCES} "${PROJECT_SOURCE_DIR}/../Dependencies/Utils.cpp")
On a related note: CMake discourages using file(GLOB ...) to get a list of source files, it's generally better to list the source files explicitly
You should use target_link_libraries after add_executable.
Please check the examples:
Executable with Static Library
Executable with Shared Library
While running the application you will also get some errors. Please be aware of RPATH.
Ok I managed to solve it ! :)
# set Cmake minimum version to use
cmake_minimum_required(VERSION 2.8.9)
# set the compiler
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# name your project
project(my_project)
set(CMAKE_BUILD_TYPE Release)
# Find and load the settings from the packages
find_package(PkgConfig REQUIRED)
find_package(OpenCV REQUIRED )
# set the extra flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -cflags -libs")
# set the shared libraries name (where the libraries are libsharedlib1.so and libsharedlib2.so + opencv runtime libraries)
set(PROJECT_LINK_LIBS sharedlib1 sharedlib2) ${OpenCV_LIBS}
# include the header files (.h)
include_directories(${PROJECT_SOURCE_DIR}/../Dependencies ${PROJECT_SOURCE_DIR}/../Dependencies/include ${PROJECT_SOURCE_DIR}/Header)
# add the source files (.cpp) using the set command as follow
set(SOURCES
Source/main.cpp
Source/file1.cpp
Source/file2.cpp
${PROJECT_SOURCE_DIR}/../Dependencies/utils/Utils.cpp)
# link the shared libraries (/build/libsharedlib1.so and /build/libsharedlib2.so)
link_directories(${PROJECT_SOURCE_DIR}/../Dependencies/build/)
# add_executable(name_of_output list_of_cpp_files)
add_executable(main ${SOURCES})
# link the executable with the shared libraries
target_link_libraries(main ${PROJECT_LINK_LIBS} )
and finally ./main will run the program !
I'm trying to build a simple GTK+ app on Windows (64 bit) using CMake. I've installed everything according to the official guide.
Here's the contents of my CMakeLists.txt:
# Set project
project(gtk-test C)
cmake_minimum_required(VERSION 3.0)
# Configure project paths
set(PROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
# Find dependencies
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})
add_definitions(${GTK3_CFLAGS_OTHER})
set(LIBRARIES ${LIBRARIES} ${GTK3_LIBRARIES})
# Compile
add_executable(main ${PROJECT_SOURCE_DIR}/main.c)
target_link_libraries(main ${LIBRARIES})
# Messages
message(STATUS "GTK include directories: ${GTK3_INCLUDE_DIRS}")
and then I'm building the source file with the following:
cmake -Bbuild -H.
cmake --build build
Everything seems to work fine on macOS, but on Windows I keep getting the following error:
fatal error: gtk/gtk.h: No such file or directory
#include <gtk/gtk.h>
I checked the directory included by CMake and the header file is there. Also, the following command from the tutorial successfully builds the application:
gcc `pkg-config --cflags gtk+-3.0` -o main.exe main.c `pkg-config --libs gtk+-3.0`
Still, I would really love to get it working with CMake. I've been searching for the solution for hours now with no result, so any help would be highly appreciated.
Thanks in advance!
Update
Apparently, the whole problem lies within included libraries. For some reason, the line:
include_directories(${GTK3_INCLUDE_DIRS})
does not include them. I managed to fix the problem including libraries myself with -I option:
# Set project
cmake_minimum_required(VERSION 3.0)
project(gtk-test C)
# Configure project paths
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
# Find dependencies
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
link_directories(${GTK3_LIBRARY_DIRS})
add_compile_options(${GTK3_CFLAGS_OTHER})
set(LIBRARIES ${LIBRARIES} ${GTK3_LIBRARIES})
set(FLAGS "-I${GTK3_INCLUDE_DIRS}")
message(STATUS "Flags: ${FLAGS}")
string(REPLACE ";" " -I" FLAGS "${FLAGS}")
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} ${GTK3_FLAGS} ${FLAGS})
# Compile
add_executable(main ${PROJECT_SOURCE_DIR}/main.c)
target_link_libraries(main ${LIBRARIES})
Although it seems to work, this does not look like a good solution to me.
Freeglut-3.0.0 is build with cmake (MinGW makefiles) and mingw and then successfully installed with mingw32-make install to C:/Program Files (x86)/freeglut.
My CMakeLists.txt is:
cmake_minimum_required(VERSION 3.7)
project(math_tests)
set(TESTS_SOURCES tests.cpp gl_core_3_3.c)
set(CMAKE_CXX_STANDARD 11)
# GLUT
find_package(GLUT REQUIRED)
include_directories(${GLUT_INCLUDE_DIR})
if(NOT GLUT_FOUND)
message(ERROR "GLUT not found!")
endif(NOT GLUT_FOUND)
# OpenGL
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})
if(NOT OPENGL_FOUND)
message(ERROR "OPENGL not found!")
endif(NOT OPENGL_FOUND)
add_executable(tests ${TESTS_SOURCES})
target_link_libraries(tests math ${GLUT_LIBRARIES} ${OPENGL_LIBRARIES})
Now CMake prints error: Could NOT find GLUT (missing: GLUT_glut_LIBRARY).
I can't figure out what I am doing wrong.
Your CMakeLists.txt file statement
find_package(GLUT REQUIRED)
is going to execute this code from FindGLUT.cmake
find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut
PATHS
${OPENGL_LIBRARY_DIR}
${GLUT_ROOT_PATH}/Release
)
and find_library is in your scenario unable to find any of glut glut32 freeglut libraries, because it doesn't know where they are (which for you are under C:/Program Files (x86)/freeglut).
In your case you could set ${OPENGL_LIBRARY_DIR} to the right directory, that is the one containing the freeglut.dll file, for e.g.:
set(OPENGL_LIBRARY_DIR "C:/Program Files (x86)/freeglut/lib")
given the file is under C:/Program Files (x86)/freeglut/lib directory.
I want to run code which needs boost libraries. I built it using CMake. Someone else has written this code and cmakelist. It needs to be linked with boost regex, filesystem and system libraries.
I downloaded boost 1.48 and built the above mentioned 3 libraries. Now I have dll and static libraries(.a). I ran a simple program which used these libraries. It worked fine.
Now while using CMake, it gives a linker error relating to the boost libraries. I have checked the cmakelist, but I don't understand what to modify. The relevant part of the cmakelist is:
set(WITH_BOOST_REGEX ON CACHE BOOL "Include BOOST REGEX support")
set(WITH_BOOST_FILESYSTEM ON CACHE BOOL "Include BOOST FILESYSTEM support")
set(WITH_BOOST_SYSTEM ON CACHE BOOL "Include BOOST SYSTEM support")
if(WITH_BOOST_REGEX)
CHECK_MODULE(libboost-regex HAVE_BOOST_REGEX)
else()
set(HAVE_BOOST_REGEX FALSE)
endif()
if(WITH_BOOST_FILESYSTEM)
CHECK_MODULE(libboost-filesystem HAVE_BOOST_FILESYSTEM)
else()
set(HAVE_BOOST_FILESYSTEM FALSE)
endif()
I think that I am just making an error in specifying the path for linking, but I am not able to find how to correct it.
I am successfully running a simple example program linking with both dynamic and static libraries of boost_regex by successfully specifying the path of the object file of that program and libraries.
Now in this code, there are various other modules. It says boost_regex library is missing. link.txt is there which says which libraries to link to, and which is like this:
/usr/bin/c++ CMakeFiles/test_ensembletraining.dir/ensembletraining.o -o ../../bin/test_ensembletraining -rdynamic ../../lib/libensembletraining.so.0.3.2 ../../lib/libutils.so.0.3.2 ../../lib/libfeatureextraction.so.0.3.2 ../../lib/libintegraltransform.so.0.3.2 -lboost_regex.so -lboost_filesystem -lboost_system.so -lopencv_core -lopencv_flann -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_objdetect -lopencv_features2d -lopencv_calib3d -lopencv_legacy -lopencv_contrib -Wl,-rpath,/home/rizwan/vosm-0.3.3/lib:
It successfully links with opencv libraries, but not with boost libraries. I think there is a mistake in specifying the path for link libraries. I tried to find where this path is specified by going through all the cmakelist files.
If anyone wants to help, first download code from VOSM. Build it using CMake. Download boost 1.48 libraries from the boost website. If it's working then please tell me how you do that.
This is part of the cmakecachelist:
//Include BOOST FILESYSTEM support
WITH_BOOST_FILESYSTEM:BOOL=ON
//Include BOOST REGEX support
WITH_BOOST_REGEX:BOOL=ON
//Include BOOST SYSTEM support
WITH_BOOST_SYSTEM:BOOL=ON
//Include OPENCV 2.x support
WITH_OPENCV:BOOL=ON
here is cmakelist..
if (BUILD_EXAMPLES)
project(ensembletraining_exe)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
endif()
include_directories(
"${CMAKE_SOURCE_DIR}/modules/ensembletraining/include"
"${CMAKE_SOURCE_DIR}/modules/common/include"
"${CMAKE_SOURCE_DIR}/modules/featureextraction/include"
)
# ---------------------------------------------
# Define executable targets
# ---------------------------------------------
MACRO(VO_DEFINE_EXAMPLE name srcs)
set(the_target "test_${name}")
add_executable(${the_target} ${srcs})
set_target_properties(${the_target} PROPERTIES
OUTPUT_NAME "test_${name}"
PROJECT_LABEL "(EXAMPLE) test_${name}")
add_dependencies(${the_target} ensembletraining
opencv_core opencv_flann opencv_imgproc opencv_highgui
opencv_ml opencv_video opencv_objdetect opencv_features2d
opencv_calib3d opencv_legacy opencv_contrib)
target_link_libraries(${the_target} ${VOSM_LINKER_LIBS} ensembletraining utils featureextraction integraltransform
boost_regex boost_filesystem boost_system opencv_core
opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib)
if(WIN32)
install(TARGETS ${the_target}
RUNTIME DESTINATION "tests" COMPONENT main)
endif()
install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)
ENDMACRO(VO_DEFINE_EXAMPLE)
file(GLOB cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp *.c)
foreach(sample_filename ${cpp_samples})
get_filename_component(sample ${sample_filename} NAME_WE)
VO_DEFINE_EXAMPLE(${sample} ${sample_filename})
endforeach()
endif(BUILD_EXAMPLES)
if (INSTALL_C_EXAMPLES AND NOT WIN32)
file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
install(FILES ${C_SAMPLES}
DESTINATION share/vosm/tests
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
endif ()
I'd recommend using find_package to find required Boost libraries:
set BOOST_ROOT environment variable to the Boost root directory, i.e. the one that contains boost, libs, stage and the rest, e.g. C:\boost_1_48_0 (either globally or when executing CMake)
add the following to your CMakeLists.txt:
find_package(Boost 1.48 COMPONENTS regex system filesystem REQUIRED)
target_link_libraries(your_target ${Boost_LIBRARIES})
include_directories(${Boost_INCLUDE_DIRS})
if you need only static libraries, set the Boost_USE_STATIC_LIBS variable to TRUE (before find_package!)
if your Boost is linked against a static C++ runtime, set the Boost_USE_STATIC_RUNTIME to TRUE