C++ g++ ld:找不到架构 x86_64 的符号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19821041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:10:31  来源:igfitidea点击:

g++ ld: symbol(s) not found for architecture x86_64

c++opencvgcc

提问by mbPro

I'm trying to compile the Sam Hare's Struck code.

我正在尝试编译 Sam Hare 的Struck 代码

I'm using mac OSX10.9, opencv 2.4.6 and Eigen 2.0.17.

我使用的是 mac OSX10.9、opencv 2.4.6 和 Eigen 2.0.17。

Eigen and opencv headers are stored in /opt/local/include while opencv dylib in /opt/local/lib.

Eigen 和 opencv 标头存储在 /opt/local/include 中,而 opencv dylib 存储在 /opt/local/lib 中。

I modified the Hare's Makefile to work on this folder. When I type make on the terminal:

我修改了 Hare 的 Makefile 来处理这个文件夹。当我在终端上输入 make 时:

g++ -L/opt/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc src/Config.o src/Features.o src/HaarFeature.o src/HaarFeatures.o src/HistogramFeatures.o src/ImageRep.o src/LaRank.o src/MultiFeatures.o src/RawFeatures.o src/Sampler.o src/Tracker.o src/main.o src/GraphUtils/GraphUtils.o -o struck

I get these errors:

我收到这些错误:

Undefined symbols for architecture x86_64:  
"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::split(cv::Mat const&, std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >&)",
referenced from:
      ImageRep::ImageRep(cv::Mat const&, bool, bool, bool) in ImageRep.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:
      LaRank::Debug() in LaRank.o
      Tracker::Debug() in Tracker.o
      _main 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)

Any ideas? Thanks!

有任何想法吗?谢谢!

回答by Nate

I had a similar warning/error/failure when I was simply trying to make an executable from two different object files (main.o and add.o). I was using the command:

当我只是尝试从两个不同的目标文件(main.o 和 add.o)创建可执行文件时,我遇到了类似的警告/错误/失败。我正在使用命令:

gcc -o exec main.o add.o

gcc -o exec main.o add.o

But my program is a C++ program. Using the g++compiler solved my issue:

但我的程序是一个 C++ 程序。使用g++编译器解决了我的问题:

g++ -o exec main.o add.o

g++ -o exec main.o add.o

I was always under the impression that gcccould figure these things out on its own. Apparently not. I hope this helps someone else searching for this error.

我一直觉得自己gcc可以解决这些问题。显然不是。我希望这有助于其他人搜索此错误。

回答by mbPro

finally solved my problem.

终于解决了我的问题。

I created a new project in XCode with the sources and changed the C++ Standard Library from the default libc++ to libstdc++ as in thisand this.

我使用源代码在 XCode 中创建了一个新项目,并将 C++ 标准库从默认的 libc++ 更改为 libstdc++,如thisthis