Tôi muốn xây dựng một liên kết tĩnh thực thi được liên kết tĩnh với libavcodec và libavformat. Thư viện ffmpeg tĩnh đã được xây dựng với:Tham chiếu không xác định đến avcodec_alloc_context nhưng lệnh liên kết ffmpeg chính xác?
./configure --enable-static --enable-gpl --enable-nonfree --disable-vaapi
--disable-libopus --prefix=myBuild --disable-swresample
Các linkers được thiết lập như sau:
g++ -O2 -static -o myBin myBin-myBin.o someotherlibraries.a
-L/ffmpeg/myBuild/lib -lavformat -lavcodec -lavutil -lrt -lm -lpthread -lz
Khi biên dịch, tôi nhận được CHỈ MỘT thông báo lỗi>: -/
src/ffmpeg/myProgram.cpp:115: error: undefined reference to 'avcodec_alloc_context'
Đầu ra của nm /ffmpeg/myBuild/lib/libavcodec.a | grep avcodec_alloc_context:
U avcodec_alloc_context3
U avcodec_alloc_context3
000003c0 T avcodec_alloc_context3
U avcodec_alloc_context3
tôi bao gồm libavcodec.h với extern "C" {} và tôi tin để mối liên kết tĩnh của tôi là đúng. Tại sao tôi nhận được lỗi này? Có phải vì phương pháp này không được chấp nhận? Làm sao tôi có thể giải quyết việc này?
SOLUTION:
Dont sử dụng
avCtx = avcodec_alloc_context()
từ các đoạn mã có thể cũ hơn, nhưng sử dụng
codec = avcodec_find_decoder(CODEC_ID_XYZ);//for completeness but should be the same as before
avCtx = avcodec_alloc_context3(codec)
đầu ra của 'nm /ffmpeg/myBuild/lib/libavcodec.a là gì | grep avcodec_alloc_context'? –
Tôi đã thêm đầu ra vào bài đăng của mình – user2212461
@PaoloBonzini có nói gì với bạn không? – user2212461