I just got the pcl installed and would like to run the examples in the folder /pcl-pcl-1.7.1/examples. The different examples each have CMakeLists.txt in them, so I thought I just do a cmake . in the terminal followed by make to compile it.
After doing that in the terminal I got
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 2.8)
So I looked into the cmake file and the weird thing is that these cmake files don' t have the normal cmake layout; which starts with cmake_minimum_required(VERSION 2.8 FATAL_ERROR) and then some other stuff.
The CMakeLists.txt file I looked into looked like:
PCL_ADD_EXAMPLE(pcl_example_fast_point_feature_histograms FILES example_fast_point_feature_histograms.cpp
LINK_WITH pcl_common pcl_kdtree pcl_search pcl_features pcl_io)
PCL_ADD_EXAMPLE(pcl_example_normal_estimation FILES example_normal_estimation.cpp
LINK_WITH pcl_common pcl_kdtree pcl_search pcl_features pcl_io)
PCL_ADD_EXAMPLE(pcl_example_point_feature_histograms FILES example_point_feature_histograms.cpp
LINK_WITH pcl_common pcl_kdtree pcl_search pcl_features pcl_io)
PCL_ADD_EXAMPLE(pcl_example_principal_curvatures_estimation FILES example_principal_curvatures_estimation.cpp
LINK_WITH pcl_common pcl_kdtree pcl_search pcl_features pcl_io)
PCL_ADD_EXAMPLE(pcl_example_shape_contexts FILES example_shape_contexts.cpp
LINK_WITH pcl_common pcl_kdtree pcl_search pcl_features pcl_io)
PCL_ADD_EXAMPLE(pcl_example_spin_images FILES example_spin_images.cpp
LINK_WITH pcl_common pcl_kdtree pcl_search pcl_features pcl_io)
PCL_ADD_EXAMPLE(pcl_example_rift_estimation FILES example_rift_estimation.cpp
LINK_WITH pcl_common pcl_kdtree pcl_search pcl_features pcl_io)
PCL_ADD_EXAMPLE(pcl_example_difference_of_normals FILES example_difference_of_normals.cpp
LINK_WITH pcl_common pcl_kdtree pcl_search pcl_features pcl_io pcl_segmentation pcl_sample_consensus)
I don' t know a whole lot about cmake but I do know it starts with defining stuff.
So my question is how do I now compile these pcl examples? Or is there something different about the cmake file?
CMake allows the build to be split up into several distinct CMakeLists.txt file, which do not necessarily have to work on their own.
In your case, the project probably uses add_subdirectory from the CMakeLists.txt in pcl-pcl-1.7.1 to include the one in examples. The CMakeLists.txt in examples is incomplete, it cannot be run on its own but only when being included as part of the top-level CMake file.
You have two options now:
Use a modified top-level CMakeLists.txt to include the one from examples. The easiest way to achieve this is probably to start with the top-level file that ships with pcl and throw out everything that you don't need. Depending on the amount of CMake-voodoo present in that file, you might have to fiddle quite a lot to get it to work.
As suggested by #arrowdodger in the comments, just run the full CMake configure on the top-level directory and then selectively compile only the targets that you are interested in. If you are using the Makefile generator, you can just give the names of the requested targets on the command line (maybe write a shell script so you don't have to memorize them all). Most IDEs should also allow to only build a subset of the targets in a project.
There are two ways in which you may compile examples.
1) change CMakeLists.txt, un-comment line
### ---[ Set up for examples
include("${PCL_SOURCE_DIR}/cmake/pcl_examples.cmake")
2) if you've already built pcl once, just go to CMakeCache.txt file in your build directory and do below change.
BUILD_examples:BOOL=ON
then just do
make
Related
I've got a shared library source directory that needs to be formatted in a particular way, and I've been unsuccessful in getting CMake to allow building of individual libraries.
Here's a basic example of the directories
libraries/
CMakeLists.txt
a/
CMakeLists.txt
a.h
src/a.cpp
test/
CMakeLists.txt
exe_test.cpp
b/
CMakeLists.txt
b.h
src/b.cpp
Library a depends on b. If I add_subdirectory() for both of them in the top-level CMakeLists.txt, I can build the whole libraries folder using cmake. However, I don't want to do this. I'd like to be able to build just b, and if I choose to build a, it automatically links to b using relative paths. For this example it may seem trivial, but imagine roughly two dozen libraries in this kind of format, and we'd like to avoid nesting.
target_link_libraries(a PUBLIC ../b) does not work. Neither does add_subdirectory(..).
When i try to run cmake to build a project where i include the SFML library i get the following Error: SFML found but version too low (requested: 2.4, found: 1.x.x)
I downloaded only the source of the newest Version of the library (SFML-2.4.2). I than run cmake (with MinGW Makefiles) And build the binaries into the same folder.
I copied the FindSFML into an subfolder of my project.
After that i had the following folder structure
SFML-2.4.2\
cmake\
Modules\
FindSFML.cmake
CMakeFiles
doc
...
include
lib
src
..
sfml-games\
tetris\
cmake_modules\
FindSFML.cmake
CMakeLists.txt
main.cpp
tetris-build
...
My CMakeLists.txt contains the following stuff:
project(Tetris)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
Find_package(SFML 2 REQUIRED system window graphics network audio)
include_directories(${SFML_INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARY})
I found that in cmake the entry CMAKE_INSTALL_PREFIX (which i dont get) is set to C:\Program Files (x86)\SFML so i put the library and the lib of SFML into C:\Program Files (x86)\SFML. (what is that CMAKE_INSTALL_PREFIX and should i realy always copy the library and lib folders into my C:\Program Files (x86)\ ??). Now my cmake runs through but when i try to compile the code i get a lot of undifined references to '_imp__....'
By the way on linux i just installed SFML via sudo apt-get install libsfml-dev and it works out of the box.
You're confusing things. CMAKE_INSTALL_PREFIX is the default location where to put SFML when you build the install target (i.e. running make install). This has nothing to do with your other issues.
You don't have to install SFML (or any other library) somewhere under C:\Program Files. That's completely up to you.
What I found to be rather neat is installing MinGW to C:\usr (or creating a symlink to your installation folder) and also use that path for CMAKE_INSTALL_PREFIX when building SFML.
This way MinGW should behave pretty much the way you're used to from Linux (i.e. not having to specify paths for include dir or libraries etc.).
As for your undefined reference errors, you should create a new question only asking for these (and then include at least a few of them), as they have nothing to do with the installation directory.
Right now I can only guess, but it's most likely due to you using the wrong CMake variables for the linker. You won't notice this on Linux, since SFML will be in the default search path (which will also happen if you use C:\usr as described above).
To try fixing this, use this line:
target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
I searched everywhere but most of the answers are relevant to Linux, not many use CLion on Windows.
So I extracted boost_1_60_0 into C:\ and now my path for the boost root folder is
C:\boost_1_60_0
I got the CMakeLists.txt file where I'm trying to set the root directory of boost and include it, but it doesn't recognize it:
set(Boost_Path "C:/boost_1_60_0")
find_package(Boost 1.60.0)
if(Boost_FOUND)
message(STATUS "It works!")
endif()
What am I doing wrong?
I try to link Boost libraries in my CMakeList on Windows. Here is my code :
set(BOOST_ROOT C:/lib/boost_1_59_0)
set(BOOST_LIBRARYDIR C:/lib/boost_1_59_0/lib)
find_package(Boost COMPONENTS system REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(${EXECUTABLE_NAME} ${Boost_LIBRARIES})
endif()
My folder "lib" contains all the lib build by bjam, including "libboost_system-vc140-mt-1_59.lib" and "libboost_system-vc140-mt-gd-1_59.lib".
It works for headers, but It doesn't find libs. I have this error :
Error:Unable to find the requested Boost libraries.
Boost version: 1.59.0
Boost include path: C:/lib/boost_1_59_0
Could not find the following Boost libraries:
boost_system
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.
I try a lot of things (this is the first time I ask a question here, I really search a lot before asking) like "add_definitions(-DBOOST_ALL_NO_LIB)" or change the path to "C:\lib\boost_1_59_0" but I find nothing to fix it.
If anyone have an idea, I will thank him a lot !
CMake Configuration- Boost- Visual Studio - C++
Step 1: Download CMake installation file, install and save it in local disk
Step 2: Create 2 Folders in local disk a) Raw File b)Solution File
Step 3: Raw File folder- Create a Main.cpp file and paste your raw c++ code it it and save. Now in the same folder create a txt file named CMakeLists and paste the following code in it and save.
cmake_minimum_required(VERSION 3.7)
project (cmboosttest)
#find_package(Boost REQUIRED)
#include_directories(${Boost_INCLUDE_DIR})
add_executable(boosttest ${PROJECT_SOURCE_DIR}/Main.cpp)
Step 4: Open CMake choose Raw File folder in browse source and Solution File Folder in browse build.
Step 5: Click Configure. Once it succeeds, click Generate.
Step 6: When you open the Solution File folder, you can see the built solution file. Click on it and your program will open in Visual Studio. Now, build your program in VS.
Hope this helps!
I'm trying to use cmake (on Linux with GNU make and g++) to build a project with two sub-directories: MyLib and MyApp. MyLib contains source for a static library; MyApp needs to link against that library. I'm trying to build on Linux with generated makefiles using the following CMakeLists.txt:
cmake_minimum_required (VERSION 2.6)
project (MyProj)
include_directories (MyLib)
file(GLOB MyLibSrc MyLib/*.cpp)
add_library(MyLibrary STATIC ${MyLibSrc})
file(GLOB MyAppSrc MyApp/*.cpp)
add_executable(MyApplication ${MyAppSrc})
target_link_libraries(MyApplication MyLibrary)
This 'almost' works. It fails at link time because while it generates libMyLibrary.a - it is in the root. When I add:
link_directories(${MyProj_BINARY_DIR})
it makes no difference.
I've got a few (inter-linked) questions:
What's the best way to coerce cmake into building my library and executable into a 'staging directory' — say MyStage — to keep targets separate from source?
How do I convince cmake to link the application against the library?
If I wanted to build a debug and a release version, what's the best way to extend my cmake scripts to do this — making sure that the debug application links against the debug library and the release application against the release library?
I'm a relative newcomer to cmake. I've read what I can find on the web, but find myself struggling to get my library to link with my executable. This sort of a configuration, to my mind, should be quite common. An example from which to crib would be very helpful, but I've not found one.
Well, it is better to read this example and do exactly as suggested.
cmake_minimum_required (VERSION 2.6)
project (MyProj CXX)
add_subdirectory(MyLib)
add_subdirectory(MyApp)
Then for each subdirectory specified, CMakeLists.txt files are created
MyLib\CMakeLists.txt
file(GLOB SRC_FILES *.cpp)
add_library(MyLib ${SRC_FILES})
MyApp\CMakeLists.txt
file(GLOB SRC_FILES *.cpp)
add_executable(MyApp ${SRC_FILES})
target_link_libraries(MyApp MyLib)
Use "out of the source build". Make a directory used only for build and while in it, call
cmake <path to the sources, it may be relative>
Either use
link_directories(${MyProj_BINARY_DIR}/MyLib)
or make CMakeLists.txt in each subdirectory - that would be better for project larger than very small.
This is a bit tricky, check out CMAKE_BUILD_TYPE in the docs (you can set it and/or "if" by it). You can also set it from command line:
cmake -DCMAKE_BUILD_TYPE=Debug
I've discovered the 'optimal' solution to (1)... so, thought I should post it here:
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY MyStage)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY MyStage)
The thing that confused me previously is that static libraries are not considered a LIBRARY by Cmake - they're considered to be ARCHIVEs.
Do not add libraries and executables in the root Cmakelists.txt. Add these libraries and executables in Cmakelists.txt of subdirectories.