I am trying to run an example from the MRPT library but I am getting the error:
cannot find -lmrpt- base
I am running ubunut 12.04 64-bit on a laptop. I am using Code::Blocks IDE with the GNU GCC compiler.
The CMakeLists.txt file had this code:
SET(sampleName geometry3D) SET(PRJ_NAME "EXAMPLE_${sampleName}")
PROJECT(${PRJ_NAME})
CMAKE_MINIMUM_REQUIRED(VERSION 2.4) if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW) endif(COMMAND cmake_policy)
SET(EXECUTABLE_OUTPUT_PATH ".")
FIND_PACKAGE(MRPT REQUIRED base)
ADD_EXECUTABLE(${sampleName} test.cpp )
SET_TARGET_PROPERTIES( ${sampleName} PROPERTIES PROJECT_LABEL
"(EXAMPLE) ${sampleName}")
SET(MY_DEFS ) IF(MY_DEFS) # If not empty
ADD_DEFINITIONS("-D${MY_DEFS}") ENDIF(MY_DEFS)
TARGET_LINK_LIBRARIES(${sampleName} ${MRPT_LIBS} "" )
IF(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_BUILD_TYPE MATCHES "Debug")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
ENDIF(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_BUILD_TYPE MATCHES
"Debug")
IF("${CMAKE_PROJECT_NAME}" STREQUAL "MRPT")
DeclareAppDependencies(${sampleName} mrpt-base)
ENDIF("${CMAKE_PROJECT_NAME}" STREQUAL "MRPT")
the example can be found here http://www.mrpt.org/tutorials/programming/maths-and-geometry/2d_3d_geometry/ at the end of the page
how do I link the lmrpt to my project? what files am I looking for?
SO the problem was I did not install the drivers correctly :P. When I was installing I did the "cmake" and "make" command but dint do the "sudo make install" so the files dint go to the correct place. Silly me :P
Related
I'm attempting to add OpenMP to a project that is building with CMake. I'm having no problem building it on Linux with the standard CMake/OpenMP addition:
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
${OpenMP_EXE_LINKER_FLAGS}")
endif()
Unfortunately this doesn't seem to work on macOS targets. When cmake is called, the following error is given:
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
I'm using macOS High Sierra (10.13.3) along with CMake 3.11. I've installed OpenMP 5.01 via brew, 'brew install libomp'. I've found some previous posts commenting on issues regarding these three but they all seem to deal with a previous way of installing OpenMP on macOS, "brew install clang-omp".
I'm thinking this might have something to do with CMake not support this OpenMP install as I'm able to use OpenMP no problem with standard makefiles. Any information provided would be much appreciated.
I've been able to answer my own question (apologies for not figuring this out beforehand, hopefully this can help others with the same issue).
It seems that a patch has been submitted to CMake to allow it to properly create buildsystems with the new OpenMP install: https://gitlab.kitware.com/cmake/cmake/merge_requests/1812
For others seeing this in the future, update to CMake 3.12 if it has been released at the time of reading.
I had the same problem and it took one complete day to find the solution. I am using Mac-Sierra 10.13.4. I want to use Opencv3 (I think the same problem also appears for opencv2) and openMP. I was actually using Clion as the IDE (CLion uses cmake to configure the project unlike other IDE), so I have to write the CMakeLists.txt file.
There was a conflict of using gcc as the compiler for openCV and openMP. If you use gcc as the compiler then it gives error for opencv as :
imwrite() on OS X error: Undefined symbols
You need to specifically use llvm compiler on OS X to resolve this issue. Following, I am giving the correct code for using OpenCV and OpenMP on Mac-Sierra:
cmake_minimum_required(VERSION 3.10)
project(MyOpenCVTest)
set(CMAKE_CXX_STANDARD 11)
add_executable(MyOpenCVTest main.cpp)
# set("OpenCV_DIR" "/modules/opencv/3.4.1/share/OpenCV/")
set(CMAKE_PREFIX_PATH "/usr/local/Cellar/opencv#3/")
set(OpenCV_INCLUDE_DIRS "/usr/local/Cellar/opencv#3/include/")
set(OpenCV_LIBS "/usr/local/Cellar/opencv#3/lib/")
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
if(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++0x")
endif()
set(CMAKE_C_COMPILER "/usr/local/Cellar/llvm/6.0.0/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/local/Cellar/llvm/6.0.0/bin/clang++")
set(OPENMP_LIBRARIES "/usr/local/Cellar/llvm/6.0.0/lib")
set(OPENMP_INCLUDES "/usr/local/Cellar/llvm/6.0.0/include")
OPTION (USE_OpenMP "Use OpenMP to enamble <omp.h>" ON)
# Find OpenMP
if(APPLE AND USE_OpenMP)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(OpenMP_C "${CMAKE_C_COMPILER}")
set(OpenMP_C_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument")
set(OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp5")
set(OpenMP_libomp_LIBRARY ${OpenMP_C_LIB_NAMES})
set(OpenMP_libgomp_LIBRARY ${OpenMP_C_LIB_NAMES})
set(OpenMP_libiomp5_LIBRARY ${OpenMP_C_LIB_NAMES})
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(OpenMP_CXX "${CMAKE_CXX_COMPILER}")
set(OpenMP_CXX_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument")
set(OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp5")
set(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
set(OpenMP_libiomp5_LIBRARY ${OpenMP_CXX_LIB_NAMES})
endif()
endif()
if(USE_OpenMP)
find_package(OpenMP REQUIRED)
endif(USE_OpenMP)
if (OPENMP_FOUND)
include_directories("${OPENMP_INCLUDES}")
link_directories("${OPENMP_LIBRARIES}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif(OPENMP_FOUND)
include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries( MyOpenCVTest ${OpenCV_LIBS})
TARGET_LINK_LIBRARIES(MyOpenCVTest opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs)
You might want to set e.g. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread") such that the linker automatically detects the appropriate pthread library
Do
brew reinstall llvm
to install llvm compiler.
Please note that, you can't use gcc compiler on Mac-Sierra for your project which needs openMP and also openCV. You need to use llvm compiler.
Verify the correct location of llvm and openCV installation directory.
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.
cmake_minimum_required(VERSION 3.1)
project(ClanLib)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
SET(ClanLib_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${ClanLib_INCLUDE_DIRS})
FIND_PACKAGE(ClanLib REQUIRED)
set(SOURCE_FILES main.cpp)
add_executable(ClanLib ${SOURCE_FILES} main.cpp)
TARGET_LINK_LIBRARIES(ClanLib ${ClanLib_LIBRARY})
and cmake give error:
Error:By not providing "FindClanLib.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "ClanLib", but CMake did not find one.
Could not find a package configuration file provided by "ClanLib" with any of the following names:
ClanLibConfig.cmake clanlib-config.cmake
Add the installation prefix of "ClanLib" to CMAKE_PREFIX_PATH or set "ClanLib_DIR" to a directory containing one of the above files. If "ClanLib" provides a separate development package or SDK, be sure it has been installed.
There is no FindClanLib.cmake provided by ClanLib project or CMake, so find_package will not work in your case.
For Linux you can use pkg-config facility from CMake.
Here the example for ClanLib usage on Linux.
I hope someone is able to help me:
I try to use the cmake plugin in a jenkins server to create a hex file, but i don't know my fault.
I also try to run the example of this site: http://robot-develop.org/archives/2952 but if i use the "make" command, i get this error message:
make: *** No targets specifed and no makefile found. Stop
Here is my code:
CMakeLists.txt:
cmake_minimum_required (VERSION 2.6.0)
INCLUDE("C:/Users/name/Desktop/example/Code/test_crosscompile.cmake")
INCLUDE("C:/Users/name/Desktop/example/Code/macro.cmake")
project (Code)
MESSAGE(STATUS "\n -------------------------------->Creating Test-Projekt...")
IF( NOT CMAKE_BUILD_TYPE )
SET( CMAKE_BUILD_TYPE Release ... FORCE )
ENDIF()
SET(MAIN_FILE
class.c)
# add the executable
add_executable(Code ${MAIN_FILE})
#makro
AVR_CREATE_HEX(class)
makro.cmake:
# create avr hex
MACRO(AVR_CREATE_HEX name)
ADD_CUSTOM_COMMAND(TARGET ${name} POST_BUILD COMMAND avr-objcopy ARGS -O ihex -R.eeprom ${name} "C:/Users/name/Desktop/example/Code/class.hex")
MESSAGE(STATUS "\n ----------JONAS---------------------->Macro")
ENDMACRO(AVR_CREATE_HEX)
test_crosscompile.cmake:
SET(CMAKE_SYSTEM_NAME "Windows")
SET(CMAKE_C_COMPILER avr-gcc)
SET(CMAKE_CXX_COMPILER avr-g++)
SET(CSTANDARD "-std=gnu99")
SET(CDEBUG "-gstabs")
SET(CWARN "-Wall -Wstrict-prototypes")
SET(CTUNING "-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums")
SET(COPT "-Os")
SET(CMCU "-mmcu=atmega32")
SET(CDEFS "-DF_CPU=12000000UL")
SET(CFLAGS "${CMCU} ${CDEBUG} ${CDEFS} ${CINCS} ${COPT} ${CWARN} ${CSTANDARD} ${CEXTRA}")
SET(CXXFLAGS "${CMCU} ${CDEFS} ${CINCS} ${COPT}")
SET(CMAKE_C_FLAGS ${CFLAGS})
SET(CMAKE_CXX_FLAGS ${CXXFLAGS})
I use the cmake GUI, but i don't know how to use it.
I try as generator visual studio 10 (specify toolchain file for cross compiling), but it generates no makefile or hex file.
If i choose MinGW Makefiles as the generator, i get the error:
The C compiler "C:/WinAVR-20100110/bin/avr-gcc.exe" is not able to compile
a simple test program.
I hope somebody can help me, THANKS!
You have the CMAKE_SYSTEM_NAME set to windows, you need to set this to generic to enable Cross compiling eg:
SET(CMAKE_SYSTEM_NAME Generic)
I'm writing a Python extension module in C++ using Boost.Python. However, I
would like to use a newer version of the Boost library than the system
installation offers. This newer version of boost is contained in
BOOST_ROOT=$HOME/opt/boost/1.55.0.
Following this guide on how
to use RPath in CMake I came up with the following CMakeLists.txt.
cmake_minimum_required(VERSION 2.8)
project("test")
set(PROJECT_DESC "Test Boost.Python")
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
add_definitions(-std=c++11 -Wall -Wextra -pedantic)
find_package(PythonInterp REQUIRED)
find_package(PythonLibsNew REQUIRED)
find_package(Boost COMPONENTS python REQUIRED)
message(STATUS "Using Boost installation in:")
message(STATUS " INCLUDE: ${Boost_INCLUDE_DIRS}")
message(STATUS " LIB: ${Boost_LIBRARIES}")
include_directories(
${PROJECT_SOURCE_DIR}
${PYTHON_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
macro(add_python_module _name _srccpp)
PYTHON_ADD_MODULE(${_name} ${_srccpp})
target_link_libraries(${_name} ${Boost_LIBRARIES})
endmacro()
add_python_module(ownership ownership.cpp)
Then I run the following commands to build the module
mkdir build; cd build
cmake -DCMAKE_INSTALL_PATH="$BOOST_ROOT/lib" ..
make
The status message after running cmake points to the right boost
installation. (The CMake boost module picks up the environment variable
$BOOST_ROOT) I.e. the CMake variable Boost_LIBARIES points to
$BOOST_ROOT/lib/libboost_python.so.
But, if I check which libraries would actually be used, the system libraries
are listed:
$ ldd ownership.so
# ...
libboost_python.so.1.53.0 => /usr/lib64/libboost_python.so.1.53.0 (0x00007f09abfc1000)
# ...
This is version 1.53, even though the status message above explicitely pointed
to 1.55.
What am I doing wrong? How can I get ldd to pick the library in
$BOOST_ROOT/lib/libboost_python.so.1.55.0?
First of all as I already mentioned in commens you don't need to use CMake RPATH-manipulations
options. Example: http://pastebin.com/UDyYbQ1d, output: standard and custom
Do you know of a way of convincing CMake otherwise even if LIBRARY_PATH is set
This issue is not related to CMake, it's compiler responsibility. Read this discussion.
Solution
You can clear LIBRARY_PATH if you set BOOST_ROOT variable explicitly. And you can check
environment variable in CMakeLists.txt to avoid this problem in future:
string(COMPARE NOTEQUAL "$ENV{LIBRARY_PATH}" "" library_path_warning)
if(library_path_warning)
message(
WARNING
"LIBRARY_PATH environment variable is not empty ($ENV{LIBRARY_PATH}) "
"This may cause dynamic linking errors!"
)
endif()