惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Attack and Defense Labs
Attack and Defense Labs
V2EX - 技术
V2EX - 技术
O
OpenAI News
S
Secure Thoughts
H
Heimdal Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Schneier on Security
Schneier on Security
H
Hacker News: Front Page
S
Security Affairs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
The Register - Security
The Register - Security
GbyAI
GbyAI
Cloudbric
Cloudbric
MongoDB | Blog
MongoDB | Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Forbes - Security
Forbes - Security
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Cloudflare Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Webroot Blog
Webroot Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
V
V2EX
T
Tailwind CSS Blog
SecWiki News
SecWiki News
NISL@THU
NISL@THU
C
Check Point Blog

OpenCV

目标检测,计算出旋转速度和加速度,有人精通吗?急 - V2EX opencv 图像动态融合问题 - V2EX 请问一个关于 OpenCV 手眼标定(cv::calibrateHandEye)获取相机安装参数的问题 - V2EX opencv 去除视频中移动的文字 - V2EX Opencv 遇到一个很奇怪的问题, mac 上获取摄像头图片,必须需要 sleep 一下, 0.1 都可以,但是不给就是黑图,代码如下,有没有大佬指点一下 - V2EX 请教一个 opencv 算法,图片中检测圆形对象 - V2EX 用 C++调用 OpenCV 的 matchTemplate 反而比 Python 更慢 - V2EX mov 视频的图片如何转换? - V2EX 大家有用过类似 PS Content-Aware Fill 抠图的库或源码吗(不限语言) - V2EX nii 文件用 opencv 转换为 mp4 视频画面失真,求教 - V2EX [求助] 如何确定点在曲线中的位置 - V2EX 哇 期待很久的 计算机视觉 - V2EX
[求助]C++ 用到 OpenCV 库 怎么静态编译呢? - V2EX
norkki · 2024-06-16 · via OpenCV

请问 c++用怎样正确的静态编译呢? 目的是让编译的程序不在依赖 libopencv_*.so 文件

测试代码如下:

cv-test.cc

#include <opencv2/opencv.hpp>
#include <iostream>

int main(int argc, char** argv) {
        cv::Mat image = cv::imread("image.jpg");
        if (image.empty()) {
                std::cout << "Error loading image!" << std::endl;
                return -1;
        }
        // cv::imshow("Image", image);
        std::cout << "size: "
                << image.cols << "x" << image.rows
                << std::endl;
        return 0;
}

c++ -o cv-test cv-test.cc -I/usr/local/opencv/include/opencv4/ -L/usr/local/opencv/lib64/ -lopencv_core -lopencv_imgcodecs

正常编译

加上 -static尝试静态编译 (opencv 是有编译静态库的/usr/local/opencv/lib64/libopencv_core.a)

c++ -o cv-test cv-test.cc -I/usr/local/opencv/include/opencv4/ -L/usr/local/opencv/lib64/ -lopencv_core -lopencv_imgcodecs -static

报错:

/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(opencl_core.cpp.o): in function `opencl_check_fn(int)':
/home/nick/github/opencv/modules/core/src/opencl/runtime/opencl_core.cpp:166: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(matrix_transform.cpp.o): in function `ipp::IwiImage::Release()':
/home/nick/github/opencv/build/3rdparty/ippicv/ippicv_lnx/iw/include/iw++/iw_image.hpp:945: undefined reference to `iwAtomic_AddInt'
/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(matrix_transform.cpp.o): in function `ipp::IwiImage::~IwiImage()':
/home/nick/github/opencv/build/3rdparty/ippicv/ippicv_lnx/iw/include/iw++/iw_image.hpp:813: undefined reference to `iwAtomic_AddInt'
/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(matrix_transform.cpp.o): in function `ipp::IwiImage::Release()':
/home/nick/github/opencv/build/3rdparty/ippicv/ippicv_lnx/iw/include/iw++/iw_image.hpp:957: undefined reference to `iwiImage_Release'
/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(matrix_transform.cpp.o): in function `ipp::IwException::IwException(int)':
/home/nick/github/opencv/build/3rdparty/ippicv/ippicv_lnx/iw/include/iw++/iw_core.hpp:133: undefined reference to `iwGetStatusString'
/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(matrix_transform.cpp.o): in function `cv::transpose(cv::_InputArray const&, cv::_OutputArray const&)':
/home/nick/github/opencv/modules/core/src/matrix_transform.cpp:228: undefined reference to `ippicviTranspose_32f_C4R'
/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(matrix_transform.cpp.o): in function `ipp_transpose':
/home/nick/github/opencv/modules/core/src/matrix_transform.cpp:228: undefined reference to `ippicviTranspose_32s_C3R'
/usr/bin/ld: /home/nick/github/opencv/modules/core/src/matrix_transform.cpp:228: undefined reference to `ippicviTranspose_16s_C3R'

...

/usr/bin/ld: /usr/local/opencv/lib64//libopencv_imgcodecs.a(grfmt_webp.cpp.o): in function `std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<unsigned char*, void (*)(void*), std::allocator<void>, void>(unsigned char*, void (*)(void*), std::allocator<void>)':
/usr/include/c++/13/bits/shared_ptr_base.h:958: undefined reference to `WebPFree'
/usr/bin/ld: /usr/local/opencv/lib64//libopencv_imgcodecs.a(grfmt_webp.cpp.o): in function `cv::WebPEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)':
/home/nick/github/opencv/modules/imgcodecs/src/grfmt_webp.cpp:286: undefined reference to `WebPEncodeLosslessBGRA'
/usr/bin/ld: /usr/local/opencv/lib64//libopencv_imgcodecs.a(grfmt_webp.cpp.o): in function `std::_Sp_ebo_helper<0, void (*)(void*), false>::_Sp_ebo_helper(void (*&&)(void*))':
/usr/include/c++/13/bits/shared_ptr_base.h:482: undefined reference to `WebPFree'
/usr/bin/ld: /usr/local/opencv/lib64//libopencv_imgcodecs.a(grfmt_webp.cpp.o): in function `cv::WebPEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)':
/home/nick/github/opencv/modules/imgcodecs/src/grfmt_webp.cpp:271: undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/usr/bin/ld: /home/nick/github/opencv/modules/imgcodecs/src/grfmt_webp.cpp:293: undefined reference to `WebPEncodeBGR'
/usr/bin/ld: /home/nick/github/opencv/modules/imgcodecs/src/grfmt_webp.cpp:297: undefined reference to `WebPEncodeBGRA'
/usr/bin/ld: /home/nick/github/opencv/modules/imgcodecs/src/grfmt_webp.cpp:282: undefined reference to `WebPEncodeLosslessBGR'
/usr/bin/ld: cv-test: hidden symbol `opj_stream_destroy' isn't defined
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status

请问大佬有没有办法静态编译