问题描述
我正在尝试使用 CMake 构建一个基于 OpenCV 的项目,该项目在 Linux 上运行.到目前为止,我的 CMakeLists.txt
文件看起来像
I'm trying to build an OpenCV-based project using CMake, running on Linux. So far my CMakeLists.txt
files looks something like
FIND_PACKAGE (OpenCV REQUIRED)
...
TARGET_LINK_LIBRARIES (my-executable ${OpenCV_LIBS})
但这会导致动态链接库.如何链接静态库?
but this results in dynamically linked libraries. How do I link with static libraries?
推荐答案
您只需在 CMake 中将 BUILD_SHARED_LIBS
标志设置为 false 即可构建静态 OpenCV 库.然后,使用这些静态库构建自己的应用程序所需要做的就是在 CMakeLists.txt
中添加对 OpenCV 的依赖:
You build static OpenCV libraries by just setting the BUILD_SHARED_LIBS
flag to false in CMake. Then all you need to do to build your own application with those static libraries is to add a dependency on OpenCV in your CMakeLists.txt
:
FIND_PACKAGE (OpenCV REQUIRED)
...
TARGET_LINK_LIBRARIES (your-application ${OpenCV_LIBS})
CMake 会处理一切.
and CMake will take care of everything.
这篇关于我如何告诉 cmake 我希望我的项目静态链接库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!