Vim can't find C++ libavformat/libavutil library (No such file or directory) - c++

Loading up the omxplayer.cpp file in vim and it gives me the following error:
omxplayer.cpp|34 col 34| fatal error: libavformat/avformat.h: No such file or directory
This is where the problem is occurring
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
But I know the files exist:
$ ls -l /usr/lib/libavu*
lrwxrwxrwx 1 root root 28 2013-11-08 13:46 /usr/lib/libavutil.so -> /usr/lib/libavutil.so.51.7.0
lrwxrwxrwx 1 root root 19 2012-06-13 12:38 /usr/lib/libavutil.so.51 -> libavutil.so.51.7.0
-rw-r--r-- 1 root root 117212 2012-06-13 12:38 /usr/lib/libavutil.so.51.7.0
$ ls -l /usr/lib/libavf*
lrwxrwxrwx 1 root root 30 2013-11-08 13:29 /usr/lib/libavformat.so -> /usr/lib/libavformat.so.53.3.0
lrwxrwxrwx 1 root root 21 2012-06-13 12:38 /usr/lib/libavformat.so.53 -> libavformat.so.53.3.0
-rw-r--r-- 1 root root 1053000 2012-06-13 12:38 /usr/lib/libavformat.so.53.3.0
And ldconfig can also find them:
$ ldconfig -p | grep libavformat && ldconfig -p | grep libavutil
libavformat.so.53 (libc6, hwcap: 0x0008000000008000) => /usr/lib/i686/cmov/libavformat.so.53
libavformat.so.53 (libc6) => /usr/lib/libavformat.so.53
libavutil.so.51 (libc6, hwcap: 0x0008000000008000) => /usr/lib/i686/cmov/libavutil.so.51
libavutil.so.51 (libc6) => /usr/lib/libavutil.so.51
I have read somewhere that ldconfig is for run time whereas ld is for build time, however, in this case I know the libraries are there in /usr/lib, therefore, what could be causing this problem?

omxplayer.cpp|34 col 34| fatal error: libavformat/avformat.h: No such file or directory
Error message says all: It is not in library, But it is header file which is not found.
Normal location is /usr/include/libavformat.
first check by command whether header location is included by g++ -v omxplayer.cpp, This command will show what all directories are included for header files.
if it dows not show directory containing specified header then you need to specify it's location in g++ -Ipath/to/headers omxplayer.cpp. command.

Related

