1

I am building opencv-3.1.0 and I want to use ffmpeg, which is installed in custom path /media/sdcard/usr/lib, /media/sdcard/usr/include. Normally, linker gives me an error:

/usr/lib/gcc/i586-poky-linux/4.9.1/../../../../i586-poky-linux/bin/ld: cannot find -lavcodec 

So I gave cmake some additional flags: -DCMAKE_SHARED_LINKER_FLAGS="--library-path /media/sdcard/usr/lib", DCMAKE_INCLUDE_PATH=/media/sdcard/usr/include. Include seems not to work at all, but as for linker flags, cmake gave me the following output:

Linker flags (Release):      --library-path /media/sdcard/usr/lib
Linker flags (Debug):        --library-path /media/sdcard/usr/lib

But when I tried to run make, I got an error: c++: error: unrecognized command line option '--library-path'

My ld knows '--library-path' flag and finds necessary libraries, e.g. if I run

ld -lavcodec --library-path /media/sdcard/usr/lib --verbose

it gives me

attempt to open /media/sdcard/usr/lib/libavcodec.a succeeded

I may be missing some ground understanding of the whole process.

Lera Sinevich
  • 164
  • 3
  • 10
  • Instead of setting linker flags, natural way is to hint CMake where to search `ffmpeg` library. The simplest way is to set `CMAKE_PREFIX_PATH`, as described [here](http://stackoverflow.com/questions/34795816/hinting-findname-cmake-files-with-a-custom-directory/34797156#34797156). – Tsyvarev Jul 29 '16 at 08:04
  • Unfortunately doesn't help: /usr/lib/gcc/i586-poky-linux/4.9.1/../../../../i586-poky-linux/bin/ld: cannot find -lavcodec – Lera Sinevich Jul 29 '16 at 08:57
  • 1
    This error message should be in your question post, because it describes your **original problem**. Are there any messages from `cmake` (not `make`) about not finding `ffmpeg` library? If no, then `opencv` build system expects library to be found in standard location, so adding `--library-path` helps only partially: the project will be built, but after installation it will forget about this hint, and library will be failed to loaded. As for `error: unrecognized command line option '--library-path'`, you may try to use `-L` instead - this is a commonly used synonym. – Tsyvarev Jul 29 '16 at 09:42
  • Possible duplicate of [how to add linker or compile flag in cmake file](http://stackoverflow.com/questions/11783932/how-to-add-linker-or-compile-flag-in-cmake-file) – usr1234567 Jul 29 '16 at 09:50
  • @Tsyvarev, thank you, I made an edit to my question, if that is what you meant. By the way, my files have .a extension, so they are statically linked and no more errors should occur once compilation is finished. Am I right about that? – Lera Sinevich Jul 29 '16 at 11:00
  • Yes, if you link statically, no error should be risen at runtime. Did you tried `-L` flag instead of `--library-path`? If this doesn't help, what compiler do you use? (It should be a value of variable `CMAKE_CXX_COMPILER` or `CMAKE_C_COMPILER`). @usr1234567: The question you refer to asks about adding flag into **own project**, so it is possible to change its CMake code. But current question has another situation: `opencv` is *3d-party project*, so changing CMake code is not accessible. – Tsyvarev Jul 29 '16 at 11:18
  • Well, `-L` seems to give no effect at all,`ld` still throws `no found` error. I believe my compiler is `gcc 4.9.1`, that is shown in my `cmake` output. I solved the problem by simply creating symlinks from `/media/sdcard/usr/lib` to normal `/usr/lib`, but it's disappointing. – Lera Sinevich Jul 29 '16 at 11:38
  • You may try to set `LIBRARY_PATH` *environment* variable, so linker should find the library. – Tsyvarev Jul 29 '16 at 12:13

0 Answers0