Thanks for the suggestions. Here are the results:

(1) Salsaman:

I tried to add "-fPIC -DPIC" to --extra-cflags , and add "-DPIC" to 
--extra-cxxflags, but still got the same error.

(2) Perette:

I have the same code as yours, and the only difference is that I put the C++ 
code in a class, like the related content in 
http://stackoverflow.com/questions/199418/using-c-library-in-c-code.


Should it still be the compilation setting issue, when compiling my library or 
compiling FFmpeg?


Thanks.


Rich



________________________________
发件人: Libav-user <[email protected]> 代表 salsaman <[email protected]>
发送时间: 2016年9月3日 14:02
收件人: 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 Sat, Sep 3, 2016 at 10:56 AM, R n 
<[email protected]<mailto:[email protected]>> wrote:

By the way, I have also been playing with the compiling flags for FFmpeg, but 
got different errors. For example:


I used '--extra-libs=-lmylibrary -L/usr/lib64 -lstdc++', and got:


.../binutils/2.25/centos6-native/da39a3e/bin/ld: 
.../mylibrary/0.1/gcc-4.9-glibc-2.20/80414d5/lib/libmylibrary.a(mylibrary_file.cpp.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-fb/80414d5/lib/libmylibrary.a: error 
adding symbols: Bad value



I know this error. Try -fPIC -DPIC in the compiler and linker flags.





Thanks.


Rich

________________________________
发件人: Libav-user 
<[email protected]<mailto:[email protected]>> 代表 R n 
<[email protected]<mailto:[email protected]>>
发送时间: 2016年9月3日 3:54
收件人: This list is about using libavcodec, libavformat, libavutil, libavdevice 
and libavfilter.
主题: [Libav-user] 答复: Are there any ways to use a lib (built from C++ OpenCV) in 
Ffmpeg filter?


Thanks Perette.


I did exactly what you suggested for the C and C++ files. (I have two header 
files, one for C and another is for C++, and the C++ header file includes the C 
header file. I have one cpp file in which I put the C and C++ source code. I 
can also split them into two cpp files for clarity). I guess perhaps the 
problem is in the how I compile the library and how I compile FFmpeg when I 
call the library from FFmpeg.


Any suggestions?


Thanks.


Rich




________________________________
发件人: Libav-user 
<[email protected]<mailto:[email protected]>> 代表 
Perette Barella <[email protected]<mailto:[email protected]>>
发送时间: 2016年9月3日 3:38
收件人: 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 2016年09月02日, at 22:32, R n 
<[email protected]<mailto:[email protected]>> wrote:
I am writing a C++ library which is based on OpenCV. I want to use it in a 
Ffmpeg filter (written in C), so I write a wrapper of the library using C. The 
wrapper consists of a C header file and some C functions which call the C++ 
functions (in the C++ files). I expect the FFmpeg filter to only include the C 
header and call the C functions.
…
However, I get the following error when compiling FFmpeg:
.../binutils/2.25/centos6-native/da39a3e/bin/ld: 
.../mylibrary/0.1/gcc-4.9-glibc-2.20/80414d5/lib/libmylibrary.a(mylibrary_file.cpp.o):
 undefined reference to symbol '_ZdlPv@@GLIBCXX_3.4'
.../libgcc/4.9.x/gcc-4.9-glibc-2.20/024dbc3/lib/libstdc++.so: error adding 
symbols: DSO missing from command line

Your approach is correct, but C++ “mangles” function names to make them unique 
when considering parameters and such.  You need to specify C linkage, so in 
your .h file, wrap it in extern “C”:

#ifdef __cplusplus
#warning is c++
extern "C" {
#endif
char foo (int);

#ifdef __cplusplus
}
#endif

You need to #include the .h file in the corresponding .cpp file, so the C++ 
compiler knows not to mangle those particular function names when they’re 
compiled.

Perette



_______________________________________________
Libav-user mailing list
[email protected]<mailto:[email protected]>
http://ffmpeg.org/mailman/listinfo/libav-user


_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to