linux - 将 OpenCV 构建为静态库

标签 linux opencv gcc cmake static-libraries

也许我遗漏了一些东西,但我无法构建 opencv 的静态库。

设置:

库本图 12.04

海湾合作委员会 4.6.3

制作 3.81

cmake 2.8.7

opencv 2.4.6.1(网站最后可用)

我手动完成所有工作。我尝试使用 cmake-gui 但没有成功。

我按照它写的去做。

$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D WITH_QT=ON -D BUILD_SHARED_LIBRARIES=OFF ..

(我也试过 BUILD_SHARED_LIBRARIES=NO)

我得到的是(例如核心):

  • libopencv_core.so
  • libopencv_core.so.2.4
  • libopencv_core.so.2.4.6
  • libopencv_core_pch_dephelp.a

说实话,我期待 libopencv_core.a

我是一个在 Linux 上构建包/库的新手。我确定我做错了什么,但我不知道是什么。我也不想使用动态库...

感谢您的帮助!

编辑 删除了 cmake 命令行中 -D ... 之间的空格

Result:

-- General configuration for OpenCV 2.4.6.1 =====================================
--   Version control:               unknown
-- 
--   Platform:
--     Host:                        Linux 3.2.0-51-generic x86_64
--     CMake:                       2.8.7
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/c++  (ver 4.6)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG -ggdb3
--     C Compiler:                  /usr/bin/gcc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG -ggdb3
--     Linker flags (Release):      
--     Linker flags (Debug):        
--     Precompiled headers:         YES
-- 
--   OpenCV modules:
--     To be built:                 core imgproc flann highgui features2d calib3d ml video objdetect contrib photo legacy gpu nonfree java python stitching superres ts videostab

...

-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    BUILD_PYTHON_SUPPORT
    BUILD_SHARED_LIBRARIES

我仍然看到 Built as dynamic libs?: YES 它告诉我它不关心 BUILD_SHARED_LIBRARIES 变量!

最佳答案

查看OpenCV's CMakeLists.txt ,看起来好像您为 OpenCV CMake 选项使用了错误的名称。

BUILD_SHARED_LIBRARIES 应该是 BUILD_SHARED_LIBSBUILD_PYTHON_SUPPORT 应该是 BUILD_opencv_python

关于linux - 将 OpenCV 构建为静态库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18222248/

相关文章:

c++ - 使用静态 glibc 编译共享对象 (.so)

linux - ubuntu 和 unix 关于目录和隐藏文件的东西

linux - 停止和关机

c++ - 用 if 语句检测蓝线

opencv - 如何加快 svm.predict 的速度?

c - 获取__data_start符号的地址

linux - 计算目录的校验和

linux - 魔法值有什么意义呢?

在 Cuda 内核中调用 Opencv 函数

c++ - 我可以让我的 Makefile 自动让 GCC 使用它支持的最新标准吗?