Undefined reference to `libbgp::BgpFsm::tick()'

I started working with c++ a few weeks ago, and I started a new project to start learning more. I'm encountering an issue with an external dependency. I'm trying to use a library called:
libbgp, and I installed it base on their documentation.
Here is my code:
https://gist.github.com/amb1s1/9b2c72294da0ec9416810c8686d3adce
Error:
/usr/bin/ld: /tmp/ccsdO32O.o: in function `ticker(libbgp::BgpFsm&)':
ambgp.cpp:(.text+0xa7): undefined reference to `libbgp::BgpFsm::tick()'
collect2: error: ld returned 1 exit status
I'm not sure if there is anything else that I have to do after installing the lib for the library to be accessible in my source code.
Update
I ran it with the -lbgp flag and when running it, i get the following error:
g++ -lbgp ambgp.cpp -o ambgp
Error:
./ambgp: error while loading shared libraries: libbgp.so.0: cannot open shared object file: No such file or directory
My Lib:
ls -l /usr/local/lib/
-rw-r--r-- 1 root root 10875880 Jan 18 16:56 libbgp.a
-rwxr-xr-x 1 root root 924 Jan 18 16:56 libbgp.la
lrwxrwxrwx 1 root root 15 Jan 18 16:56 libbgp.so -> libbgp.so.0.0.0
lrwxrwxrwx 1 root root 15 Jan 18 16:56 libbgp.so.0 -> libbgp.so.0.0.0
-rwxr-xr-x 1 root root 4291128 Jan 18 16:56 libbgp.so.0.0.0
drwxrwsr-x 3 root staff 4096 Dec 16 19:27 python3.7
echo $LD_LIBRARY_PATH
:/usr/local/lib
Before running the executable, you have to tell it where to find the libgdp.so file, if it is not stored in a standard place such as /usr/lib or /lib. Following should help you:
$ export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib"
$ ./ambgp
If you do not want to export the LD_LIBRARY_PATH each time you start the shell manually, add the line to your /home/<user>/.bashrc file.
Additionally, i think the -lbgp flag should go after the source file in the compiler command (g++ ambgp.cpp -lbgp -o ambgp)
TL;DR :
ld states it cannot find libbgp.so.0, and you wrote in the comments that you found libbgp.so without a trailing .0. So, creating a symlink to the library could help too:
$ sudo ln -s /usr/local/lib/libbgp.so /usr/local/lib/libbgp.so.0
For linking, you need a library file without a trailing .0, but for loading, the library name must have a trailing .0.
The last thing to try is to directly specify the library location to the linker with -Wl,-rpath=/usr/local/lib (as you worked out already !)

Using Freetype library with CMake [duplicate]

I'm new to cmake, and I'm only using it to install opencv on my ubuntu linux.
Here's the command I ran: cmake -DCMAKE_BUILD_TYPE=Release DCMAKE_INSTALL_PREFIX=/home/jinha/OCV/source
Then it returns the error:
FATAL: In-source builds are not allowed. You should create separate directory for build files.
My current directory, ~/OCV/build/opencv, does contain the CMakefiles.txt file, so that's not the problem. I tried to change the directory in my command, but they all raise the same error. I saw the other answers on this issue, so I erased CMakeFiles directory and CMakeCache.txt file every time before I ran the command, but none of them worked.
Thanks.
It wants you to create a separate build directory (anywhere), and run cmake there. For example:
mkdir my_build_dir
cd my_build_dir
rm ../CMakeCache.txt
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/jinha/OCV/source
Note the .. in this example telling cmake where to look for the source.
In case you didn't remove CMakeCache.txt before building again, it will still show this error.
So, please remember to delete CMakeCache.txt first before running cmake.
After you have success downloaded and unzipped OpenCV sources from sources you need create simple command-file install.sh. For example, your working dir will be /home/user/myopencv
So /home/user/myopencv/install.sh will be contain next code:
#!/bin/bash
rm CMakeCache.txt
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local
make
make install
make clean
Next
chmod 777 install.sh
./install.sh
And after the all you will get those executable files:
root#cartman:/usr/local/bin# ls -las | grep opencv
32 -rwxr-xr-x 1 root root 29888 апр 20 18:10 opencv_annotation
244 -rwxr-xr-x 1 root root 247608 апр 20 18:10 opencv_createsamples
244 -rwxr-xr-x 1 root root 247504 апр 20 18:10 opencv_haartraining
20 -rwxr-xr-x 1 root root 18600 апр 20 18:10 opencv_performance
288 -rwxr-xr-x 1 root root 294592 апр 20 18:10 opencv_traincascade
16 -rwxr-xr-x 1 root root 14288 апр 20 18:10 opencv_version
60 -rwxr-xr-x 1 root root 61040 апр 20 18:10 opencv_visualisation
Enjoy!

C++ compiler cannot find Boost libraries even after installing them

While compiling few test applications, I get the following error:
g++: error: −lboost_system: No such file or directory
g++: error: −lboost_filesystem: No such file or directory
while running the following command:
g++ -I/usr/include/boost/ -L/usr/lib/x86_64-linux-gnu/ aescuda.cpp -o test.o −lboost_system −lboost_filesystem
The libraries are installed and present in location as shown below:
<prompt>$ ll /usr/lib/x86_64-linux-gnu/libboost_system.*
-rw-r--r-- 1 root root 49178 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_system.a
lrwxrwxrwx 1 root root 25 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_system.so -> libboost_system.so.1.54.0
-rw-r--r-- 1 root root 14536 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_system.so.1.54.0
<prompt>$ ll /usr/lib/x86_64-linux-gnu/libboost_filesystem.*
-rw-r--r-- 1 root root 217628 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_filesystem.a
lrwxrwxrwx 1 root root 29 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_filesystem.so -> libboost_filesystem.so.1.54.0
-rw-r--r-- 1 root root 88936 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.54.0
Can anyone suggest where am I going wrong :(
You have a wrong character in front of the l:
−lboost_system
It should be an ASCII hyphen:
-lboost_system
This causes the compiler driver to treat the whole string as an input file name (which obviously does not exist, hence the No such file or directory error), and not as an option to be passed to the linker.
(Perhaps consider switching the terminal font.)

How to build pHash on MacOSX Lion (using latest ffmpeg-devel)

Building pHash 0.9.4 on OSX can turn out to be tricky.
For those of you who've run into issues, my somewhat lengthy answer below might help.
Make sure you've got macports fully updated and working. This means a recent Xcode, and inside Xcode preferences->downloads->components install Command-Line Tools !
$ sudo port selfupdate
# if you've had previous build issues:
$ sudo port clean --all
# get pHash
wget http://www.phash.org/releases/pHash-0.9.4.tar.gz
tar zxvf pHash-0.9.4.tar.gz
cd pHash-0.9.4
# remove old versions of ffmpeg, e.g.
$ sudo port installed ffmpeg
$ sudo port uninstall --follow-dependents ffmpeg #0.7.11_1+mmx
$ sudo port uninstall --follow-dependents ffmpeg #0.7.8_0
# install latest ffmpeg-devel version (#20120329 for me) - enable the non-free stuff as well
$ sudo port install ffmpeg-devel +nonfree
# double check that you have some new header files
$ ll -tr /opt/local/include/
total 8816
-rw-r--r-- 1 root admin 191 Dec 23 2004 lua.hpp
-rw-r--r-- 1 root admin 1026 Dec 27 2007 lualib.h
-rw-r--r-- 1 root admin 5777 Dec 27 2007 lauxlib.h
...
drwxr-xr-x 6 root admin 204 Jul 12 17:27 libmodplug
drwxr-xr-x 3 root admin 102 Jul 12 17:32 libswscale
drwxr-xr-x 3 root admin 102 Jul 12 17:32 libswresample
drwxr-xr-x 3 root admin 102 Jul 12 17:32 libpostproc
drwxr-xr-x 41 root admin 1394 Jul 12 17:32 libavutil
drwxr-xr-x 5 root admin 170 Jul 12 17:32 libavformat
drwxr-xr-x 8 root admin 272 Jul 12 17:32 libavfilter
drwxr-xr-x 3 root admin 102 Jul 12 17:32 libavdevice
drwxr-xr-x 10 root admin 340 Jul 12 17:32 libavcodec
# get CImg and copy CImg.h into your pHash dir
$ cd ..
$ wget http://downloads.sourceforge.net/project/cimg/CImg-1.5.0.zip
$ unzip CImg-1.5.0.zip
$ cp CImg-1.5.0/CImg.h pHash-0.9.4/
$ cd pHash-0.9.4
# copy the JNI headers from your Java SDK into your pHash dir - for 1.7.0 they're here:
$ cp /Library/Java//JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h ./
$ cp /Library/Java//JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/darwin/jni_md.h ./
# install libsndfile, libsamplerate and mpg123 if not installed already
$ sudo port install libsndfile
$ sudo port install libsamplerate
$ sudo port install mpg123
# now run configure, with Java enabled as you likely want those cool bindings, and expect the missing libavcodec error:
$ ./configure --enable-java
OR this which would make more sense:
$ ./configure --enable-java CPPFLAGS="-I/opt/local/include" LDFLAGS="-L/opt/local/lib"
but configure completely ignores the new include/lib paths stated :( Seemingly as they're hardcoded inside configure.
...
checking CImg.h usability... no
checking CImg.h presence... no
checking for CImg.h... no
checking whether CImg.h is in the current or src directory.... yes
*** Configuring video Hash ***
checking whether FFmpeg is present... checking for avcodec_alloc_frame in -lavcodec... no
configure: error:
*** libavcodec not found.
So then since configure expects all the libs and includes to be in /usr/local/ (not /opt/local) and I cant't get it to look elsewhere, the only thing left to do is brute-force it ! :D
# edit ./configure as follows
$ nano configure
CTRL-W -> search for ' -L/' (note the space)
# edit the lines as follows
LDFLAGS="$LDFLAGS -L/usr/local/lib -L/opt/local/lib"
CPPFLAGS="$CPPFLAGS -I/usr/local/include -I/opt/local/include"
# Or do the newbie version (I actually did this the first time!)
$ sudo mv /usr/local/lib /usr/local/lib-foo
$ sudo mv /usr/local/include/ /usr/local/include-foo
$ sudo ln -s /opt/local/lib /usr/local/lib
$ sudo ln -s /opt/local/include /usr/local/include
$ ll /usr/local/
total 16
drwxr-xr-x 32 root wheel 1088 Jun 29 18:04 bin
drwxr-xr-x 3 root wheel 102 Mar 6 14:40 etc
lrwxr-xr-x 1 root wheel 18 Jul 12 19:27 include -> /opt/local/include
drwxr-xr-x 11 root wheel 374 Jul 12 19:22 include-foo
lrwxr-xr-x 1 root wheel 14 Jul 12 19:27 lib -> /opt/local/lib
drwxr-xr-x 25 root wheel 850 Jul 12 19:23 lib-foo
drwxr-xr-x 8 root wheel 272 Oct 11 2010 sbin
drwxr-xr-x 4 root wheel 136 Jun 12 11:52 share
# at this point ./configure should work ok
Time to run make - you'll get a bunch of errors:
$ make
# on to the code bits:
# we need to adjust src/cimgffmpeg.cpp to support the latest version of ffmpeg
# a few things have moved from being deprecated to having been completely changed:
$ make 2>&1 | grep error
cimgffmpeg.cpp:57: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:70: error: 'CODEC_TYPE_VIDEO' was not declared in this scope
cimgffmpeg.cpp:134: error: 'avcodec_decode_video' was not declared in this scope
cimgffmpeg.cpp:202: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:216: error: 'CODEC_TYPE_VIDEO' was not declared in this scope
cimgffmpeg.cpp:283: error: 'avcodec_decode_video' was not declared in this scope
cimgffmpeg.cpp:339: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:357: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:368: error: 'CODEC_TYPE_VIDEO' was not declared in this scope
cimgffmpeg.cpp:399: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:410: error: 'CODEC_TYPE_VIDEO' was not declared in this scope
# change as follows; left: original downloaded source, right: modified source
$ diff ~/Downloads/pHash-0.9.4-fresh/src/cimgffmpeg.cpp ~/dev/pHash-0.9.4/src/cimgffmpeg.cpp
57c57
< if(av_open_input_file(&st_info->pFormatCtx, st_info->filename, NULL, 0, NULL)!=0)
---
> if(avformat_open_input(&st_info->pFormatCtx, st_info->filename, NULL, NULL)!=0)
70c70
< if(st_info->pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
---
> if(st_info->pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
134c134
< avcodec_decode_video(st_info->pCodecCtx, pFrame, &frameFinished,packet.data, packet.size);
---
> avcodec_decode_video2(st_info->pCodecCtx, pFrame, &frameFinished, &packet);
202c202
< if(av_open_input_file(&(st_info->pFormatCtx),st_info->filename,NULL,0,NULL)!=0){
---
> if(avformat_open_input(&(st_info->pFormatCtx),st_info->filename,NULL,NULL)!=0){
216c216
< if(st_info->pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
---
> if(st_info->pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
282,283c282
< avcodec_decode_video(st_info->pCodecCtx, pFrame, &frameFinished,
< packet.data,packet.size);
---
> avcodec_decode_video2(st_info->pCodecCtx, pFrame, &frameFinished, &packet);
339c338
< if (av_open_input_file(&pFormatCtx, file, NULL, 0, NULL))
---
> if (avformat_open_input(&pFormatCtx, file, NULL, NULL))
357c356
< if (av_open_input_file(&pFormatCtx, file, NULL, 0, NULL))
---
> if (avformat_open_input(&pFormatCtx, file, NULL, NULL))
368c367
< if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
---
> if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
399c398
< if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL))
---
> if (avformat_open_input(&pFormatCtx, filename, NULL, NULL))
410c409
< if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
---
> if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
That was tons of fun I'm sure, no worries we're almost there.
# make should now complete with only useless warnings
$ make
$ sudo make -n install
# if all went well you've not got pHash with Java bindings
# let's build the Java files and test it
$ cd ll bindings/java/org/phash/
$ javac *.java
# go back to the Java bindins root and run
$ cd ../..
# oh yeah.. if you actually DID rename the include/lib dirs previously then:
$ sudo rm /usr/local/lib
$ sudo rm /usr/local/include
$ sudo mv /usr/local/include-foo/ /usr/local/include
$ sudo mv /usr/local/lib-foo/ /usr/local/lib
# drum roll..
$ java -Djava.library.path=/usr/local/lib org/phash/pHash -mh ~/Downloads/s01.jpg ~/Downloads/s02.jpg
File 1: /Users/xxx/Downloads/s01.jpg
File 2: /Users/xxx/Downloads/s02.jpg
0.3159722222222222
# now go try out your image recognition app ideas ;)

How do I make Boost multithreading?

I am trying to compile the latest Boost c++ libraries for Centos. I 've used bjam install and it has placed the libraries in /usr/lib and /usr/lib64.
The problem is I need the -mt variants for a specific application to run. I cannot understand in the documentation how to create the multithreading variants. :(
Please give me a hint!
Thanks!
-mt is just distribution specific extension.
either edit your config file or create symbolic link to libboost_thread
andrey#localhost:~$ ls -l /usr/lib/libboost_thread*
-rw-r--r-- 1 root root 174308 2010-01-25 10:36 /usr/lib/libboost_thread.a
lrwxrwxrwx 1 root root 41 2009-11-04 10:10 /usr/lib/libboost_thread-gcc41-mt-1_34_1.so.1.34.1 -> libboost_thread-gcc42-mt-1_34_1.so.1.34.1
-rw-r--r-- 1 root root 49912 2008-11-01 02:55 /usr/lib/libboost_thread-gcc42-mt-1_34_1.so.1.34.1
lrwxrwxrwx 1 root root 17 2010-01-27 18:32 /usr/lib/libboost_thread-mt.a -> libboost_thread.a
lrwxrwxrwx 1 root root 25 2010-01-27 18:32 /usr/lib/libboost_thread-mt.so -> libboost_thread.so.1.40.0
lrwxrwxrwx 1 root root 25 2010-01-27 18:32 /usr/lib/libboost_thread.so -> libboost_thread.so.1.40.0
-rw-r--r-- 1 root root 89392 2010-01-25 10:36 /usr/lib/libboost_thread.so.1.40.0
You can build all variations of the boost binary libraries using the --build-type=complete option. For example:
bjam --build-type=complete stage
This will put all library files into <your boost dir>/stage/lib/