I got this error from CMake when building a project that needs to link with Python 3.4 libraries:
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.4.3", minimum required is "3.0")
-- Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS) (Required is at least version "3.0")
Turns out that the CMake available on my system only supported finding Python 3 packages upto version 3.3. To change it to support Python 3.4 was possible by editing two files:
In file /usr/share/cmake-3.4/Modules/FindPythonInterp.cmake find the line containing _PYTHON3_VERSIONS and prepend 3.4 to the versions already listed there.
In file /usr/share/cmake-3.4/Modules/FindPythonLibs.cmake find the line containing _PYTHON3_VERSIONS and prepend 3.4 to the versions already listed there.
I was able to build with Python 3.x libraries after that.
Importing a CMake project into Qt Creator is easier than it is with Eclipse (which is described here). The problem is that you cannot do this properly by using the Import option. Counter-intuitively, you need to Open Project to import a CMake project and make a Qt Creator project from it. After this operation, the project will be available in Qt Creator always, with auto-complete (thanks to indexing) and building (thanks to make).
To do this:
Do Open file or project and open the CMakeLists.txt file.
Choose the Build directory properly. Qt Creator will create a .cbp file here with the name of the CMake project.
Qt Creator will ask you to run cmake once, so that it can learn the include, library and build directories.
You are now in the project Qt Creator has created for you. It will index the files perfectly, so you get excellent auto-complete (better than Eclipse).
Click the Projects button in left column and you will be able to set the command options to build and the environment variables for build.
I tried to build source code that uses Qt5 using CMake. It quit with this error:
CMake Error at CMakeLists.txt:20 (find_package):
By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5Core", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5Core" with any
of the following names:
Add the installation prefix of "Qt5Core" to CMAKE_PREFIX_PATH or set
"Qt5Core_DIR" to a directory containing one of the above files. If
"Qt5Core" provides a separate development package or SDK, be sure it has
I checked for Qt5 packages and they seemed to be installed. There has been a naming change between Qt4 and Qt5 packages in Ubuntu and that threw me off.
What was needed is the package qtbase5-dev. Once I installed it, this error was solved:
For most common libraries, CMake has inbuilt modules which find and include them for compilation and linking. But, there are situations where you need to use library files (say *.so) that are in a custom directory somewhere that need to be linked with the code you are building.
One or more of such paths which should be requested to search for library files while linking can be specified like this:
Many developer SDKs and libraries set their own environment variables. For example, installing OpenNI2 sets OPENNI2_INCLUDE to the path containing its header files. It would be convenient to use these shell environment variables directly in CMake without having to create another CMake variable for it.
This can be done in CMake easily. For example to set the above environment variable as an include directory:
A build type indicates a set of compile-time decisions used while compiling your code. For example, whether or not to optimize or to include debug information. A build type or build mode or configuration is popular in Visual Studio, where C++ projects typically have at least two types: Release and Debug.
CMake has build types and follows similar rules. For compiling C++, there are at least 4 build types in CMake: Release, Debug, MinSizeRel and RelWithDebInfo.
The compile options or rules associated with a build type for a source file of a particular language can be found in /usr/share/cmake-2.8/Modules/Find*.cmake. For compiled languages like C++, look for the matching compiler in /usr/share/cmake-2.8/Modules/Compiler directory.
For C++ code compiled using GNU C++ compiler, see the files /usr/share/cmake-2.8/Modules/Compiler/GNU.cmake for the options used during compilation.
When no build type is provided, I found the compilation string to be: g++ /your/code.cpp
For Release build type, I found the compilation string to be: g++ -O3 -DNDEBUG /your/code.cpp. Note that assert will be disabled with this build type.
For Debug build type, I found the compilation string to be: g++ -g /your/code.cpp
You can specify a build type in the CMakeLists.txt file. For example:
You can also specify a build type at the shell. For example:
$ cmake -D CMAKE_BUILD_TYPE=Debug ..
You can make one of the build types as default, when no build type is provided. For example, to make Release build type as default, add this to CMakeLists.txt:
FindCUDA.cmake is trying to find your CUDA installation directory and failing. I had installed CUDA 7.0 on this machine, which was in /usr/local/cuda-7.0. However, CMake looks for /usr/local/cuda. The CUDA installer is supposed to create a symbolic link /usr/local/cuda pointing to that actual installation directory.
That symbolic link was not there on this computer. This can sometimes happen when you have two CUDA installations and remove one of them. The one removed takes out the symbolic link with it. I had CUDA 6.5 and CUDA 7.0 on this computer before I removed CUDA 6.5.
Anyway, we now know how to fix this:
$ sudo ln -s /usr/local/cuda-7.0 /usr/local/cuda
Pass the CUDA installation directory to the CUDA_TOOLKIT_ROOT_DIR variable directly during the invocation of CMake:
target_include_directories is an useful CMake directive to specify the include directories for building a particular target, as described here. The FindCUDA module for CMake which handles CUDA compilation seems to completely ignore this directive. The include directories specified for the target are not passed to CUDA compilation by nvcc.
This will most commonly result in errors of the form: someheader.h: No such file or directory.
This is a well known limitation of the CUDA module of CMake, as documented here. There seems to be no plan currently to support target_include_directories for CUDA compilation.
The only solution is to switch to include_directories to add these directories for all the targets in the CMakeLists.txt file.
Tried with: CMake 184.108.40.206, CUDA 6.5 and Ubuntu 14.04
The Quickfix feature of Vim is great if you work regularly with source code of languages which need to be compiled, like C or C++. If you are coming from Visual Studio or Eclipse CDT, the Quickfix feature basically gives an IDE-like feel of the edit-compile-fix cycle. (The only missing piece is a visual debugger inside Vim.) For example, you can view the errors and warnings produced on compiling your code in the Quickfix window, jump to the location of the error or warning, fix them and compile the code again. All from within Vim! 🙂
Here are some pointers on how I use Quickfix:
Quickfix is a plugin that ships with Vim. So, there is nothing to install!
If you have a compile command, then redirect its output to a file. Use the -q option of Vim to open this file and you can navigate the errors from there (as described later below). For example:
$ g++ main.cpp 2> errors.txt
$ vim -q errors.txt
If you are using CMake or Make, then life is much easier for you. Open Vim in build directory and invoke make from within it using the command :make. This runs Make and fills up the Quickfix buffer with the error output.
To open the Quickfix window, use the command :copen. In the screenshot above, the Quickfix window is visible at the bottom.
Navigate the Quickfix window as usual and press Enter on any error or warning line. That file, which may not even be in the same directory, is opened in the top window and the cursor is placed at the line and column of the error. Now, is that not like an IDE! 🙂
Now you can jump between the editor window and Quickfix window, using the usual Ctrl + w + w command and fix all the errors.
Once done, you can compile again right from inside Vim using :make. More errors? Fix them. And the edit-compile-edit cycle continues 🙂