cmake command can't find boost libraries - c++

I'm using an ubuntu terminal to run a cmake .
But, the boost libraries couldn't be found.
The following Boost libraries could not be found:
boost_program_options
boost_signals
boost_serialization
boost_unit_test_framework
With commands like:
cmake . -DBoost_USE_STATIC_LIBS=ON
The problem persist, also, if I use a location boost_unit_test_framework I'm not getting any result.
How I can install those references?

You can use apt-get command (requires sudo)
sudo apt-get install libboost-all-dev
How to Install boost on Ubuntu?

If you do not want to install all Boost libraries, you can install selectively what you need.
For example, for boost_unit_test_framework you can do:
sudo apt install libboost-test-dev
And the others would be:
sudo apt install libboost-program-options-dev libboost-serialization-dev libboost-signals-dev

Related

Building LiquidFun(Box2D) results in an error

I am currently trying to build LiquidFun, but I get the following error:
CMake Error at CMakeLists.txt:165 (set_target_properties):
set_target_properties Can not find target to add properties to:
Freetype::Freetype
CMake Error at CMakeLists.txt:165 (set_target_properties):
set_target_properties Can not find target to add properties to:
Fontconfig::Fontconfig
...
Here is the repo: https://github.com/google/liquidfun and here are the build steps:
sudo apt-get install cmake
sudo apt-get install libglapi-mesa
sudo apt-get install libglu1-mesa-dev#
cd liquidfun/Box2D
cmake -G'Unix Makefiles'
make
http://google.github.io/liquidfun/Building/html/md__building_linux.html.
Does someone know why this happens?
Thanks in advance.

Testing with google and cmake [duplicate]

Similar issue here.
This is my CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
# Locate GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
# Add test cpp file
add_executable(foo foo.cpp)
# Link test executable against gtest & gtest_main
target_link_libraries(foo ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)
And my foo.cpp:
#include <gtest/gtest.h>
TEST(sample_test_case, sample_test)
{
EXPECT_EQ(1, 1);
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Now, all works fine when using the g++ compiler. However, when attempting to use QNX's compiler, ntox86-c++, I run into this problem:
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE):
Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR
GTEST_MAIN_LIBRARY)
I am on Ubuntu using the ntox86-c++ compiler, googletest, and cmake-gui.
What gives?
Google test was probably not properly installed (libgtest-dev may install only source files that needed to be compiled). I had the same problem and I followed the instructions from http://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/
sudo apt-get install libgtest-dev
sudo apt-get install cmake # install cmake
cd /usr/src/gtest
sudo cmake CMakeLists.txt
sudo make
#copy or symlink libgtest.a and libgtest_main.a to your /usr/lib folder
sudo cp *.a /usr/lib
This worked for me.
As explained by #detrick, the Ubuntu package libgtest-dev only installs sources, so you need to build and install the libraries yourself.
However, there is a much simpler way for building and installing since Ubuntu 18.04 than the manual commands in other answers:
sudo apt install libgtest-dev build-essential cmake
cd /usr/src/googletest
sudo cmake .
sudo cmake --build . --target install
ntox86-c++ looks like a cross-compiler, libgtest-dev package does not provide compiled library for the target platform (QNX).
Since year 2014 compiled libraries was dropped from libgtest-dev and has been added again in Ubuntu-20.04 focal, so find_package(GTest REQUIRED) does not work on Ubuntu-16.04 xenial and Ubuntu-18.04 bionic. The reason is given in /usr/share/doc/googletest/README.Debian (/usr/share/doc/libgtest-dev/README.Debian) and in e.g. in /usr/src/googletest/googletest/docs/V1_7_FAQ.md "Why is it not recommended to install a pre-compiled copy of Google Test (for example, into /usr/local)" section. Difference in compiler flags for the library and for a test could generate incompatible executable code. The problem with 18.04 and 16.04 is the reason why I have decided to add another answer to the old question.
add_subdirectory could be used to compile gtest provided by system package
set(GTest_ROOT /usr/src/googletest/googletest)
add_subdirectory(${GTest_ROOT}
"${CMAKE_CURRENT_BINARY_DIR}/googletest" EXCLUDE_FROM_ALL)
add_executable(test test.cpp)
target_link_libraries(test gtest_main)
# or just gtest if main function is defined
Instead of using system package for googletest sources there are at least 2 variants how to obtain particular version from git (besides obvious submodule), see
https://cmake.org/cmake/help/latest/module/FetchContent.html
https://github.com/google/googletest/blob/master/googletest/README.md
Some time ago I created a dockerfile and it helps me to keep a kind of recipe for installing later on google test on my systems:
apt-get install -y git g++ make cmake
git clone https://github.com/google/googletest.git
cd googletest
mkdir gbuild && cd gbuild && cmake .. && make
cp -r googletest/include/gtest /usr/local/include
cp gbuild/googlemock/gtest/lib*.a /usr/local/lib
cp gbuild/googlemock/lib*.a /usr/local/lib
I hope it helps :)

Opencv 3.2.0 python install

I using python opencv3.2 in ubuntu14.04,install follow open-python 3.2.0.7 : Python Package Index, and installed by pip but still get error when call cv2.imshow()
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /io/opencv/modules/highgui/src/window.cpp, line 583
, so I try build opencv 3.2.0 followed Install OpenCV 3.0 and Python 2.7+ on Ubuntu,but i didn't see the cv2.so after make install
CMake: cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
where i can find cv2.so ?
Sounds like CMake never found your Python dev libararies and/or numpy libraries.
Be sure to sudo apt install libpython2.7-dev and sudo pip install numpy then specify to CMake where these libraries are using the flags:
-D PYTHON2_INCLUDE_DIR=/usr/include/python2.7 \
-D PYTHON2_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so \
-D PYTHON2_NUMPY_INCLUDE_DIRS=/usr/lib/python2.7/dist-packages/numpy/core/include \
-D PYTHON2_PACKAGES_PATH=/usr/lib/python2.7/dist-packages
The above is for python 2.7 only.
then build and install:
make -j$(nproc)
sudo make -j$(nproc) install
The cv2.so file should now reside in your python site-packages or dist-packages folder.

