问题描述
我的问题如下:
我有 OpenSSL 作为静态库(libcrypto.a
和libssl.a
).在Windows上使用 MSys2/MinGW64 进行编译.除此之外,我还有一个基于OpenSSL
的小型自行编写的库.
I have OpenSSL as static libraries (libcrypto.a
and libssl.a
).Compiled on Windows with MSys2/MinGW64.Besides that, I have a small self written library based on OpenSSL
.
现在,我想将Crypto lib
从具有我的lib的OpenSSL
捆绑到一个大"静态库,以便以后在Windows上的其他应用程序中进行静态编译而无需部署任何库.
Now I want to "bundle" the Crypto lib
from OpenSSL
with My lib to a "big" static library for later statically compiling in other applications on Windows without deploying any library.
CMakeLists.txt
文件的外观如何?前提条件(OpenSSL
和static libs
)正确吗?
What would a CMakeLists.txt
file looks like? And are the prerequisites (OpenSSL
as static libs
) correct?
实际上将其编译为动态的DLL
就像一个吊饰.但是我的静态库仅包含我自己的库的符号,也没有来自OpenSSL
的符号.
Actually compiling this to a dynamic DLL
works like a charm. But My static lib are only includes the symbols of My own library, not from OpenSSL
too.
实际上我没有可用的CMake
文件,因此无法提供示例.我只是在寻找如何做的方向.
Actually I have no working CMake
file, so I can't include an example. I'm just looking for a direction how to do it.
对于如何开始的简短建议,我们将不胜感激.
A short suggestion how to begin would be highly appreciated.
推荐答案
如果您真正想做的是将多个静态库组合到一个中,为了方便外部使用者,您可能需要运行一个自定义命令来执行此操作(因为这不是经常执行的操作).
If what you really want to do is combine multiple static libraries into one, for the convenience of external consumers, you'll probably need to run a custom command to do this (as it's not something that's frequently done).
使用GNU工具链,执行此操作的命令可能看起来像这样(虽然未经测试):
Using the GNU toolchain, the commands to do so might look something like this (untested though):
${CMAKE_COMMAND} -E make_directory tempdir
cd tempdir
${CMAKE_AR} x $<yourlib:TARGET_FILE>
${CMAKE_AR} x ${OPENSSL_CRYPTO_LIBRARY}
${CMAKE_AR} x ${OPENSSL_SSL_LIBRARY}
${CMAKE_AR} cf ${CMAKE_BINARY_DIR}/bin/libyourmegalib.a *.o
cd ..
${CMAKE_COMMAND} -E remove_directory tempdir
然后,您将使用add_custom_command()
创建目标以运行此脚本-将这些行作为COMMAND
自变量,或创建脚本模板,使用configure_file()
在CMake生成时替换值,然后进行自定义命令运行该脚本.
Then you would use add_custom_command()
to create a target to run this script - either put those lines as COMMAND
arguments, or create a script template, substitute values at CMake generation time using configure_file()
, then have the custom command run that script.
也就是说,如果外部使用者自己都在使用CMake,我将完全跳过此过程,而只是让您的库的安装过程生成CMake软件包配置文件,以声明对OpenSSL库的依赖关系.
That said, if the external consumers are all using CMake themselves, I would skip this entirely, and just have the installation process for your library generate CMake package configuration files that declare the dependencies on the OpenSSL libraries.
这篇关于CMake与其他静态库一起构建静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!