如何生产“独立”的产品?静态库?
我以共享库的形式开发了一个框架(在Linux中)。用户请求该库的静态版本。我使用 cmake,因此只需将 BUILD_SHARED_LIBS 切换为 OFF。正如预期的那样,我最终得到了一个静态库。
然而,用户抱怨说他现在必须链接到我的库的依赖项 boost 和 hdf5。
您认为我必须采取行动来避免这种情况吗?还是正常的?是否有可能提供一个没有依赖项的库?
编辑:我应该做一些事情,比如从 boost 和 hdf5 静态库中提取目标文件并在构建我自己的库时添加它们吗?
I develop a framework under the form of a shared library (in Linux). A user asked for a static version of the library. I use cmake and therefore just switched BUILD_SHARED_LIBS to OFF. I ended up with a static library as expected.
However, the user complained that he has now to link against boost and hdf5 that are dependencies of my library.
Do you think that I have to take action to avoid this situation ? Or is it normal ? Is it ever possible to provide a library that has no dependencies ?
EDIT: Should I do something like extracting the object files from the boost and hdf5 static libraries and add them when building my own ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
boost的解决方案是:
对于hdf5,你可以尝试这样的方法。
使用
将静态库复制到构建树中的目录中
EXEC_PROGRAM( ${CMAKE_COMMAND} -E copy_if_ Different ${HDF_LIB} ${PROJECT_BINARY_DIR}/HDFStaticLib)
首先添加 HDFStaticLib 的链接目录
LINK_DIRECTORIES(${PROJECT_BINARY_DIR}/HDFStaticLib)
像这样添加库:
TARGET_LINK_LIBRARIES(foo ${PROJECT_BINARY_DIR}/HDFStaticLib/HDF)
还有一件事:如果文件名不存在,您应该将 API.a 重命名为 libAPI.a从lib开始。
The boost' solution is:
For hdf5 you could try something like this.
Copy the static library into a directory in your build tree with
EXEC_PROGRAM( ${CMAKE_COMMAND} -E copy_if_different ${HDF_LIB} ${PROJECT_BINARY_DIR}/HDFStaticLib)
Add the link directory for HDFStaticLib first with
LINK_DIRECTORIES(${PROJECT_BINARY_DIR}/HDFStaticLib)
Add the library like this:
TARGET_LINK_LIBRARIES(foo ${PROJECT_BINARY_DIR}/HDFStaticLib/HDF)
One more thing: you should have renamed API.a to libAPI.a, if the file name does not start by lib.