How to install shared library and include files manually in linux? - linux

I am trying to build and install TBB library from source so that it can be used for OpenCV to take advantages of multiple cores on my raspberry pi.
I was able to build TBB from source without any problems using this steps.
(Source : How do I build OpenCV with TBB on Raspberry Pi?)
wget -O ~/tbb43_20150316oss_src.tgz --no-check-certificate https://www.threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb43_20150316oss_src.tgz
tar -xvzf tbb43_20150316oss_src.tgz
cd tbb43_20150316oss
make tbb CXXFLAGS="-DTBB_USE_GCC_BUILTINS=1 -D__TBB_64BIT_ATOMICS=0"
However, it's not getting detected while cmake step of building OpenCV.
Where do I add generated .so files and .h files to system paths so that cmake can detect it ?
Thanks.

Run 'make install' in the TBB source directory after running make it should install the files to the correct locations.

You can use the CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH environment variables to help CMake find your custom-built TBB by prefixing your cmake command like so:
CMAKE_INCLUDE_PATH=~/tbb43_20150611oss/include/ \
CMAKE_LIBRARY_PATH=~/tbb43_20150611oss/build/*_release/ \
cmake -DWITH_TBB=ON -DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DBUILD_NEW_PYTHON_SUPPORT=ON \
-DINSTALL_C_EXAMPLES=ON \
-DINSTALL_PYTHON_EXAMPLES=ON \
-DBUILD_EXAMPLES=ON ..

As a work around, I created tbb.pc file to /usr/lib/pkgconfig/.
Here is a sample of that file. https://github.com/openembedded/meta-oe/blob/master/meta-oe/recipes-support/tbb/tbb/tbb.pc
Change prefix, libdir and include dir path according to your own tbb path and you're good to go. Hope it helps.

Related

How to compile c++ programs in the new c++ driver provided by Datastax in Linux

I am new to Cassandra. I installed c++ driver from Datastax. Can some one please provide me the steps like in which path I have to create the ā€˜.cā€™ file and how I can compile it. I can see some example programs in example folder. Can anyone plz tell me how to compile the example programs.
The cpp-driver uses cmake and depends on libuv. So the first steps would be to ensure you have cmake installed as well as libuv. Depending on your linux distribution it may be as simple as using package manager like apt or yum (i.e. sudo apt-get install cmake libuv-dev)
Building is just a matter of running the following steps in the cpp-driver directory:
cmake .
make
sudo make install
This will install libcassandra.so to somewhere in your lib path. You can then link by providing '-lcassandra' in your parameters to clang or gcc (i.e. clang myfile.c -o myfile -lcassandra)
There is very comprehensive documentation on building from source here.

Compiling FFmpeg lib and add it to NDK sources on Windows8

I've seen some articles about how to compile and uses FFmpeg for Android.
These are 2 good examples - example1 and example2
Unfortunately, non off them, or others I found helped me. In those two examples a build_android.sh is created and configure the FFmpeg's configuraion file and call to make. Every time when I'm running the script I'm getting the following error:
c:\android\development\android-ndk-r9\sources\ffmpeg>sh build_android.sh
c:/android/development/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebu
ilt/windows-x86_64/arm-linux-androideabi/bin/bin/arm-linux-androideabi-gcc is un
able to create an executable file.
C compiler test failed.
If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user#ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "config.log" produced by configure as this will help
solving the problem.
Makefile:2: config.mak: No such file or directory
Makefile:49: /common.mak: No such file or directory
Makefile:92: /libavutil/Makefile: No such file or directory
Makefile:92: /library.mak: No such file or directory
Makefile:169: /doc/Makefile: No such file or directory
Makefile:170: /tests/Makefile: No such file or directory
make: *** No rule to make target `/tests/Makefile'. Stop.
Makefile:2: config.mak: No such file or directory
If someone encountered and solved this issue it'll be much appreciated!
After trying the suggested script I ran into a new problem that I couldn't solved, this is the output of the script:
.... Enabled components list....
In the end of the list I got the following:
Enabled indevs:
dv1394 v4l2i
fbdev
Enabled outdevs:
fbdev v4l2
License: LGPL version 2.1 or later
Creating config.mak, config.h, and doc/config.texi...
WARNING: C:/android/development/android-ndk-r9/toolchains/arm-linux-androideabi-
4.8/prebuilt/windows-x86_64/bin/arm-linux-androideabi-pkg-config not found, libr
ary detection may fail.
make: *** No rule to make target libavfilter/libavfilter.so', needed by all-ye
s'. Stop.
make: *** No rule to make target install-libavfilter-shared', needed by instal
l-libs-yes'. Stop.
Can you paste what's in your build_android.sh file which you've copied inside the FFmpeg directory?
I've got the same error when one of the variables defined at the start of the script where set incorrectly. Check to see if your NDK or SYSROOT or TOOLCHAIN variables are set to a valid path!
I've tried using the following steps and it worked for me:
1) Download FFmpeg
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
2) Create a file called build_android.sh inside the FFmpeg directory
cd ffmpeg; touch build_ffmpeg_for_android.sh;
3) Add the following content to the file
#!/usr/bin/env bash
NDK=$HOME/Software/Android/android-ndk-r10/
SYSROOT=$NDK/platforms/android-19/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64
function build_one
{
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-doc \
--disable-symver \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make -j4
make install
}
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one
4) Make the script executable
chmod +x build_ffmpeg_for_android.sh
5) Start the build of FFmpeg for Android (ARM)
(run the script with Bash, i.e. /usr/bin/bash not /usr/bin/sh)
./build_ffmpeg_for_android.sh
I was getting the same errors as #powerX and I was able to solve the issue using a different method from #dZkF9RWJT6wN8ux.
Though I am using Ubuntu 13.10, I hope you find my answer helpful. With android NDK r9 and FFMPEG 2.2 "Muybridge" release, I was finally able to accomplish the third step entitled "Build FFMPEG" from #powerX example1 link: http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/
I finally fixed this by changing the SYSROOT variable in the build_android.sh file to point to ".../android-19/arch-arm" instead of .../android-9/arch-arm".
Hope this helps.

Prerequisites for gcc-4.7.2: ppl-0.11 fails to find gmp-4.3.2

I'm trying to build prerequisites for gcc-4.7.2.
Both ppl-0.11 and gmp-4.3.2 are the recommended versions in <gcc_src>/gcc-4.7.2/gcc/doc/HTML/prerequisites.html
I have built and installed gmp-4.3.2 (with --enable-cxx set)
Attempting to configure ppl-0.11 fails.
configure: error: Cannot find GMP version 4.1.3 or higher.
GMP is the GNU Multi-Precision library:
see http://www.swox.com/gmp/ for more information.
When compiling the GMP library, do not forget to enable the C++ interface:
add --enable-cxx to the configuration options.
This is my configure line:
./configure \
--prefix=$PREFIX \
--with-gmp=$PREFIX \
--with-gmp-prefix=$PREFIX \
If I look in the directory where I specified with-gmp, here is the installed gmp:
$ grep MP_VERSION $PREFIX/include/gmp*
$PREFIX/include/gmp.h:#define __GNU_MP_VERSION 4
$PREFIX/include/gmp.h:#define __GNU_MP_VERSION_MINOR 3
$PREFIX/include/gmp.h:#define __GNU_MP_VERSION_PATCHLEVEL 2
.
$ l $PREFIX/include/gmp*
$PREFIX/include/gmp.h
$PREFIX/include/gmpxx.h
.
$ l /$PREFIX/lib/libgmp*
$PREFIX/lib/libgmp.a
$PREFIX/lib/libgmp.la
$PREFIX/lib/libgmp.so -> libgmp.so.3.5.2
$PREFIX/lib/libgmp.so.3 -> libgmp.so.3.5.2
$PREFIX/lib/libgmp.so.3.5.2
$PREFIX/lib/libgmpxx.a
$PREFIX/lib/libgmpxx.la
$PREFIX/lib/libgmpxx.so -> libgmpxx.so.4.1.2
$PREFIX/lib/libgmpxx.so.4 -> libgmpxx.so.4.1.2
$PREFIX/lib/libgmpxx.so.4.1.2
Am I missing something?
As far as I can tell, GMP is available and of the requisite version
Depending on what distro you are running, have you tried to install the gmp-devel package (i.e. yum install gmp-devel on Fedora/RedHat etc)?
PPL will by default try to use default locations for GMP. If you use crosstool-ng, you must do either a cross-native or canadian-cross build. If you are doing this manually, specify CXXFLAGS to PPL's ./configure, with a -I<path-to-gmp-header> and a -Wl,-L<path-to-gmp-libs>. This allows the PPL ./configure to find the correct version of GMP.
Apparently a PPL configure with,
--prefix=$PREFIX \
--with-gmp=$PREFIX \
--with-gmp-prefix=$PREFIX \
Is not enough. I sleuthed through the ./configure script and was hacking up crosstool-ng before I realized that I was no longer building a cross-compiler, but a canadian-cross when I wasn't using my distro gcc, but another host compiler with a lower glibc shared library. This is useful if you want your compiler to run on a larger class of machines. It is unlikely that the glibc version of the build compiler will effect much.
I still had to patch 120-ppl.sh in crosstool-ng,
do_ppl_for_build() {
...
ppl_cxxflags="${CT_CFLAGS_FOR_BUILD}"
+ ppl_cxxflags+=" -I${CT_BUILDTOOLS_PREFIX_DIR}/include "
+ ppl_cxxflags+=" -Wl,-L${CT_BUILDTOOLS_PREFIX_DIR}/lib "
if [ "${CT_PPL_NEEDS_FPERMISSIVE}" = "y" ]; then
ppl_cxxflags+=" -fpermissive"
fi
So I also faced the same issue and what I did was:
1) Went inside gmp-4.3.2 folder
2) make distclean
3) ./configure --prefix=/home/sen/Documents/mingw/downloads/gmp_build --enable-cxx
4) make && make install
5) Went inside ppl-0.11 folder
6) ./configure --prefix=/home/sen/Documents/mingw/downloads/ppl_build --with-gmp-prefix=/home/sen/Documents/mingw/downloads/gmp_build --enable-cxx
7) make & make install
Took some 10-20 mins to compile and things were fine.
Thanks,
Sen
After years, the issue has been run into. The solution is firstly to download last version of gmp. Then, copy the path as in like the picture. Don't forget to ./configure with --enable-cxx, which is really important point. ./configure --enable-cxx. Now time is to ppl installation, ./configure -help indicates that --with-gmp=DIR search for libgmp/libgmpxx in DIR/include and DIR/lib. So write ./configure --with-gmp=<<dir of gmp as shown in first picture, you may have a different path>>
I wrote, respectively, ./configure --with-gmp=/usr/local/include, make, sudo make install then it works like a charm!

Configure and Build OpenCV to Custom FFMPEG Install

I cannot seem to configure OpenCV to link to a non-/usr/lib set of FFMPEG libraries.
My LD_LIBRARY_PATH contains a direct link to the folder for the custom install of FFMPEG:
LD_LIBRARY_PATH=/pathto/ffmpeg-0.10.2/lib
Additionally, I've configured pkgconfig as:
PKG_CONFIG_PATH=/samepathto/ffmpeg-0.10.2/lib/pkgconfig/
Within CMake however I cannot find any setting for path to FFMPEG - either in basic or custom. The only setting related to FFMPEG appears to be WITH_FFMPEG type setting (set to ON).
I can build OpenCV but it seems to link to the system libraries for libavcodec - this causes a conflict as the system libraries are version .52 and the version in my install of FFMPEG are .53. Linking an app on a machine without the same system libraries seems to NOT link to my custom install of OpenCV (specifically the libavcodec) because of this (I'm installing these libraries on a shared network folder).
I am not sure if my problem is with building and linking to the wrong version of FFMPEG or if it is something with my environment after building (and then linking to the wrong ffmpeg).
I am building on Linux, Redhat 6, OpenCV 2.3.1.
Something like
export LD_LIBRARY_PATH=/ffmpeg_install_path/lib/
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/ffmpeg_install_path/lib/pkgconfig
export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR:/ffmpeg_install_path/lib/
should work. At least it works for OpenCV 2.4.x on my Ubuntu.
For OpenCV 3.x and ffmpeg 3.x, I have to apply the following patch
diff --git a/cmake/OpenCVFindLibsVideo.cmake b/cmake/OpenCVFindLibsVideo.cmake
index 13b62ac..bab9df3 100644
--- a/cmake/OpenCVFindLibsVideo.cmake
+++ b/cmake/OpenCVFindLibsVideo.cmake
## -228,6 +228,12 ## if(WITH_FFMPEG)
if(FFMPEG_libavresample_FOUND)
ocv_append_build_options(FFMPEG FFMPEG_libavresample)
endif()
+ CHECK_MODULE(libavcodec HAVE_FFMPEG)
+ CHECK_MODULE(libavformat HAVE_FFMPEG)
+ CHECK_MODULE(libavutil HAVE_FFMPEG)
+ CHECK_MODULE(libswscale HAVE_FFMPEG)
+ CHECK_MODULE(libswresample HAVE_FFMPEG)
+ CHECK_MODULE(libavresample HAVE_FFMPEG)
if(HAVE_FFMPEG)
try_compile(__VALID_FFMPEG
"${OpenCV_BINARY_DIR}"
And with the following script to build
#!/bin/bash
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/Applications/ffmpeg/lib
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HOME/Applications/ffmpeg/lib/pkgconfig
export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR:$HOME/Applications/ffmpeg/lib
cmake \
-D BUILD_EXAMPLES=ON \
-D BUILD_TESTS=OFF \
-D OPENCV_EXTRA_EXE_LINKER_FLAGS="-Wl,-rpath,$HOME/Applications/ffmpeg/lib" \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$HOME/Applications/opencv \
/path/to/opencv
Also, when build ffmpeg, I have to enable flags --enable-avresample.
It's years after the question was asked, but I recently ran into the kinds of issues described in this question! I'd like to add my input.
First: I only built the static ffmpeg libraries (for reasons), which the opencv build process is somewhat hostile towards. There have been posts by opencv developers stating that they don't support an opencv build against static ffmpeg libraries, but my thinking was "what if you're also building static opencv libraries? Certainly that should be supported?"
And the answer is yes, you can compile static opencv libraries against static ffmpeg libraries! I did this with opencv 4.1.1 against ffmpeg 4.2. I had to use the following cmake options:
cmake3 \
-D BUILD_opencv_apps=OFF \
-D BUILD_opencv_python2=OFF \
-D BUILD_SHARED_LIBS=OFF \
-D WITH_FFMPEG=ON \
-D OPENCV_FFMPEG_SKIP_BUILD_CHECK=ON \
These options result in a set of opencv static libraries that include whatever ffmpeg static libraries that you've also built, assuming your PKG_CONFIG_PATH is setup to correctly find those libraries (or if you've installed them to some default system location).
Q/A:
Why can't we build apps?
The opencv build process assumes that you are building and linking against shared libraries, even if you only build static libraries. This seems like a shortcoming in the build process rather than a technical limitation; perhaps some day this will be fixed.
What is the OPENCV_FFMPEG_SKIP_BUILD_CHECK flag?
There is a step in ffmpeg's cmake process where an application is built and linked using the same faulty build process as opencv's other applications. It's faulty in the sense that the process assumes that you're linking against shared libraries when it doesn't need to; you can perform the same build steps yourself while not making that assumption and create a working application. Thus, this build check needs to be turned off in order for opencv to accept that yes, in fact, any static libraries it finds are okay to use. This is
And why do you disable python support?
The opencv python build process explicitly produces a shared library loadable by Python.
Does this imply that you're still building the tests suite even with the static libraries?
Yes. But I haven't tried running them
In addition to Andrey's answer:
I found that (for my configuration) the opencv 4.1.1 build-system did not correctly add the ffmpeg library path (though it did set the include directory.) My workaround was to supply these paths with the following cmake build arguments:
-DCMAKE_SHARED_LINKER_FLAGS=" -Wl,-rpath-link $FFMPEG_LIBDIR -L$FFMPEG_LIBDIR"
-DCMAKE_MODULE_LINKER_FLAGS=" -Wl,-rpath-link $FFMPEG_LIBDIR -L$FFMPEG_LIBDIR"
-DCMAKE_EXE_LINKER_FLAGS=" -Wl,-rpath-link $FFMPEG_LIBDIR -L$FFMPEG_LIBDIR"
where $FFMPEG_LIBDIR is the path to your ffmpeg library binaries.
It was necessary to use the -rpath-link otpion, because the build system didn't supply all necessary ffmpeg library arguments for my ffmpeg installation.
Examining modules/videoio/cmake/detect_ffmpeg.cmake, it looks like FFMPEG can also be coerced to accept user supplied library paths by specifying:
-DHAVE_FFMPEG=ON
-DFFMPEG_INCLUDE_DIRS=(path to your ffmpeg include directories)
-DFFMPEG_LIBRARIES=(list of ffmpeg libraries, e.g. -lavcodec)
But if we perform this method, the build system displays "YES" to FFMPEG, but "NO" to the individual modules (didn't debug further.)
Some users will find that they may need to supply the --sysroot linker argument in the linker flags, or specify -DCMAKE_SYSROOT as a build argument
Hope this helps someone :)

Compile GCC and install to DESTDIR

I'm trying to install GCC into /my/custom/path/gcc
but for some reason it installs into the normal installation path.
the commands i'm using:
configure --target=i686-pc-linux-gnu --disable-nls --enable-languages=c,c++ --without-headers
make DESTDIR=/my/custom/path/gcc
make DESTDIR=/my/custom/path/gcc install
What am I doing wrong?
You should run (in a new build tree outside of the source tree)
/your/source/path/to/gcc/configure --target=i686-pc-linux-gnu --prefix=/my/custom/path/gcc ...
and then GCC will become installed in /my/custom/path/gcc/bin/ with include files in /my/custom/path/gcc/include/, libraries in /my/custom/path/gcc/lib/ etc etc
I suggest using /opt/ or $HOME/pub as your prefix and you might also be interested by the --program-suffix=-foo option
(do that in a fresh new build tree outside of the source tree; your previous one is rotten)
After successive compilation with make, you can run in your build tree
make install DESTDIR=/tmp/mygccinst/
and finally, you can copy the definitive files with something like
cp -va /tmp/mygccinst/ /
You may need to run this copy as root...
PS the installation prefix is built-in the gcc driver binary, which actually runs cc1 or cc1plus etc...

Resources