我已经基于this post构建了一个静态opencv库,之后我想为我的应用程序调用静态opencv库。但是,似乎应用程序无法链接静态opencv库,它给了我以下警告:
ld: warning: ignoring file /usr/local/lib/libopencv_core.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/libopencv_core.a
ld: warning: ignoring file /usr/local/lib/libopencv_highgui.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/libopencv_highgui.a
ld: warning: ignoring file /usr/local/lib/libopencv_imgproc.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/libopencv_imgproc.a
ld: warning: ignoring file /usr/local/lib/liblibjasper.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/liblibjasper.a
ld: warning: ignoring file /usr/local/lib/liblibjpeg.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/liblibjpeg.a
ld: warning: ignoring file /usr/local/lib/liblibpng.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/liblibpng.a
ld: warning: ignoring file /usr/local/lib/liblibtiff.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/liblibtiff.a
ld: warning: ignoring file /usr/local/lib/libzlib.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/libzlib.a
ld: warning: ignoring file /usr/local/lib/libIlmImf.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/libIlmImf.a
在我看来,应用程序正在尝试调用动态opencv库,而只调用cv::Mat
测试的简单应用程序会给我以下错误:
Undefined symbols for architecture i386:
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in main.o
"cv::fastFree(void*)", referenced from:
cv::Mat::~Mat() in main.o
修改 由于答案表明它不是链接问题,而是链接为不同体系结构构建的库的问题。除此之外,构建和使用静态OpenCV库时应注意的另外两件重要事项是:
确保它仅构建Active Architecture(是)。
此外,您应该链接opencv_highgui.a使用的framework Cocoa;general;-framework QTKit;general;-framework QuartzCore;general;-framework AppKit;
。
答案 0 :(得分:2)
这不是关于不成功的链接,这是关于不成功的建设。 '文件是为归档而构建的,而不是被链接的体系结构(i386)'。您需要正确构建它,所以说,构建它以获得正确的架构。
答案 1 :(得分:1)
我相信通过不向cmake
命令行传递任何选项,它确实为您的计算机的本机架构(这是默认选项)构建了库,大概是 x86_64 。但是,出于某种原因,您正在尝试在此构建一个32位 i386 应用程序。因此,您的架构没有正确的静态库。
您可以通过在-Darch=i386
中以32位(cmake
)构建OpenCV,或者通过构建应用程序64位(本机arch或x86_64,具体取决于您的构建系统)来解决此问题。 / p>
如果您觉得很勇敢,您还可以构建32位和64位静态库,将它们组装成通用二进制文件,并链接到该通用库。
答案 2 :(得分:0)
您应该使用以下方式构建本地应用程序:
cmake .. -DOpenCV_DIR=/path/to/opencv-3.0.0-beta/build/ -DCMAKE_OSX_ARCHITECTURES=x86_64
即。强制本地构建为x86_64,这就是opencv版本