首页 > 解决方案 > Linking an external library bundle file on macos with cmake

问题描述

I have a library compiled as a single file that I'm trying to link with cmake but haven't been able to cobble together something that works using existing examples that should be related, eg.

CMake link an external library Cmake linking external libraries

What I have so far:

cmake_minimum_required(VERSION 3.17)
project(atem)

set(CMAKE_CXX_STANDARD 14)
set(BMD_API_LIB "BMDSwitcherAPI")
set(BMD_API_PATH "/Library/Application Support/Blackmagic Design/Switchers/BMDSwitcherAPI.bundle/Contents/MacOS/")

find_library(BMDSwitcherAPI ${BMD_API_LIB} PATHS ${BMD_API_PATH})

add_executable(atem main.cpp BMDSwitcherAPIDispatch.cpp)

target_link_libraries(atem ${BMDSwitcherAPI})

The files main.cpp and BMDSwitcherAPIDispatch.cpp exist in the same directory. Building says that the file for the library can't be found, but the binary for the library file for ${BMD_API_LIB} cannot be found, but it is definitely at the path given in ${BMD_API_PATH}.

I'm not sure where to go from here.

Edit: added entire error message

====================[ Build | atem | Debug ]====================================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/user/Code/atem/cmake-build-debug --target atem -- -j 9
[ 33%] Linking CXX executable atem
ld: library not found for -lBMDSwitcherAPI
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [atem] Error 1
make[2]: *** [CMakeFiles/atem.dir/all] Error 2
make[1]: *** [CMakeFiles/atem.dir/rule] Error 2
make: *** [atem] Error 2

标签: c++cmake

解决方案


这可能对其他人没有帮助,因为它对我正在使用的一个库来说是如此特定,但无论如何它都在这里。

cmake_minimum_required(VERSION 3.17)
project(atem)
set(CMAKE_CXX_STANDARD 14)
find_library(CoreFoundation_Library CoreFoundation)
mark_as_advanced(CoreFoundation_Library)
set(
    SWITCHERS_SDK_INCLUDE_DIR
    /Applications/Blackmagic\ ATEM\ Switchers/Developer\ SDK/Mac\ OS\ X/include/
)
add_executable(
    atem
    atem/main.cpp
    ${SWITCHERS_SDK_INCLUDE_DIR}/BMDSwitcherAPIDispatch.cpp
)
target_include_directories(atem PRIVATE ${SWITCHERS_SDK_INCLUDE_DIR})
target_link_libraries(atem ${CoreFoundation_Library})

推荐阅读