c++ - 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
解决方案
这可能对其他人没有帮助,因为它对我正在使用的一个库来说是如此特定,但无论如何它都在这里。
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})
推荐阅读
- ms-access - 没有打开 VBA 编辑器,宏不起作用
- javascript - 在 javascript 和 reactjs 上对表格进行排序
- vba - 将页脚值拉为字符串
- scala - scala 文本中单词之间的绝对最小距离
- excel - 将范围复制到不同工作表中的下一个可用单元格
- git - 在 GitLab 上,如何比较两个不同提交的文件
- c# - 如何允许 python 脚本(在 C# 应用程序中调用)访问 USB 端口
- html - 让文本在底部 div 对齐
- php - 如果我当前的日志文件在 php 中大于 50mb,如何创建新的日志文件?
- javascript - 有什么 Object.create() 可以做而工厂函数不能做的事情吗?