Скомпилированная библиотека со ссылками PUBLIC в cmake, но не может использовать связанные символы в моем проекте - PullRequest
1 голос
/ 14 октября 2019

У меня есть библиотека с именем liborwell.a, скомпилированная с помощью cmake, которая связана с моим маленьким проектом с помощью make-файла.

Вот как я связываю liborwell.a:

target_link_libraries(orwell PRIVATE 
${ZLIB_LIBRARY} ${X11_LIBRARY} ${LIB_VDPAU} ${LIB_VA} ${LIB_VA_DRM} ${LIB_VA_X11} 
myRtspClient-static ${GTKMM_LIBRARIES} ${GLEW_LIBRARY} ${GLU_LIBRARY} ${GL_LIBRARY} epoxy 
PUBLIC pthread -lstdc++fs AVCODEC_LIB AVUTIL_LIB SWS_SCALE_LIB SWRESAMPLE_LIB ${LIBDL_LIBRARY} zlmediakit zltoolkit )

и вот как я делаю ссылки в make-файле:

EXTRA_LDFLAGS=-L ../../gtk/build/desktoplinux -L ../../deps/ffmpeg/build/desktop/x86_64/lib -L ../../ -lGL -lorwell 

Библиотека cmake успешно компилируется, но в проекте, использующем эту библиотеку, компоновщик жалуется, что ffmpeg функционирует (например, av_codec_open2)отсутствуют:

