我正在组织我的“C语言开发策略”并在静态和共享库中分发一些代码。
静态库是可以的,但我发现文档中的共享库存在“差距”:如何在“find_library”上指定SOVERSION。
此刻我正在以这种方式构建库:
my.expressions <-c(as.expression(bquote('N'['F']*' = '*.( N_female))),as.expression(bquote('N'['M']*' = '*.( N_male))) )
N_male<-4#random variable
N_female<-6#random variable
plot(x=2,y=3)#random plot
legend("topright",legend=my.expressions,
text.col="black",box.col=0, bty="n", cex = .75, lty= c(2:3))
运行cmake,make和make install会导致:
cmake_minimum_required (VERSION 2.8.11)
set (INSTALL_BIN_DIR "" CACHE PATH "full binary path")
set (INSTALL_LIB_DIR "$ENV{HOME}/embedded/llib/lib" CACHE PATH "full binary path")
set (INSTALL_INCLUDE_DIR "$ENV{HOME}/embedded/llib/include" CACHE PATH "full include path")
set (SRC_DIR "src" CACHE PATH "Source files path")
set (H_DIR "include" CACHE PATH "Source files path")
set (C_FILES )
list (
APPEND C_FILES
${SRC_DIR}/cJSON.c
)
set (H_FILES )
list (
APPEND H_FILES
${H_DIR}/cJSON.h
)
# Define Project name
project (cJSON)
# Create a library called "cJSON" which includes the source and header files.
add_library (cJSON SHARED "${C_FILES}")
#set_target_properties(cJSON PROPERTIES
# PUBLIC_HEADER "include/cJSON.h")
include_directories (include)
# Make sure the compiler can find include files for our Hello library
# when other libraries or executables link to Hello
#target_include_directories (cJSON PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties (cJSON
PROPERTIES
VERSION 1.0 SOVERSION 1
PUBLIC_HEADER "${H_FILES}"
)
install(TARGETS cJSON
# IMPORTANT: Add the foo library to the "export-set"
EXPORT cJSONTargets
LIBRARY
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT shlib
PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}" COMPONENT dev
)
在另一个图书馆,我是这样写的:
lrwxrwxrwx 1 takaite takaite 13 Dez 7 11:52 libcJSON.so -> libcJSON.so.1
lrwxrwxrwx 1 takaite takaite 15 Dez 7 11:52 libcJSON.so.1 -> libcJSON.so.1.0
-rw-r--r-- 1 takaite takaite 27194 Dez 7 15:03 libcJSON.so.1.0
我无法相信这是正确的做法。任何人都可以向我展示更好的方式吗?
答案 0 :(得分:3)
对于库的搜索特定搜索,您可以在NAMES
的{{1}}选项中使用精确文件名:
find_library
来自find_library的文档:
首先将赋予NAMES选项的每个库名称视为库文件名,然后考虑使用特定于平台的前缀(例如lib)和后缀(例如.so)。因此,可以直接指定库文件名,例如libfoo.a。这可以用于在类UNIX系统上定位静态库。
请注意,相同库的不同 soversion 被假定为ABI 兼容彼此。所以很少需要搜索图书馆的特定搜索。
引入ABI 不可接受性的库中的更改应伴随更改库的版本。例如:find_library (
CJSON_LIB
NAMES libcJSON.so.1
PATHS ${INSTALL_LIB_DIR}
)
。因此,您无法使用libcJSON2.so
意外找到不兼容的库。