OpenCV格式化程序类和Mat对象的cout产生链接器错误:体系结构x86_64的未定义符号:libopencv_co



我刚开始使用OpenCV,在浏览一些基本的示例程序时,收到了一个链接错误。所有的东西都应该是核心库libopencv_core.2.4.3.dylib的一部分,它被适当地链接(Mat对象没有问题,只是operations.hpp中的格式化程序类)

此外,如果行:cout<lt;格式(M,"C")<lt;endl;被排除在外,则代码编译良好,但存在异常行为。一旦M Mat对象被发送到cout,对象中包含的值就不会打印出来,随后对cout的调用也不会产生任何结果,即使代码运行到完成。

其他人有这个问题吗?

openCV 2.4.3来自macports,xcode 4.5.2,os x Lion 10.7.5

代码:(实际上是openCV示例代码中的cout_mat.cpp片段)

#include "/usr/local/include/opencv2/opencv.hpp"
#include "/usr/local/include/opencv2/core/operations.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int,char**)
{
Mat M = Mat::eye(4, 4, CV_64F);
M.at<double>(0,0) = CV_PI;
// print out val at 0,0
cout << "M(0,0) = " << M.at<double>(0,0) << endl;
// test serial out capabilities of cv::Mat (yields no output beyond M=)
cout << "M = " << endl << M << endl;
// try to print M(0,0) to screen again to demonstrate that cout no longer prints to screen
cout << "M(0,0) = " << M.at<double>(0,0) << endl;
// Try to format the output with 'c-style',  Note: if included in program this line yields linker error
cout << format(M,"C") << endl;

return 0;
}

调试器中的输出:行"cout<<format(M,"C")<<endl;"注释掉

M(0,0) = 3.14159
M = 

M=为空,同时为:M(0,0)=3.14159 添加cout

包含行"cout<<format(M,"C")<<endl;"的错误:

Undefined symbols for architecture x86_64:
"cv::Formatted::Formatted(cv::Mat const&, cv::Formatter const*, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
__ZN2cvL6formatERKNS_3MatEPKcRKNSt3__16vectorIiNS5_9allocatorIiEEEE in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

tomridge_1234的建议解决了我的两个问题。

在Project->Build Settings->Build Options->Compiler for c++/objective-c/c下:选择LLVM gcc 4.2代替Apple LLVM 4.1。

现在,cout适当地显示所有条目,并且format函数也能正常工作,而不会出现链接器错误。

相关内容

最新更新