所以我有一个库,可以在使用其 CMake 自行编译时进行编译。然后我将此库作为 git 子模块包含在另一个项目中,但现在由于某种原因无法在代码中找到引用。
/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'
这是自己构建的库的CMakeLists.txt:
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)
这是该项目的 CMakeLists.txt。请注意,
cmake
可以工作,但在尝试使用make
或ninja
时,我收到上面的错误消息。
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)