I'm trying to set up PCL with eclipse. I have never did any CMake stuff, so I don't really know what is going on.
I have installed PCL with apt-get. Next, I made folder ~/hello_pcl/src, where I saved pcd_write.cpp file and following CMakeLists.txt:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(hello_pcl)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (pcd_write_exe pcd_write.cpp)
target_link_libraries (pcd_write_exe ${PCL_LIBRARIES})
Next, I've done:
cd ~/hello_pcl
mkdir build
cd build
cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ../src
As for the last, I have imported created project into eclipse with File -> Import -> C/C++ -> Existing code as Makefile project.
My problem is: after that, the application runs correctly, but Eclipse code editor marks all includes as Unresolved inclusion and almost every function as Unresolved symbol. Strangely, it does it also with #include <iostream>. I figured out, that it's a problem with indexer. Therefore, I have add /usr/include/c++/4.8 and /usr/include/pcl-1.7 in Project properties -> C/C++ general -> Paths and symbols in Includes tab and GCC C++ language.
It seems to have resolved some of the issues, but there are still functions, that are marked red (see screenshot).
Anyone knows how to solve this problem?
I solved my problem.
It seems, that in this case, typicas workflow for using Eclipse CDT with CMake makes indexer work incorectly.
What I have done is, after invoking cmake command, imported project not as Makefile project, but with Import -> General -> Existing projects into workspace.
After importing project in this way, indexer takes really lot of time (and I suppose it can crush Eclipse, if project is big enough) to parse all includes. But after that everything works fine.
Related
Previously I've worked on the project using Eclipse. There, I'd import an xml file with <includepath> directories and <macro> defines into "paths/symbols" project settings and that would've been enough to index everything. I did a similar trick with VSCode and QtCreator, and it worked as well, but indexing was too slow compared to Eclipse.
Now I'm trying to import the same project into CLion. I'm not planning to build it, I only want the indexing to work. I've added all the local and external folders into the CMakeLists.txt using include_directories and just copying all the paths from my Eclipse config. At first it wouldn't index anything at all. After I marked the "src" folder of my project as "Project Sources and Headers", it seems that now it indexes source/header links, but it still ignores anything specified in the CMakeLists file. How do I force CLion to index all of all the external include paths without actually building? Basically it's set up with mingw, and it's fine with using mingw gcc, g++ and make, and it just fails to do anything without showing any kinds of errors.
The current CMakeLists.txt file looks like...
cmake_minimum_required(VERSION 3.10)
project(GRP)
set(CMAKE_CXX_STANDARD 11)
include_directories("${PROJECT_SOURCE_DIR}/src/...") #hundreds of project dirs
...
include_directories("C:/Users/...") #hundreds of external includes
...
For me in this situation right-clicking on project and selecting Reload CMake Project solved the problem.
I started with building my project with CMake by using the cmake <folder> -G"Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug command (I'm using Ubuntu 14.04). Say the results were written to /home/student/tempFolder/HelloFrameworkApp folder.
The thing is that I have header files needed for he application in /home/student/git/fagot/sw/branches/head/framework/include folder. This is also described in CMakeLists so after I import my project from /home/student/tempFolder/HelloFrameworkApp to Eclipse as existing code as makefile project, it can successfully be built and runs just as expected.
But in the code edit area there are tons of red underlining which makes it clear that Eclipse can't see the include folder I mentioned before. I tried going to Properties -> C/C++ General -> Paths and symbols and adding that include folder to all configurations and languages but it didn't help.
Any suggestions?
CMake creates an Eclipse project for you. Therefore you need to use: Import->General->Existing Project into Workspace.
I was using Boost 1.54.0 and it was located in "/usr/include". We blew that away and installed Boost 1.57.0. It got installed in "/usr/local/include".
Now, my CLion project, which uses CMake cannot find the Boost library. Here is my CMakeLists.txt file:
And here are my errors:
I have no idea how to make CMake look in the correct place for Boost.
According to the FindBoost documentation (http://www.cmake.org/cmake/help/v3.1/module/FindBoost.html), you can set a CMake variable BOOST_ROOT to give CMake a hint about where to look.
In your CMakeLists.txt file, you can add the following before the find_package(Boost...) line:
set(BOOST_ROOT /usr/local)
Update:
I agree with the comments that putting machine specific configuration parameters directly in CMakeLists.txt is not best practice.
As an alternative to directly setting this variable, you can pass options like this to the cmake process in CLion by doing the following:
Navigate to File -> Settings... -> Build, Execution, and Deployment -> CMake. Under Generation, add -DBOOST_ROOT=/usr/local to CMake options.
I am attempting to import a manually-created cmake project that I had been using in a different IDE into Netbeans 8.0.2 on Windows 7. Needless to say, my cmake configuration worked fine there.
Netbeans seems to import the directory fine. I imported it in "automatic" (cmake) mode. However, when I attempt to build the project, I get a rather cryptic (Java?) error message:
Makefile:76: recipe for target 'all' failed
process_begin: CreateProcess(NULL, /C/MinGW/bin/make.exe -f CMakeFiles/Makefile2 all, ...) failed.
make (e=2): The system cannot find the file specified.
Knowing very little about Java, I am not sure how to interpret this error. The first directory (/C/MinGW/bin/make.exe) stands out to me as not being in Windows-format, but I am not sure if that's incorrect. I do indeed have a file by that name, as I copied the longer-named mingw make binary so I would only need to type "make".
Presuming this is being run in the project root, and that the first directory is formatted correctly, I don't see any problem with finding these files.
My CMakeLists.txt is:
cmake_minimum_required(VERSION 2.8.4)
set(Project_Name "Test")
set(Test_VERSION_MAJOR 1)
set(Test_VERSION_MINOR 0)
project(${Project_Name})
include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/inc"
"${CMAKE_CURRENT_SOURCE_DIR}/inc/SDL"
"C:/Users/Bakaiya/Documents/ogre/OgreMain/include"
)
file(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
link_directories(${CMAKE_CURRENT_SOURCE_DIR} ${OPENGL_LIBRARIES})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_executable(${Project_Name} ${SOURCE_FILES})
target_link_libraries(${Project_Name} SDL2main SDL2 OgreMain) #Ogre
Running the "generate makefile" command in the IDE completes without issue, but does not fix the problem. Additionally, clean fails, but "help" does work.
This is a problem within the IDE, it seems, because if I run make from the command line in the project root, it builds without issue.
Also, I fiddled with the file path mode setting under C/C++ -> Project Options, and it did nothing. Even set to absolute, what seems to be a relative path (CMakeFiles/Makefile2) is still in the failed command. I'm not sure if that option is expected to change that sort of reference or not.
What could be wrong with this imported project to cause this issue?
However, when I attempt to build the project, I get a rather cryptic (Java?) error message:
This is an error shown by netbeans to tell you, that it was unable to execute make command successfully. Usually this indicates a wrong setting of your (mingw-) tools.
Here are some points you can check:
Don't use make from mingw/bin, you have to use the one from mingw/msys/... There's a mingw make within mingw's msys folder, usually C:\<Path to MSYS>\<Version>\bin\make.exe - this bin-path must also be set in PATH environment variable! If MSys wasn't installed with your mingw installation, please install it.
Please check the tools set in Tools -> Options -> C/C++ -> Build Tools; you can test them by clicking Versions....
(If existing) Clean the CMake generated files and clean the cmake's cache. If not done yet, please use an out-of-source build as described here.
Can you build your project from terminal (without netbeans)?
The first directory (/C/MinGW/bin/make.exe) stands out to me as not being in Windows-format, but I am not sure if that's incorrect.
This is ok and intended by mingw - it uses linux / unix like paths.
Update
Which make program should I use?
Many MinGW users have a problem because they use mingw32-make.exe from
the MinGW installation. While this seems like the right choice, it
actually breaks the build. The problem is that this is a non-Posix
implementation of the Unix make program and doesn't work well at all.
In fact, thats why the MinGW people renamed it! They've also made a
FAQ entry explaining why you should not use mingw32-make.exe. Instead,
you should use the make.exe program from the MSYS package.
As of NetBeans 6.1, the Build Tools panel no longer allows a user to
select mingw32-make. If you choose a MinGW compiler collection it will
default to make in MSYS. If MSYS is not found, it will tell you no
make program has been found.
(http://wiki.netbeans.org/MinGWInCCDevelopmentPack)
I wish to use PCL with Eclipse on Ubuntu. Now, that's what I did this far:
a) Installed PCL with apt-get:
sudo add-apt-repository ppa:v-launchpad-jochen-sprickerhof-de/pcl
sudo apt-get update
sudo apt-get install libpcl-all
b) Created new project in eclipse
~/workspace/hello_pcl/
c) In above folder created src/pcd_write.cpp from this source.
d) Created following CMakeLists.txt:
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(hello_pcl)
find_package(PCL 1.3 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcd_write_test pcd_write.cpp)
target_link_libraries(pcd_write_test ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})
e) Set include path /usr/include/pcl-1.7/ in project setting
My question is: What I should do now to build projects with Eclipse? Should I make the project with cmake:
cd ~/workspace/hello_pcl/build
cmake ../src
make
Or should I do something else? I'm fairly new to cmake.
I suppose I should add libraries to project setting, but didn't find on pcl page, what are names of these libraries...
EDIT:
OK, thanks to the comment I was able to create and run the hello_pcl application (I used solution from How to configure eclipse CDT for CMake), but now I have further issue. Application works, but the Eclipse code editor still underlines all PCL-dependent commands and signs them as Field [...] could not be resolved as well as includes Unresolved inclusion [...]. Strangely, #include <iostream> makrs also as unresolved. Should I include somehow PCL libraries?
I have managed to solve my problem, this is what I have done:
Basically, point from a) to d) are correct (though I have created the project not in eclipse workspace folder, but in ~/). Now is the trick: It seems, that when following typical workflow for using CMake with Eclipse CDT, indexer behaves incorrectly. Even after adding specific include path to Path and Symbols in project properties.
What is essential here, is that after creating CMakeLists.txt (maybe for start is better to set target_link_libraries for all libraries - ${PCL_LIBRARIES}), one has to build the project with (in my case):
cd ~/hello_pcl/build
cmake -G "Eclipse CDT4 - Unix Makefiles" ../src
Of course, if You want to have Debug build, You have to specify proper option.
Next step is to add project to eclipse workspace but not as a Makefile project, but as general project, that is:
File -> Import -> General -> Existing projects into workspace.
Place path to the build folder in Select root directory (~/hello_pcl/build in my case) and click Finish.
This is the moment, when indexer parses all includes. And it takes a lot of time. But after that, everything seems to work fine.