sdl2-image是作为静态库libSDL2_image.a
构建和安装的,它依赖于另一个静态库,如webp,libpng等。当我链接它时:
add_executable(main main.cpp)
target_link_libraries(main
SDL2::SDL2-static
${SDL2_IMAGE_LIBRARY}
)
失败,显示错误:
[ 50%] Linking CXX executable main
/usr/local/Cellar/cmake/3.11.1/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1
/Library/Developer/CommandLineTools/usr/bin/c++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/main.dir/main.cpp.o -o main /Users/Ryan/vcpkg/installed/x64-osx/debug/lib/libSDL2d.a /Users/Ryan/vcpkg/installed/x64-osx/lib/libpng16.a /Users/Ryan/vcpkg/installed/x64-osx/debug/lib/libSDL2_image.a /Users/Ryan/vcpkg/installed/x64-osx/lib/libwebp.a /Users/Ryan/vcpkg/installed/x64-osx/lib/libjpeg.a /Users/Ryan/vcpkg/installed/x64-osx/lib/libpng16.a -lm -liconv -framework CoreVideo -framework Cocoa -framework IOKit -framework ForceFeedback -framework Carbon -framework CoreAudio -framework AudioToolbox -Wl,-undefined,error /Users/Ryan/vcpkg/installed/x64-osx/lib/libz.a
Undefined symbols for architecture x86_64:
"_IMG_InitJPG", referenced from:
_IMG_Init in libSDL2_image.a(IMG.c.o)
"_IMG_InitPNG", referenced from:
_IMG_Init in libSDL2_image.a(IMG.c.o)
"_IMG_InitTIF", referenced from:
_IMG_Init in libSDL2_image.a(IMG.c.o)
"_IMG_Load", referenced from:
发生了什么事?
另一个问题:
提供一个静态库libA.a和libB.a,它依赖于libA.a. 如果我用libB.a链接程序,我还必须链接libA.a,例如
add_executable(main main.cpp)
target_link_libraries(main
/path/to/libB.a
/path/to/libA.a
)
有必要吗?如果和为什么? 如果libA.a有其他依赖关系但我不知道,我该怎么办?