OpenCv编译和链接错误
OpenCv Compiling and Linking error
亲爱的朋友,如果我要问的问题听起来很愚蠢或很基本,请原谅我。我现在正试图使用opencv三天,我发现很难在Qt和XCODE中编译代码,昨天我很幸运,在经过许多教程之后能够获得最基本的代码之一。然而,问题是在一些书中,我发现以这种方式编写的代码示例:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main( int argc, char** argv ) {
IplImage* img = cvLoadImage( "/Users/mughery/Desktop/1_s.jpg" );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
}
上面的代码工作得很好,它现在有问题了,但是当我测试下面的代码时,我得到了很多错误。我相信它们都是c++代码,它们应该做同样的事情。
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main()
{
//read an image
cv::Mat image = cv::imread("/Users/mughery/Desktop/1_s.jpg");
//create image window named "My Image"
cv::namedWindow("My Image");
cv::imshow("My image", image);
cv::waitKey(5000);
return 1;
}
当我运行第二个代码时,它说库没有找到,书都使用相同的库,所以有什么问题可以有人帮助请。我从第二个代码收到的错误是
Ld /Users/mughery/Library/Developer/Xcode/DerivedData/Open-dvjwxosfuaihuabwnlxxuydfmyou/Build/Products/Debug/Open normal x86_64
cd /Users/mughery/Documents/ImageProgramtest/Open
export MACOSX_DEPLOYMENT_TARGET=10.9
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -L/Users/mughery/Library/Developer/Xcode/DerivedData/Open-dvjwxosfuaihuabwnlxxuydfmyou/Build/Products/Debug -L/usr/local/lib -F/Users/mughery/Library/Developer/Xcode/DerivedData/Open-dvjwxosfuaihuabwnlxxuydfmyou/Build/Products/Debug -filelist /Users/mughery/Library/Developer/Xcode/DerivedData/Open-dvjwxosfuaihuabwnlxxuydfmyou/Build/Intermediates/Open.build/Debug/Open.build/Objects-normal/x86_64/Open.LinkFileList -mmacosx-version-min=10.9 -stdlib=libstdc++ -lopencv_highgui.2.4.9 -lopencv_core.2.4.9 -Xlinker -dependency_info -Xlinker /Users/mughery/Library/Developer/Xcode/DerivedData/Open-dvjwxosfuaihuabwnlxxuydfmyou/Build/Intermediates/Open.build/Debug/Open.build/Objects-normal/x86_64/Open_dependency_info.dat -o /Users/mughery/Library/Developer/Xcode/DerivedData/Open-dvjwxosfuaihuabwnlxxuydfmyou/Build/Products/Debug/Open
Undefined symbols for architecture x86_64:
"cv::namedWindow(std::string const&, int)", referenced from:
_main in main.o
"cv::imread(std::string const&, int)", referenced from:
_main in main.o
"cv::imshow(std::string const&, cv::_InputArray const&)", referenced from:
_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)
这两种约定对于在c++代码中使用OpenCV函数都是有效的。第一个代码片段使用C函数,而第二个代码片段使用c++函数。我复制了您的错误,当您在项目的构建设置下将 c++标准库从默认的libc++ (LLVM C++ standard library)
更改为libstdc++ (GNU C++ standard library)
时,就会发生这种情况。
如果您使用libc++
,那么这两种约定都可以正常工作。由于某些原因,libstdc++
不识别新的c++函数
第一个代码是使用c库,而下面的代码使用c++库…1-确保两者都链接了适当的openv库2 -从错误代码来看,在我看来,错误来自混合32/64位库,尝试匹配它们。
相关文章:
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 使用cmake错误链接boost日志
- 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):在 Macbook 上
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- clang:错误:链接器命令失败,C++代码中的退出代码为 1(使用 -v 查看调用)
- 静态库中的 g++ 错误链接函数
- 未定义的参考错误链接天然函数Android
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- QT Q_PROPERTY错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- C 错误链接器命令失败了出口代码1(使用-V查看调用)
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- 聚输出错误 - 链接列表
- Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用)
- 尝试构建C DLIB示例无法与数百个未定义的参考错误链接