I am having an issue trying to build my program, which is using a C++ class to dela with FFmpeg objects:
Undefined symbols for architecture armv7:
"__Z13avcodec_open2P14AVCodecContextP7AVCodecPP12AVDictionary", referenced from:
__Z10openStreamPKcb in RTPReader.o
"__Z21avcodec_decode_audio4P14AVCodecContextP7AVFramePiP8AVPacket", referenced from:
__Z13getStreamDataRPhRi in RTPReader.o
"__Z20avformat_close_inputPP15AVFormatContext", referenced from:
__Z11closeStreamv in RTPReader.o
"__Z21avformat_network_initv", referenced from:
__Z10openStreamPKcb in RTPReader.o
"__Z26avcodec_get_frame_defaultsP7AVFrame", referenced from:
__Z13getStreamDataRPhRi in RTPReader.o
"__Z15av_register_allv", referenced from:
__Z10openStreamPKcb in RTPReader.o
"__Z19av_find_best_streamP15AVFormatContext11AVMediaTypeiiPP7AVCodeci", referenced from:
__Z10openStreamPKcb in RTPReader.o
"__Z14av_free_packetP8AVPacket", referenced from:
__Z13getStreamDataRPhRi in RTPReader.o
__Z11closeStreamv in RTPReader.o
"__Z6av_logPviPKcz", referenced from:
__Z10openStreamPKcb in RTPReader.o
__Z13getStreamDataRPhRi in RTPReader.o
"__Z19avformat_open_inputPP15AVFormatContextPKcP13AVInputFormatPP12AVDictionary", referenced from:
__Z10openStreamPKcb in RTPReader.o
"__Z26av_samples_get_buffer_sizePiii14AVSampleFormati", referenced from:
__Z13getStreamDataRPhRi in RTPReader.o
"__Z19avcodec_alloc_framev", referenced from:
__Z13getStreamDataRPhRi in RTPReader.o
"__Z25avformat_find_stream_infoP15AVFormatContextPP12AVDictionary", referenced from:
__Z10openStreamPKcb in RTPReader.o
"__Z13av_read_frameP15AVFormatContextP8AVPacket", referenced from:
__Z13getStreamDataRPhRi in RTPReader.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Somehow it is adding a prefix _Z## to all my C++ methods, and I don't know why.
What could be the issue?
Al the __Z## stuff you see, is normal. It is called 'name mangling' in C++, see http://en.wikipedia.org/wiki/Name_mangling for a good explanation.
I have to make a couple of guesses here, lacking more detailed info (sorry, I cannot comment yet, only answer). Looking at the ffmpeg api docs, it seems that FFmpeg has a C API, not C++. If that is indeed the case, your solution may be to wrap all #includes of FFmpeg files with extern "C", for example (see http://developers.sun.com/solaris/articles/mixing.html for explanation):
extern "C" {
#include <someffmpegheader.h>
}
As for the reason the link fails, are you linking against a pre-built ffmpeg library, or are you including the ffmpeg source files in your project? If you're linking to a library, it may not have the correct architectures. If you run the following command in a terminal window, it will tell you what architectures are available in the library:
file libffmpeg.a