我现有的目录下有src、include、client、server四个文件夹,依赖/usr/local/lib/libhiredis.so.我希望用src、include牛成一个动态库,用server加这个动态库生成一个程序并封装成service。service的配置文件应该放置在哪儿,应该怎么写cmakelist.txt
时间: 2023-05-16 11:05:51 浏览: 159
MYSQL安装目录及配置文件详解.pdf
您可以将动态库生成的文件放在/usr/local/lib目录下,将头文件放在/usr/local/include目录下。service的配置文件可以放在/etc/systemd/system目录下,命名为your_service_name.service。关于cmakelist.txt的编写,您可以参考以下示例:
cmake_minimum_required(VERSION 3.5)
project(your_project_name)
set(CMAKE_CXX_STANDARD 11)
# 添加头文件路径
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
# 添加源文件路径
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src SRC_LIST)
# 添加动态库路径
link_directories(/usr/local/lib)
# 生成动态库
add_library(your_lib_name SHARED ${SRC_LIST})
# 链接动态库
target_link_libraries(your_lib_name hiredis)
# 生成可执行文件
add_executable(your_executable_name ${CMAKE_CURRENT_SOURCE_DIR}/server/main.cpp)
# 链接动态库
target_link_libraries(your_executable_name your_lib_name)
# 安装动态库和头文件
install(TARGETS your_lib_name DESTINATION /usr/local/lib)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION /usr/local/include)
# 安装service配置文件
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/your_service_name.service DESTINATION /etc/systemd/system)
阅读全文