Eug*_*uge 1 macos gcc opencv clang gcc4.9
我在OS X 10.9上安装了opencv-2.4.8.2.我正在尝试编译一个简单的代码:
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
并且可以使用clang(/ usr/bin/g ++ pkg-config opencv --libs-arch x86_64 test.cpp)执行此操作,但不能使用gcc 4.9(/ usr/local/bin/g ++ pkg-config opencv --libs-arch x86_64 test.cpp).
这是我用gcc 4.9得到的:
$ /usr/local/bin/g++ `pkg-config opencv --libs` test.cpp
Undefined symbols for architecture x86_64:
"cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
_main in cc52UZjK.o
"cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
_main in cc52UZjK.o
"cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in cc52UZjK.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我找出原因吗?
有关我的编译器的信息:
$/usr/bin/gcc -v配置: - prefix =/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir =/usr/include/c ++/4.2.1 Apple LLVM版本5.1(clang-503.0.40)(基于LLVM 3.4svn)目标:x86_64-apple-darwin13.1.0线程模型:posix
$/usr/local/bin/gcc -v使用内置规范.COLLECT_GCC =/usr/local/bin/gcc COLLECT_LTO_WRAPPER =/usr/local/libexec/gcc/x86_64-apple-darwin13.0.0/4.9.0/lto-wrapper目标:x86_64-apple-darwin13.0.0配置:.. /gcc-4.9-20131215/configure --enable-languages = c ++,fortran线程模型:posix gcc版本4.9.0 20131215(实验)(GCC)
简短的回答是:你不能使用GCC在OS X 10.9及更高版本上构建C++代码,因为Apple转而使用libc ++而不是libstdc ++,而GCC与该运行时不兼容.已经进行了许多尝试来找到一种解决方法,但最终它变得不可行.
| 归档时间: |
|
| 查看次数: |
1074 次 |
| 最近记录: |