1

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
geoffjay
  • 413
  • 4
  • 13
  • @Tsyvarev added entire error output. – geoffjay Oct 17 '20 at 21:10
  • `find_library` should store into the variable, passed to it as the first parameter, an **absolute path**. But the message from the linker implies relative path. You may try to perform **clean reconfiguration** of the project, that is removing `CMakeCache.txt` from the build directory and run `cmake` again. – Tsyvarev Oct 17 '20 at 22:47
  • unfortunately, that doesn't help. I think it's possible that the symbol for the library isn't actually `BMDSwitcherAPI`, and it's not documented by the vendor what else it would be – geoffjay Oct 19 '20 at 17:16
  • Whatever vendor tells, `find_library` shouldn't assign `BMDSwitcherAPI` value to `BMDSwitcherAPI` variable. You may add `message(STATUS "BMDSwitcherAPI: ${BMDSwitcherAPI"}` after `find_library` call and may check what it will print. – Tsyvarev Oct 19 '20 at 17:51

1 Answers1

0

This may not be helpful to anyone else because it was so specific to the one library I was using, but here it is anyway.

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})
geoffjay
  • 413
  • 4
  • 13