3

我在运行 Lion 的 Macbook 上本地构建了 i386 风格的 OpenCV,方法是使用

cmake -G "Unix Makefiles" -D CMAKE_OSX_ARCHITECTURES=i386 -D CMAKE_C_FLAGS=-m32 -D CMAKE_CXX_FLAGS=-m32 ..
make -j8
sudo make install

库构建和发布良好,我已将它们添加到我的 xcode 项目中。但是,在构建我的测试应用程序时存在链接错误,它们似乎是名称修改问题。

Undefined symbols for architecture i386: "cv::namedWindow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from: _main in main.o "cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from: _main in main.o "cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from: _main in main.o

以 cv::imread 为例,从 libopencv_highgui.dylib 导出,名称为:

00007510 (__TEXT,__text) external __ZN2cv6imreadERKSsi 

而 main.o 正在引用符号

U __ZN2cv6imreadERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEi

另一方面,__ZN2cv7waitKeyEi来自同一个 dylib 链接的函数很好。

测试应用程序和框架都适用于 i386 arch。

任何想法可能导致此问题?

4

2 回答 2

2

我有同样的问题。我认为问题可能在于,如果您使用MacPorts编译 OpenCV 库,它们可能是由 GCC 根据它的 Portfile 构建的。我将 XCode(Apple LLVM 4.1)中使用的编译器切换到 LLVM GCC 4.2,现在它可以工作了。

希望能帮助到你。

于 2012-11-22T10:00:28.080 回答
0

我刚刚遇到了同样的问题,并通过使用 libstdc++ 作为 C++ 标准库来修复它。它默认为 libc++

在项目构建设置 -> APPLE LLVM 编译器 4.2 - 语言 -> C++ 标准库下

于 2013-08-17T03:14:35.210 回答