[Libav-user] 答复: 答复: 答复: 答复: 答复: 答复: Are there any ways to use a lib (built from C++ OpenCV) in Ffmpeg filter?

R n flynewdream at hotmail.com
Mon Sep 5 07:04:39 EEST 2016


Thanks, Charles.


I followed your suggestion by using "--extra-libs=-L/<path to>/mylibrary/ -lmylibrarytest -lstdc++" when compiling FFmpeg, the previous errors disappeared [😊] Thanks a lot.


If I only added the above argument and the dependency of FFmpeg on my library, the compiling was successful. But if I put "#include "mylibrary_header.h" " to the FFmpeg filter file, libavfilter/vf_myfilter.c, I got the following error. (Basically, I want to write a FFmpeg filter in C which calls my library through the C API file in my library. The core code of my library is in C++ and uses C++ OpenCV, as you described). It is said we can enable the libopencv in FFmpeg, but my case is different. I do not enable the libopencv directly. In my case, the opencv is indirectly used by FFmpeg by calling my library. Should I still play with any opencv setting/flag stuff when compiling FFmepg?


libavfilter/libavfilter.so: undefined reference to `cv::fastFree(void*)'

libavfilter/libavfilter.so: undefined reference to `cv::Mat::deallocate()'

collect2: error: ld returned 1 exit status

make: *** [ffprobe_g] Error 1

make: *** Waiting for unfinished jobs....

libavfilter/libavfilter.so: undefined reference to `cv::fastFree(void*)'

libavfilter/libavfilter.so: undefined reference to `cv::Mat::deallocate()'

collect2: error: ld returned 1 exit status

make: *** [ffmpeg_g] Error 1


+status fail (honored)



Thanks a lot.


Rich


________________________________
发件人: Libav-user <libav-user-bounces at ffmpeg.org> 代表 Charles <linux2 at orion15.org>
发送时间: 2016年9月5日 0:12
收件人: This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter.
主题: Re: [Libav-user] 答复: 答复: 答复: 答复: 答复: Are there any ways to use a lib (built from C++ OpenCV) in Ffmpeg filter?

On 09/04/2016 01:45 AM, R n wrote:
> Thanks, Charles.
>
>
> I just want to build it anyway to make it work 😊
>

Been there, just once... ;-)

After writing this I kinda think this is all you need to do, MAYBE, re-configure ffmpeg and change the order

--extra-libs=-L/<path to>/mylibrary/ -lmylibrarytest -lstdc++

See explanation and more info below.

>
> .../binutils/2.25/centos6-native/da39a3e/bin/ld: .../mylibrary/0.1/gcc-4.9-glibc-2.20/80414d5/lib/libmylibrary.a(mylibrary_file.o):
> relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
>
> .../mylibrary/0.1/gcc-4.9-glibc-2.20/80414d5/lib/libmylibrary.a: error adding symbols: Bad value
>
> collect2: error: ld returned 1 exit status
>
> make: *** [libavfilter/libavfilter.so.6] Error 1

At this point I realized what you are doing...had to go reread your first message.

Your build
"The wrapper consists of a C header file and some C functions which call the C++ functions (in the C++ files)"

I guess you mean something like this mylibrary_file.cpp

MylibraryClass myobj;
extern "C" void mylib_magic_c_foo()
{
    myobj.DoTheMagicFoo();
}

Build your lib with fPIC on each object (source file)->(.o)

g++ -fPIC -O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector [blah blah] ... -o mylibrary_file.o -c mylibrary_file.cpp

Then build your library as a shared lib

LDFLAGS += -fPIC -shared

g++ -fPIC -shared -O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector [blah blah]... mylibrary_file.o -o libmylibrary.so

When ffmpeg builds it need to do the -L.../<path to>/mylibrary/ -lmylibrary -lstdc++

The -L path then your mylibrary all before -lstdc++ (linker "express need then satisfy need")

--extra-libs=-L/<path to>/mylibrary/ -lmylibrarytest -lstdc++'

No idea if it will work, just a theory...sorry not an expert

>
> The full building commands are too big and I just copied something (below) I feel important. Please let me know if I missed anything.
> 2. This is the compile command for building FFmpeg (which is calling my library):
>
> CFLAGS='-O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -fno-omit-frame-pointer
> -momit-leaf-frame-pointer -m64 -mtune=generic -nostdinc -grecord-gcc-switches ... -fPIC'
[...]
> Here, I did not see anything like "Wextra -DDEBUG..."

FYI : They don't have anything to do with your problem
-W is options passed to compiler -Wl is passed to linker and -D is defines passed to C Pre Processor
-Wextra is added to -Wall for compile warnings, I used it for -Wmissing-field-initializers and -Wunused-parameter
-DDEBUG is just enabling my code where I have #if defined(DEBUG)


> 3. This is the compile command for building my library:
> CFLAGS='-O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -fno-omit-frame-pointer
> -momit-leaf-frame-pointer -m64 -mtune=generic -nostdinc -grecord-gcc-switches ...
[...]
>>                    '--extra-libs=-L /lib64 -lstdc++ -lmylibrarytest',
>>
>> .../binutils/2.25/centos6-native/da39a3e/bin/ld: .../mylibrary/0.1/gcc-4.9-glibc-2.20-fb/8fd4fe1/lib/libmylibrary.a(my_file.cpp.o):
>> relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
>
> -fPIC is for shared objects, you have to compile all the object code with -fPIC to build a shared library.
> libmylibrary.a is a static lib so you probably should not be using -fPIC
> The -lstdc++ indicates you are at least linking against it.
> Are you doing a cross compile? Centos 6 should be gcc 4.4.7ish and I thought 4.9 was Centos 7
>
>> .../mylibrary/0.1/gcc-4.9-glibc-2.20/8fd4fe1/lib/libmylibrary.a: error adding symbols: Bad value

Hope this helps...

Thanks
cco
_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user
Libav-user Info Page - FFmpeg<http://ffmpeg.org/mailman/listinfo/libav-user>
ffmpeg.org
This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter. To see the collection of prior postings to the list, visit the Libav-user ...



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20160905/13ce2fde/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OutlookEmoji-😊.png
Type: image/png
Size: 488 bytes
Desc: OutlookEmoji-😊.png
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20160905/13ce2fde/attachment.png>


More information about the Libav-user mailing list