link libavformat error

468 views
Skip to first unread message

khahn

unread,
Nov 10, 2014, 1:09:36 AM11/10/14
to native-cli...@googlegroups.com
hi all.

i try to create player use ffmpeg on NaCl.
i built ffmpeg in naclports.
i write to sample c file and Makefile in NACL_SDK_ROOT(pepper_37)/examples/tutorial/using_ppapi_simple/.

in Sample.c, written to below.
...
#include <libavformat/avformat.h>
...
int example_main(int argc, char* argv[]) {
...
av_register_all
();
...

and Makefile, written to below.
EXTRA_INC_PATHS := $(NACL_SDK_ROOT)/toolchain/linux_x86_newlib/i686-nacl/usr/include
...
LDFLAGS = -L$(NACL_SDK_ROOT)/toolchain/linux_x86_newlib/i686-nacl/usr/lib -lavformat
SOURCES=Sample.c

and i have following errors...TT
python /home/khahn/nacl_sdk/pepper_37/tools/oshelpers.py mkdir -p newlib/Release/
/home/khahn/nacl_sdk/pepper_37/toolchain/linux_x86_newlib/bin/i686-nacl-g++ -o newlib/Release/using_ppapi_simple_unstripped_x86_32.nexe newlib/Release/hello_world_x86_32.o -O2 -Wl,-as-needed -pthread -Wl,-Map,./newlib/Release/using_ppapi_simple_x86_32.map -L/home/khahn/nacl_sdk/pepper_37/lib/newlib_x86_32/Release -lppapi_simple -lnacl_io -lppapi_cpp -lppapi -L/home/khahn/nacl_sdk/pepper_37/toolchain/linux_x86_newlib/i686-nacl/usr/lib -lavformat
/home/khahn/nacl_sdk/pepper_37/toolchain/linux_x86_newlib/i686-nacl/usr/lib/libavformat.a(g723_1.o): In function `g723_1_read_packet':
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/g723_1.c:62: undefined reference to `av_new_packet'
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/g723_1.c:72: undefined reference to `av_free_packet'
/home/khahn/nacl_sdk/pepper_37/toolchain/linux_x86_newlib/i686-nacl/usr/lib/libavformat.a(iss.o): In function `iss_read_header':
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/iss.c:92: undefined reference to `av_log'
/home/khahn/nacl_sdk/pepper_37/toolchain/linux_x86_newlib/i686-nacl/usr/lib/libavformat.a(mpegenc.o): In function `flush_packet':
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/mpegenc.c:717: undefined reference to `av_fifo_size'
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/mpegenc.c:754: undefined reference to `av_fifo_size'
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/mpegenc.c:850: undefined reference to `av_fifo_size'
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/mpegenc.c:851: undefined reference to `av_fifo_generic_read'
/home/khahn/nacl_sdk/pepper_37/toolchain/linux_x86_newlib/i686-nacl/usr/lib/libavformat.a(mpegenc.o): In function `output_packet':
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/mpegenc.c:940: undefined reference to `av_rescale'
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/mpegenc.c:946: undefined reference to `av_fifo_size'
/home/khahn/nacl_sdk/pepper_37/toolchain/linux_x86_newlib/i686-nacl/usr/lib/libavformat.a(mpegenc.o): In function `remove_decoded_packets':
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/mpegenc.c:923: undefined reference to `av_freep'
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/mpegenc.c:915: undefined reference to `av_log'
/home/khahn/nacl_sdk/pepper_37/toolchain/linux_x86_newlib/i686-nacl/usr/lib/libavformat.a(mpegenc.o): In function `output_packet':
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/mpegenc.c:992: undefined reference to `av_log'
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/mpegenc.c:1006: undefined reference to `av_fifo_size'
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/mpegenc.c:1025: undefined reference to `av_fifo_size'
/home/khahn/nacl_sdk/pepper_37/toolchain/linux_x86_newlib/i686-nacl/usr/lib/libavformat.a(mpegenc.o): In function `remove_decoded_packets':
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/mpegenc.c:923: undefined reference to `av_freep'
/home/khahn/naclports/src/out/build/ffmpeg/ffmpeg-2.1.3/libavformat/mpegenc.c:915: undefined reference to `av_log'
...

how can i solve these errors?
that is ffmpeg port build problem?
or link problem?

thanks.

Sam Clegg

unread,
Nov 10, 2014, 1:11:04 PM11/10/14
to native-cli...@googlegroups.com
The newlib toolchain that you are using only supports statically
linked libraries. This means that you need to explicitly link against
all the libraries that you transitively depend on. In this case it
looks like libavformat depends on the libavcodec so you need to at
least add -lavcodec to your command line (and possibly other libraries
too).

Another way to solve this issue is to use pkg-config. Normally this
would look like 'pkg-config --libs libavformat', but since we are
cross compiling you first need to set:
PKG_CONFIG_LIBDIR=$NACL_SDK_ROOT/toolchain/linux_x86_newlib/x86_64-nacl/usr/lib/pkgconfig/.
When I run this command it results in:
-pthread -lavformat -lavcodec -lvorbisenc -lvorbis -ltheoraenc
-ltheoradec -logg -lmp3lame -lbz2 -lz -lavutil -lm.

cheers,
sam
> --
> You received this message because you are subscribed to the Google Groups
> "Native-Client-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to native-client-di...@googlegroups.com.
> To post to this group, send email to native-cli...@googlegroups.com.
> Visit this group at http://groups.google.com/group/native-client-discuss.
> For more options, visit https://groups.google.com/d/optout.

khahn

unread,
Nov 12, 2014, 9:46:26 PM11/12/14
to native-cli...@googlegroups.com
thanks, your reply.

I solved this issue by your comment.

thank you very much~~~^^

2014년 11월 11일 화요일 오전 3시 11분 4초 UTC+9, Sam Clegg 님의 말:

holla....@gmail.com

unread,
Nov 1, 2015, 4:37:39 PM11/1/15
to Native-Client-Discuss
Hello Sam,

 I have been reading and following most of your posts related to NaCl and would like to thank you for that :) I really wished you had a blog/tutorial site.

I followed your advice on pkg-config and added the links but I still have problems. I am trying to do the same thing as khahn.

This is my output:
$ make
/Users/aholla/codeBase/teflon/sdk/nacl_sdk/pepper_46/toolchain/mac_pnacl/bin/pnacl-clang++ -o hello_tutorial.bc hello_tutorial.cc -L/Users/aholla/codeBase/teflon/sdk/nacl_sdk/pepper_46/getting_started/ffmpeg_trial/payload/lib -lavdevice -lvorbisenc -lvorbis -logg -ltheoraenc -ltheoradec -logg -lmp3lame -lm -pthread -lavfilter -lvorbisenc -lvorbis -logg -ltheoraenc -ltheoradec -logg -lmp3lame -lm -pthread -lswscale -lm -lpostproc -lavformat -lvorbisenc -lvorbis -logg -ltheoraenc -ltheoradec -logg -lmp3lame -lm -pthread -lavcodec -lvorbisenc -lvorbis -logg -ltheoraenc -ltheoradec -logg -lmp3lame -lm -pthread -lswresample -lm -lavutil -lm  payload/lib/*.a tmp/*.o -O2 -I/Users/aholla/codeBase/teflon/sdk/nacl_sdk/pepper_46/include -D__STDC_CONSTANT_MACROS -L/Users/aholla/codeBase/teflon/sdk/nacl_sdk/pepper_46/lib/pnacl/Release -lppapi_cpp -lppapi
/Users/aholla/codeBase/teflon/sdk/nacl_sdk/pepper_46/getting_started/ffmpeg_trial/hello_tutorial.bc---hello_tutorial.cc---.po: error: undefined reference to 'av_register_all()'
make: *** [hello_tutorial.bc] Error 1

here is a part of my makefile:

EXT_LIBS := payload/lib/*.a tmp/*.o
PKGFLAGS := $(shell pkg-config --libs libavcodec libavformat libavutil libswscale libswresample libavdevice libavfilter)
#export PKG_CONFIG_LIBDIR=payload/lib/pkgconfig/.
export PKG_CONFIG_LIBDIR=/Users/aholla/codeBase/teflon/sdk/nacl_sdk/pepper_46/toolchain/mac_pnacl/x86_64-nacl/usr/lib/pkgconfig
#
# Disable DOS PATH warning when using Cygwin based tools Windows
#
CYGWIN ?= nodosfilewarning
export CYGWIN

hello_tutorial.bc: hello_tutorial.cc
$(PNACL_CXX) -o $@ $< $(PKGFLAGS) $(EXT_LIBS) -O2 $(CXXFLAGS) $(LDFLAGS) 

Thank you very much in advance.

Sam Clegg

unread,
Nov 3, 2015, 4:53:49 PM11/3/15
to native-cli...@googlegroups.com
On Sun, Nov 1, 2015 at 1:37 PM, <holla....@gmail.com> wrote:
> Hello Sam,
>
> I have been reading and following most of your posts related to NaCl and
> would like to thank you for that :) I really wished you had a blog/tutorial
> site.
>
> I followed your advice on pkg-config and added the links but I still have
> problems. I am trying to do the same thing as khahn.
>
> This is my output:
> $ make
> /Users/aholla/codeBase/teflon/sdk/nacl_sdk/pepper_46/toolchain/mac_pnacl/bin/pnacl-clang++
> -o hello_tutorial.bc hello_tutorial.cc
> -L/Users/aholla/codeBase/teflon/sdk/nacl_sdk/pepper_46/getting_started/ffmpeg_trial/payload/lib
> -lavdevice -lvorbisenc -lvorbis -logg -ltheoraenc -ltheoradec -logg
> -lmp3lame -lm -pthread -lavfilter -lvorbisenc -lvorbis -logg -ltheoraenc
> -ltheoradec -logg -lmp3lame -lm -pthread -lswscale -lm -lpostproc -lavformat
> -lvorbisenc -lvorbis -logg -ltheoraenc -ltheoradec -logg -lmp3lame -lm
> -pthread -lavcodec -lvorbisenc -lvorbis -logg -ltheoraenc -ltheoradec -logg
> -lmp3lame -lm -pthread -lswresample -lm -lavutil -lm payload/lib/*.a
> tmp/*.o -O2 -I/Users/aholla/codeBase/teflon/sdk/nacl_sdk/pepper_46/include
> -D__STDC_CONSTANT_MACROS
> -L/Users/aholla/codeBase/teflon/sdk/nacl_sdk/pepper_46/lib/pnacl/Release
> -lppapi_cpp -lppapi
> /Users/aholla/codeBase/teflon/sdk/nacl_sdk/pepper_46/getting_started/ffmpeg_trial/hello_tutorial.bc---hello_tutorial.cc---.po:
> error: undefined reference to 'av_register_all()'

This looks like an issue with C++ vs C name mangling. I imagine that
the ffmpeg header is declaring av_register_all as a C function but is
not wrapping the declarations in extern "C". You might want to try
adding exten "C" { } around the #include of the ffmpeg headers.
>> > email to native-client-di...@googlegroups.com.
>> > To post to this group, send email to native-cli...@googlegroups.com.
>> > Visit this group at
>> > http://groups.google.com/group/native-client-discuss.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Native-Client-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to native-client-di...@googlegroups.com.

Akshay Holla

unread,
Nov 3, 2015, 8:38:15 PM11/3/15
to native-cli...@googlegroups.com

Thank you very much Sam, that fixed the issue!

You received this message because you are subscribed to a topic in the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/native-client-discuss/a_OJRtpHy7g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to native-client-di...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages