Configuring OpenCV in QT on OSX

I am trying to configure OpenCV to work with QT on OSX 10.7.5 / MacbookPro 2.5 GHz Intel Core 2 Duo. I saw some related questions here ( How to link opencv in QtCreator and use the Qt library and How do you configure OpenCV with QT in OSX? ), But not so many details. On the QT website and in my web searches, all the information seems to be related to Windows or Linux.


I have listed my installation and code below. When I run the code, I get the error message:: :-1: error: symbol(s) not found for architecture x86_64

Does this mean that he does not find things because the paths are wrong or because I may have created openCV for x86_32? Is there any way to check the latter? I do not know much about the details of the setup and configuration process.


Update 2

The console output is lower - perhaps the error is obvious?

 02:44:38: Running steps for project RP_openCV_01... 02:44:38: Configuration unchanged, skipping qmake step. 02:44:38: Starting: "/usr/bin/make" clang++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o RP_openCV_01 main.o -L/usr/local/lib -1ibopencv_core.2.4.6,dylib -1ibopencv_imgproc.2.4.6.dylib -F/Users/rise/Qt5.0.2/5.0.2/clang_64/lib -framework QtCore clang: warning: argument unused during compilation: '-1ibopencv_core.2.4.6,dylib' clang: warning: argument unused during compilation: '-1ibopencv_imgproc.2.4.6.dylib' Undefined symbols for architecture x86_64: "cv::_InputArray::_InputArray(cv::Mat const&)", referenced from: _main in main.o "cv::namedWindow(std::string const&, int)", referenced from: _main in main.o "cv::Mat::deallocate()", 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 "cv::waitKey(int)", referenced from: _main in main.o "cv::fastFree(void*)", 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) make: *** [RP_openCV_01] Error 1 02:44:38: The process "/usr/bin/make" exited with code 2. Error while building/deploying project RP_openCV_01 (kit: Desktop Qt 5.0.2 clang 64bit) When executing step 'Make' 

What I still have (tl; dr):

  • built and installed the latest version of openCV (2.4.6) from the source and tested it using some command line programs.

  • The latest version of QT (5.1) is installed, and I can run all the examples, etc.

  • paths in the project file are specified (below)

 QT += core QT -= gui TARGET = RP_openCV_01 CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp INCLUDEPATH += /usr/local/include\ LIBS += -L/usr/local/lib 
  • I tried to specify the path in the project settings (below). I added /usr/local/include and /usr/local/lib

enter image description here

Simple sample code in main.cpp

 #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> int main() { // read an image cv::Mat image= cv::imread("dog.jpg"); // create image window named "My Image" cv::namedWindow("My Image"); // show the image on window cv::imshow("My Image", image); // wait key for 5000 ms cv::waitKey(5000); return 1; } 

Update 1

Another thing I tried based on the tutorial is to specify the libraries in the QT profile (as shown in the figure below). The tutorial was for Windows, although I did not know if OSX was different. Where in the Windows example this is -1ibopencv_core246d I tried it with and without splitting periods, but without the "d". Of course, the full lib name is "libopencv_core.2.4.6.dylib", etc.

These kinds of important details always upset me, but in manuals they often mean that someone knows this stuff.

  LIBS += -L/usr/local/lib \ -1ibopencv_core.2.4.6 \ -1ibopencv_imgproc.2.4.6 \ -1ibopencv_features2d.2.4.6 \ -1ibopencv_highgui.2.4.6 

enter image description here

+6
source share
4 answers

Just a naive mistake

Own declaration:

 LIBS += -L/usr/local/lib \ -lopencv_core \ -lopencv_imgproc \ -lopencv_features2d\ -lopencv_highgui 
+6
source

I just stumbled upon the same problem. Here's how I solved it:

As sansuiso has already said, the problem is that you are trying to bind C ++ - STD-lib. You are probably trying to link libC ++ (LLVM ...), but use libstdC ++ (GNU C ++ ...) instead.

Using Qt Creator, you can add the following to your .pro file:

 mac: CONFIG += MAC_CONFIG MAC_CONFIG { QMAKE_CXXFLAGS = -std=c++11 -stdlib=libstdc++ -mmacosx-version-min=10.7 QMAKE_LFLAGS = -std=c++11 -stdlib=libstdc++ -mmacosx-version-min=10.7 } 

This answer may also be of interest to your problem: fooobar.com/questions/238444 / ...

Hope this helps!

+1
source

I have successfully installed both opencv, Qt, and PyQt through macports.

0
source

Here you are faced with two potential problems:

  • first on Mac platforms , depending on the compiler (clang or gcc), you won’t refer to the same stdC ++ library (I ran into this problem while trying to get some static opencv lib working with an iOS project). However, this does not seem to be the case, because you do not have C ++ errors, but it is worth checking which compiler you use in each case;
  • second, QtCreator - a graphical application . Thus, he does not know the settings of your terminal. This includes the path to the dynamic libraries in /usr/local . You can avoid this in many ways: using static opencv lib, using install_tool to change the path to the library encoded in the output binary format, or using the QtCreator preferences to set the DYLD_LIBRARY_PATH variable to something like /usr/local/lib when it runs your the program.
0
source

Source: https://habr.com/ru/post/948908/


All Articles