How do you add libraries to CMakeLists?

After searching everywhere I could not find anything or anyone to help me figure out how to add GL GLEW and SDL2 Libraries to my CMakeLists.txt. I am using Ubuntu 14.04 LTS and I installed the following libraries with
sudo apt-get install libsdl2-dev #for SDL-2
sudo apt-get install libgl-dev #for GL
sudo apt-get install libglew-dev #for GLEW
This all worked great, and i was able to compile in g++ with this commmand
g++ ./main.cpp ./display.h ./display.cpp ./shader.cpp ./shader.h -l SDL2 -l GL -l GLEW
Now I need to switch to CMake Compiler and I have no clue how to add the libraries GL, GLEW, and SDL2 to the CMakeLists.txt.
The way to include the libraries depends on a few things. Some packages such as sdl2 have pkgconfig files that define the libraries and includes to use.
Cmake comes with a FindPkgConfig module that can get it for you.
For example:
include(FindPkgConfig)
pkg_check_modules(SDL2 REQUIRED sdl2)
target_link_libraries(executablename ${SDL2_LIBRARIES})
You can also manually add them with the target_link_libraries function.
Other packages have "Find" modules like GLEW: /usr/share/cmake-*/Modules/FindGLEW.cmake
CMake has lots of great docs in the man pages, and on their wiki as #Mikael Persson mentioned.

Linux, Eclipse C++, how to connect ffmpeg libs to your project?

So I downloaded FFmpeg from svn. Compiled and installed into system. in /usr/local it created ./lib and ./include. one with includes and one with libs in form of *.a files.
I downloaded eclipse Helios for C++ and created new simple project. I included ffmpeg headers into my C++ file. in project properties in C/C++Build in settings I declared ffmpeg libs (Library search path was declared)
I wrote some simple code that calls functions from headers.
But for all ffmpeg functions I used it gave me errors of eclipse not seeing ffmpeg.
So I wonder - how to connect ffmpeg libs to my project (or may be there is any way to compile ffmpeg not into .a and it would work with .so)?
I had the same problem on my ubuntu 12.04 and I fixed it by compiling ffmpeg and x264 in this way:
I removed the folders of ffmpeg and x264 and then typed this in the terminal:
sudo apt-get remove ffmpeg x264
sudo apt-get autoremove
and then
sudo apt-get update
sudo apt-get upgrade
then
sudo apt-get install make automake g++ bzip2 python unzip patch subversion ruby build-essential git-core checkinstall yasm texi2html libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libvdpau-dev libvorbis-dev libvpx-dev libx11-dev libxfixes-dev libxvidcore-dev zlib1g-dev
installing x264
sudo git clone git://git.videolan.org/x264.git
cd x264
sudo ./configure --enable-shared --prefix=/usr/local
sudo make
sudo make install
cd ..
installing libvpx
sudo wget http://webm.googlecode.com/files/libvpx-v0.9.7-p1.tar.bz2
sudo tar xvjf libvpx-v0.9.7-p1.tar.bz2
cd libvpx-v0.9.7-p1
sudo ./configure --enable-shared --prefix=/usr/local
sudo make
sudo make install
cd ..
check if /etc/ld.so.conf contains the lines /usr/lib and /usr/local/lib. if not then add them and save it
then run
sudo ldconfig
installing ffmpeg
sudo wget http://ffmpeg.org/releases/ffmpeg-0.8.10.tar.bz2
sudo tar xvjf ffmpeg-0.8.10.tar.bz2
cd ffmpeg-0.8.10
./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-shared --prefix=/usr/local
sudo make
sudo make install
cd ..
sudo ldconfig
in your project you should include the headers in this way:
#include<libavformat/avformat.h>
#include<libavcodec/avcodec.h>
In eclipse you should add the ffmpeg libraries to your project: avutil, avformat, avcodec, m, z ... by going to project->properties->C/C++->Build->Settings->GCC C++-> Linker->Libraries
I hope this works for you
You need to link them with your code. Use -l and -L gcc command line parameters in your make file, or edit the properties for your Eclipse project (go to the project properties->C/C++->Build->Settings->GCC C++-> Linker->Libraries.
if the includes and libraries that you want are in /usr/local/include and /usr/local/lib respectively, seems that you are covered with include and library paths (these directories are in the default search path usually).
Verify that you didn't use lib... when specifying the library that you want to link to, this is prepended by default, e.g. to use libabc.a just specify abc in the library list of the project settings.
If you are getting compile errors (not linker errors), make sure libav* folders reside in /usr/local/include and you include ffmpeg headers with their folder names.
#include libavformat/avformat.h
#include libavcodec/avcodec.h
// ...
You have to define /usr/local/include as an include directory and not libav* folders inside. This is needed because ffmpeg headers themselves reference other headers this way.
This is dependent on platform.
You have to properly configure the ffmpeg libraries with all the right flags mingw/or cygwin. you would get .a files recognizable by eclipse.
as littleadv says you must configure the path to the ffmeg libraries. in the project ->build properties- include(ffmpeg folderand your mingw/cygwin local include ) and linker settings avformat avcodec avfilter avdevice swscale postproc .
Do not forget to set the path variable in your os. Eclipse takes this. Path should point to lib and include /local mingw/cygwin.