OpenCV架构x86_64的未定义符号:错误 [英] OpenCV Undefined symbols for architecture x86_64: error
问题描述
在此标记为重复问题之前,请阅读结束。感谢您查找。
我使用home-brew设置了openCV。
这些是我使用的命令:
brew tap homebrew / science
brew install opencv
我使用以下简单文件在线查找设置:
//显示如何读写图像的示例
#include< opencv2 / opencv.hpp> ;
#include< opencv2 / highgui / highgui.hpp>
using namespace cv;
int main(int argc,char ** argv)
{
//从文件加载图像 - 根据您的图像名称更改此图像
Mat img = imread(my_image.jpg,CV_LOAD_IMAGE_UNCHANGED);
if(img.empty())
{
fprintf(stderr,无法加载输入image\\\
);
return -1;
}
//这只是为了显示,你不必预先分配
//结果图像与c ++任何更多..
垫灰色;
cvtColor(img,gray,CV_BGR2GRAY);
//图像写入到一个不同的名称,
文件//使用不同的图像格式 - png格式,而不是.JPG
如果(imwrite(! my_image_copy.png,img))
{
fprintf(stderr,未能写入图像文件\\\
);
}
//不需要使用c ++释放任何东西!
return 0;
}
这是我在编译并运行suing后得到的错误 g ++ test.cpp -o test
。
架构x86_64的未定义符号:
cv :: _ InputArray :: _ InputArray(cv :: Mat const&) ,引用自:
_main in test-41a30e.o
cv :: namedWindow(std :: __ 1 :: basic_string< char,std :: __ 1 :: char_traits< char>,std :: __1 ::分配器<焦炭>>常量和放大器;,INT),从引用:在测试41a30e.o
_mainCV ::的DestroyWindow(STD :: __ 1 :: basic_string的<焦炭, std :: __ 1 :: char_traits< char>,std :: __ 1 :: allocator< char>> const&),引用自:
_main in test-41a30e.o
cv :: Mat :: deallocate(),引用自:
cv :: Mat :: release()in test-41a30e.o
cv :: imread(std :: __ 1 :: basic_string& std :: __ 1 :: char_traits< char> ;, std :: __ 1 :: allocator< char>> const& int),引用自:
_main in test-41a30e.o
cv :: imshow(STD :: __ 1 :: basic_string的<焦炭,性病:: __ 1 :: char_traits<焦炭>中的std :: __ 1 ::分配器<焦炭>>常量和放大器;,CV :: _ InputArray常量和放大器;),引用从:
_main in test-41a30e.o
cv :: waitKey(int),引用自:
_main in test-41a30e.o
cv :: fastFree (void *),引用自:
cv :: Mat ::〜Mat()in test-41a30e.o
ld:没有为架构找到符号x86_64
clang:错误:链接器命令失败,退出代码1(使用-v查看调用)
在堆栈溢出和问题,但使用自制的无我不知道怎么的敏感时间(与问候更新和更改OpenCV的,我的操作系统等)的问题。我使用与10.9.4操作系统的mac。这些答案也不是真的清楚我应该改变什么。许多人只是建议一行代码,而不说行在哪里。我非常新手这些技术。任何帮助将是非常感谢!
编辑:
Mark Setchell帮助第一批错误。但我现在得到:
g ++ $(pkg-config --cflags --libs opencv)test.cpp -o测试& ./Test
[3] 7187
dyld:未加载库:lib / libopencv_calib3d.2.4.dylib
引用自:/ usr / local /Cellar/opencv/2.4.9/include/./Test
原因:没有找到图片
[2]完成G ++ $(pkg配置--cflags --libs OpenCV的)TEST.CPP -o测试
跟踪/ BPT陷阱:5
brewdoctor给了我这个警告:
警告:你的地窖里有没有连接的桶
断开连接的桶可能导致构建故障并导致依赖于
的brew,这些桶一旦构建就无法正常运行。在这些上运行 brew link
:
opencv
所以我运行brew链接--overwrite opencv但得到了:
链接/usr/local/Cellar/opencv/2.4.9 ...
错误:无法符号链接include / opencv / cv.h
需要重写,因为brew link opencv赋予
链接/usr/local/Cellar/opencv/2.4.9 ...
错误:无法符号链接包含/ opencv / cv.h
目标/ usr / local / include / opencv / cv .h
已存在。您可能要删除它:
rm /usr/local/include/opencv/cv.h
解决方案您收到链接器错误。我认为这是因为你没有链接到 opencv
需要的正确的库。
正确的库是 pkg-config
,所以我建议:
brew install pkg-config
然后您可能需要重新安装opencv
brew重新安装opencv
brew卸载opencv
brew install opencv
那么你应该能够:
g ++ $(pkg- config --cflags --libs opencv)test.cpp -o Test
>
pkg-config --cflags --libs opencv
要看看它输出的 G ++
编译器,如果你有兴趣 - 它告诉编译器所在的库和头文件。在我的系统上,它输出:
pkg-config --cflags --libs opencv
-I / usr / local / Cellar / opencv / 2.4.12_2 / include / opencv \
-I / usr / local / Cellar / opencv / 2.4.12_2 / include \
-L / usr /local/Cellar/opencv/2.4.12_2/lib \
-lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab
如果您不熟悉 pkgconfig
,你可以要求它告诉你所有它知道的包,像这样:
pkg-config - list-all
我的系统给出如下输出:
$ b b libzmq libzmq - 0MQ C ++库
GIO-UNIX的2.0 GIO UNIX特定的API - 为油腔滑调UNIX特定的头文件I / O库
glibmm-2.4 glibmm - GLib的C ++包装
libpostproc libpostproc - FFmpeg后处理库
libgsf-1 libgsf-1 - 用于读取和写入结构化文件(例如MS OLE和Zip)的库
gobject-introspection-no -export-1.0 gobject-introspection - GObject内省
libtasn1 libtasn1 - 用于ASN.1和DER操作的库
libusb-1.0 libusb-1.0 - 用于从Linux,Mac OS X,Windows和OpenBSD / NetBSD用户空间
gio-2.0 GIO - glib I / O库
libusb libusb - USB访问库(libusb-1.0 compat包装)
libecpg_compat libecpg_compat - PostgreSQL libecpg_compat库
QtNetwork Qtnetwork - Qtnetwork库
opencv OpenCV - 开源计算机视觉库
基本上,上面列表中每一行的名称都告诉你这些包的名称 pkgconfig
知道,这是运行命令时应该指定的名称,例如
pkg-config --cflags --libs opencv
如果你的系统有点乱,你可以找到 .pc
文件 pkgconfig
使用像这样:
find / usr / local / Cellar -name \ * .pc
或
find / usr / local / Cellar -name \ * .pc | grep -i opencv
/usr/local/Cellar/opencv3/3.1.0_3/lib/pkgconfig/opencv.pc
然后直接使用配置文件,如下:
pkg-config - -cflags --libs /usr/local/Cellar/opencv3/3.1.0_3/lib/pkgconfig/opencv.pc
如果所有编译都正确,您可以使用
./ Test
before this gets flagged as a repeat question please read the end. Thanks for looking.
I set up openCV using home-brew.
These were the commands I used:
brew tap homebrew/science
brew install opencv
I am using the following simple file I found online to test my set up:
// Example showing how to read and write images
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char** argv)
{
// Load an image from file - change this based on your image name
Mat img = imread("my_image.jpg", CV_LOAD_IMAGE_UNCHANGED);
if(img.empty())
{
fprintf(stderr, "failed to load input image\n");
return -1;
}
// this is just to show, that you won't have to pre-alloc
// result-images with c++ any more..
Mat gray;
cvtColor(img,gray,CV_BGR2GRAY);
// Write the image to a file with a different name,
// using a different image format -- .png instead of .jpg
if( ! imwrite("my_image_copy.png", img) )
{
fprintf(stderr, "failed to write image file\n");
}
// no need to release anything with c++ !
return 0;
}
This is the error I am getting after trying to compile and run suing g++ test.cpp -o test
.
Undefined symbols for architecture x86_64:
"cv::_InputArray::_InputArray(cv::Mat const&)", referenced from:
_main in test-41a30e.o
"cv::namedWindow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
_main in test-41a30e.o
"cv::destroyWindow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in test-41a30e.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in test-41a30e.o
"cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
_main in test-41a30e.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 test-41a30e.o
"cv::waitKey(int)", referenced from:
_main in test-41a30e.o
"cv::fastFree(void*)", referenced from:
cv::Mat::~Mat() in test-41a30e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I did find similar issues on stack overflow but none using homebrew and I'm not sure how time- sensitive (with regards to updates and changes to OpenCV, my OS etc) the problem is. I'm using a mac with the 10.9.4 OS. Also those answers weren't really clear to me what should be changed. Many just suggested one line of code without saying where the line should go. I'm extremely novice with these technologies. Any help would be great thanks!
Edit:
Mark Setchell helped with the first batch of errors. But I am now getting:
g++ $(pkg-config --cflags --libs opencv) test.cpp -o Test & ./Test
[3] 7187
dyld: Library not loaded: lib/libopencv_calib3d.2.4.dylib
Referenced from: /usr/local/Cellar/opencv/2.4.9/include/./Test
Reason: image not found
[2] Done g++ $(pkg-config --cflags --libs opencv) test.cpp -o Test
Trace/BPT trap: 5
brewdoctor gave me this warning:
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run brew link
on these:
opencv
So I ran brew link --overwrite opencv but got this:
Linking /usr/local/Cellar/opencv/2.4.9...
Error: Could not symlink include/opencv/cv.h
needed the overwrite because brew link opencv gave
Linking /usr/local/Cellar/opencv/2.4.9...
Error: Could not symlink include/opencv/cv.h
Target /usr/local/include/opencv/cv.h
already exists. You may want to remove it:
rm /usr/local/include/opencv/cv.h
解决方案 You are getting linker errors. I think that is because you are not linking with the correct libraries that opencv
requires.
The easiest way to get the correct libraries is with pkg-config
, so I would recommend:
brew install pkg-config
Then you may have to reinstall opencv
brew reinstall opencv
or maybe
brew uninstall opencv
brew install opencv
Then you should be able to do:
g++ $(pkg-config --cflags --libs opencv) test.cpp -o Test
You can run
pkg-config --cflags --libs opencv
to see what it outputs for the g++
compiler if you are interested - it tells the compiler where the libraries and header files are. On my system, it outputs this:
pkg-config --cflags --libs opencv
-I/usr/local/Cellar/opencv/2.4.12_2/include/opencv \
-I/usr/local/Cellar/opencv/2.4.12_2/include \
-L/usr/local/Cellar/opencv/2.4.12_2/lib \
-lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab
If you are unfamiliar with pkgconfig
, you can ask it to tell you all the packages it knows about like this:
pkg-config --list-all
My system gives output like this:
libzmq libzmq - 0MQ c++ library
gio-unix-2.0 GIO unix specific APIs - unix specific headers for glib I/O library
glibmm-2.4 glibmm - C++ wrapper for GLib
libpostproc libpostproc - FFmpeg postprocessing library
libgsf-1 libgsf-1 - A library for reading and writing structured files (eg MS OLE and Zip)
gobject-introspection-no-export-1.0 gobject-introspection - GObject Introspection
libtasn1 libtasn1 - Library for ASN.1 and DER manipulation
libusb-1.0 libusb-1.0 - C API for USB device access from Linux, Mac OS X, Windows and OpenBSD/NetBSD userspace
gio-2.0 GIO - glib I/O library
libusb libusb - USB access library (libusb-1.0 compat wrapper)
libecpg_compat libecpg_compat - PostgreSQL libecpg_compat library
QtNetwork Qtnetwork - Qtnetwork Library
opencv OpenCV - Open Source Computer Vision Library
Basically, the first word in each line of the list above tells you the names of the packages pkgconfig
knows about and that is the name you should specify when running commands such as
pkg-config --cflags --libs opencv
If your system is a bit messed up, you can find the .pc
file that pkgconfig
uses like this:
find /usr/local/Cellar -name \*.pc
or
find /usr/local/Cellar -name \*.pc | grep -i opencv
/usr/local/Cellar/opencv3/3.1.0_3/lib/pkgconfig/opencv.pc
And then use the config file directly, like this:
pkg-config --cflags --libs /usr/local/Cellar/opencv3/3.1.0_3/lib/pkgconfig/opencv.pc
If it all compiles correctly, you can run it with
./Test
这篇关于OpenCV架构x86_64的未定义符号:错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!