So I have a library that compiles when compiled by itself using its CMake. I then include this library as a git submodule in another project, and now it fails to find references in the code for some reason.
/usr/bin/ld: libfreedom/libfreedom.so: undefined reference to `drmModeGetResources'
/usr/bin/ld: libfreedom/libfreedom.so: undefined reference to `drmModeGetConnector'
/usr/bin/ld: libfreedom/libfreedom.so: undefined reference to `drmModeFreeConnector'
This is the CMakeLists.txt for the library that builds by itself:
cmake_minimum_required(VERSION 3.10)
project(libfreedom LANGUAGES C)
# Specify the C standard
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Add library target
add_library(libfreedom SHARED src/libfreedom.c)
target_include_directories(libfreedom PRIVATE /usr/include/libdrm)
# Prevent it from being called liblibfreedom.so
set_target_properties(libfreedom PROPERTIES
OUTPUT_NAME "freedom" # This will create libfreedom.so
)
# Install targets and configuration
install(TARGETS libfreedom DESTINATION lib)
install(FILES include/libfreedom.h DESTINATION include)
And this is the CMakeLists.txt for the project. Note that cmake
works but then while trying to use make
or ninja
I get the error messages above.
cmake_minimum_required(VERSION 3.10)
project(Freedom)
# Add the submodule as a dependency
add_subdirectory(libfreedom)
# Create the executable
add_executable(Freedom src/main.c)
# Link the submodule library to the main project
target_link_libraries(Freedom PRIVATE libfreedom)
target_include_directories(Freedom PRIVATE libfreedom/include)