FfmpegHardwareDecoder.cpp:(.text+0x5bb): undefined reference to `av_hwdevice_iterate_types'
FfmpegHardwareDecoder.cpp:(.text+0x5e3): undefined reference to `av_hwdevice_get_type_name'
../../gtk/build/desktoplinux/liborwell.a(FfmpegHardwareDecoder.cpp.o): In function `FfmpegHardwareDecoder::FfmpegHardwareDecoder(Decoder::Codec, FfmpegHardwareDecoder::Device, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
FfmpegHardwareDecoder.cpp:(.text+0x7b9): undefined reference to `av_hwdevice_find_type_by_name'
FfmpegHardwareDecoder.cpp:(.text+0x94a): undefined reference to `avcodec_find_decoder'
FfmpegHardwareDecoder.cpp:(.text+0x98d): undefined reference to `avcodec_find_decoder'
FfmpegHardwareDecoder.cpp:(.text+0x9b9): undefined reference to `avcodec_alloc_context3'
FfmpegHardwareDecoder.cpp:(.text+0xa3b): undefined reference to `avcodec_get_hw_config'
FfmpegHardwareDecoder.cpp:(.text+0xa53): undefined reference to `av_hwdevice_get_type_name'
FfmpegHardwareDecoder.cpp:(.text+0xb4f): undefined reference to `av_hwdevice_ctx_create'
FfmpegHardwareDecoder.cpp:(.text+0xbd4): undefined reference to `av_buffer_ref'
FfmpegHardwareDecoder.cpp:(.text+0xc13): undefined reference to `avcodec_open2'
../../gtk/build/desktoplinux/liborwell.a(FfmpegHardwareDecoder.cpp.o): In function `FfmpegHardwareDecoder::hardwareDecode(std::shared_ptr<EncodedPacket>)':
FfmpegHardwareDecoder.cpp:(.text+0xdd4): undefined reference to `avcodec_send_packet'
FfmpegHardwareDecoder.cpp:(.text+0xe2f): undefined reference to `av_frame_alloc'
FfmpegHardwareDecoder.cpp:(.text+0xe4a): undefined reference to `av_frame_alloc'
FfmpegHardwareDecoder.cpp:(.text+0xef7): undefined reference to `avcodec_receive_frame'
../../gtk/build/desktoplinux/liborwell.a(FfmpegHardwareDecoder.cpp.o): In function `FfmpegHardwareDecoder::sendPacket(std::shared_ptr<EncodedPacket>, std::shared_ptr<DecodedFrame>)':
FfmpegHardwareDecoder.cpp:(.text+0x1134): undefined reference to `av_frame_alloc'
FfmpegHardwareDecoder.cpp:(.text+0x11a6): undefined reference to `av_hwframe_transfer_data'
../../gtk/build/desktoplinux/liborwell.a(FfmpegHardwareDecoder.cpp.o): In function `AVPacketDeleter::operator()(AVPacket*)':
FfmpegHardwareDecoder.cpp:(.text._ZN15AVPacketDeleterclEP8AVPacket[_ZN15AVPacketDeleterclEP8AVPacket]+0x18): undefined reference to `av_packet_unref'
../../gtk/build/desktoplinux/liborwell.a(FfmpegHardwareDecoder.cpp.o): In function `AVFrameDeleter::operator()(AVFrame*)':
FfmpegHardwareDecoder.cpp:(.text._ZN14AVFrameDeleterclEP7AVFrame[_ZN14AVFrameDeleterclEP7AVFrame]+0x18): undefined reference to `av_frame_unref'
../../gtk/build/desktoplinux/liborwell.a(FfmpegHardwareDecoder.cpp.o): In function `AVBufferRefDeleter::operator()(AVBufferRef*)':
FfmpegHardwareDecoder.cpp:(.text._ZN18AVBufferRefDeleterclEP11AVBufferRef[_ZN18AVBufferRefDeleterclEP11AVBufferRef]+0x18): undefined reference to `av_buffer_unref'
../../gtk/build/desktoplinux/liborwell.a(FfmpegHardwareDecoder.cpp.o): In function `AVCodecContextDeleter::operator()(AVCodecContext*)':
FfmpegHardwareDecoder.cpp:(.text._ZN21AVCodecContextDeleterclEP14AVCodecContext[_ZN21AVCodecContextDeleterclEP14AVCodecContext]+0x18): undefined reference to `avcodec_free_context'
../../gtk/build/desktoplinux/liborwell.a(FfmpegSoftwareDecoder.cpp.o): In function `FfmpegSoftwareDecoder::FfmpegSoftwareDecoder(Decoder::Codec)':
FfmpegSoftwareDecoder.cpp:(.text+0x5db): undefined reference to `avcodec_find_decoder'
FfmpegSoftwareDecoder.cpp:(.text+0x67a): undefined reference to `avcodec_alloc_context3'
FfmpegSoftwareDecoder.cpp:(.text+0x6b3): undefined reference to `avcodec_open2'
../../gtk/build/desktoplinux/liborwell.a(FfmpegSoftwareDecoder.cpp.o): In function `FfmpegSoftwareDecoder::sendPacket(std::shared_ptr<EncodedPacket>, std::shared_ptr<DecodedFrame>)':
FfmpegSoftwareDecoder.cpp:(.text+0x903): undefined reference to `av_log_set_level'
FfmpegSoftwareDecoder.cpp:(.text+0x94a): undefined reference to `av_packet_alloc'
FfmpegSoftwareDecoder.cpp:(.text+0xa3f): undefined reference to `avcodec_send_packet'
FfmpegSoftwareDecoder.cpp:(.text+0xa4a): undefined reference to `av_frame_alloc'
FfmpegSoftwareDecoder.cpp:(.text+0xa9c): undefined reference to `avcodec_receive_frame'
../../gtk/build/desktoplinux/liborwell.a(FileWriter.cpp.o): In function `FileWriter::setPath(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
FileWriter.cpp:(.text+0xc25): undefined reference to `std::experimental::filesystem::v1::create_directories(std::experimental::filesystem::v1::__cxx11::path const&)'
../../gtk/build/desktoplinux/liborwell.a(FileWriter.cpp.o): In function `std::experimental::filesystem::v1::__cxx11::path::path(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)':
FileWriter.cpp:(.text._ZNSt12experimental10filesystem2v17__cxx114pathC2EONSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZNSt12experimental10filesystem2v17__cxx114pathC5EONSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x4c): undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'
../../gtk/build/desktoplinux/liborwell.a(ZLRTSPClient.cpp.o): In function `ZLRTSPClient::startThreadMode()':
ZLRTSPClient.cpp:(.text._ZN12ZLRTSPClient15startThreadModeEv[_ZN12ZLRTSPClient15startThreadModeEv]+0x76): undefined reference to `mediakit::Client::kRtpType[abi:cxx11]'

Я проверил liborwell.a:

nm liborwell.a | grep avcodec_open
                 U avcodec_open2
                 U avcodec_open2

nm liborwell.a | grep av_frame_alloc
                 U av_frame_alloc
                 U av_frame_alloc

Как видите, символы есть.

Что я делаю не так?

Вот полная команда связывания, если кто-то вставлен:

 "/usr/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o /home/dev/orwell/orwell_flutter/linux/../build/linux/debug/flutter_desktop_example /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crt1.o /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/crtbegin.o -L/home/dev/orwell/orwell_flutter/linux/../build/linux/debug/lib -L../../gtk/build/desktoplinux -L../../deps/ffmpeg/build/desktop/x86_64/lib -L../../ -L/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../.. -L/usr/lib/llvm-6.0/bin/../lib -L/lib -L/usr/lib /home/dev/orwell/orwell_flutter/linux/../build/linux/obj/main.o /home/dev/orwell/orwell_flutter/linux/../build/linux/obj/flutter/generated_plugin_registrant.o /home/dev/orwell/orwell_flutter/linux/../build/linux/obj//home/dev/orwell/orwell_flutter/linux/flutter/ephemeral/cpp_client_wrapper_glfw/flutter_window_controller.o /home/dev/orwell/orwell_flutter/linux/../build/linux/obj//home/dev/orwell/orwell_flutter/linux/flutter/ephemeral/cpp_client_wrapper_glfw/plugin_registrar.o /home/dev/orwell/orwell_flutter/linux/../build/linux/obj//home/dev/orwell/orwell_flutter/linux/flutter/ephemeral/cpp_client_wrapper_glfw/engine_method_result.o /home/dev/orwell/orwell_flutter/linux/../build/linux/obj//home/dev/orwell/orwell_flutter/linux/flutter/ephemeral/cpp_client_wrapper_glfw/standard_codec.o /home/dev/orwell/orwell_flutter/linux/../build/linux/obj/../common/src/flutter_video_renderer.o /home/dev/orwell/orwell_flutter/linux/../build/linux/obj/../common/src/flutter_texture_video_renderer.o /home/dev/orwell/orwell_flutter/linux/../build/linux/obj/../common/src/flutter_orwell_plugin.o /home/dev/orwell/orwell_flutter/linux/../build/linux/obj/../../engine/src/flutter/third_party/glad/src/gl.o -lflutter_linux_glfw -lGL -lpthread -lorwell "-rpath=\$ORIGIN/lib" -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/crtend.o /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crtn.o

ОБНОВЛЕНИЕ:

Я только что обнаружил, что U в nm означаетundefined, но я скомпилировал исполняемый файл только для тестирования, и он не жаловался на неопределенность библиотеки, почему библиотека не может найти символы?

...