Ask Your Question

Undefined symbols for architecture x86_64 [MACOS with Terminal]

asked 2019-10-01 03:32:18 -0500

Nyamkhuub gravatar image

updated 2019-10-01 03:37:08 -0500

berak gravatar image

Hello developers, I want to compile my C++ code in the terminal. But I have some errors looks like that:

Undefined symbols for architecture x86_64: "cv::Mat::deallocate()", referenced from: cv::Mat::release() in main-9ae616.o "cv::imread(std::__1::basic_string<char, std::__1::char_traits,="" std::__1::allocator="" &gt;="" const&amp;,="" int)",="" referenced="" from:="" _main="" in="" main-9ae616.o="" "cv::imshow(std::__1::basic_string<char,="" std::__1::char_traits,="" std::__1::allocator="" &gt;="" const&amp;,="" cv::_inputarray="" const&amp;)",="" referenced="" from:="" _main="" in="" main-9ae616.o="" "cv::waitkey(int)",="" referenced="" from:="" _main="" in="" main-9ae616.o="" "cv::fastfree(void*)",="" referenced="" from:="" cv::mat::~mat()="" in="" main-9ae616.o="" ld:="" symbol(s)="" not="" found="" for="" architecture="" x86_64="" clang:="" error:="" linker="" command="" failed="" with="" exit="" code="" 1="" (use="" -v="" to="" see="" invocation)<="" p="">

My command:

g++ -std=c++11 -o out main.cpp

How to solve this issue? help me, please?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-10-01 03:44:42 -0500

berak gravatar image

updated 2019-10-01 03:48:36 -0500

How to solve this issue?

you have to LINK the opencv libraries to your program, like:

g++ -std=c++11 -o out main.cpp -lopencv_core -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui

for opencv4, you also need to correct the INCLUDE path:

g++ -std=c++11 -I/usr/local/include/opencv4 -o out main.cpp -lopencv_core -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui

in general, there is a library file to link for each module you include in your code, e.g.

#include "opencv2/face.hpp"

would require an additional:


on your cmdline

edit flag offensive delete link more


Thanks, man! your commands working for me!

Nyamkhuub gravatar imageNyamkhuub ( 2019-10-01 03:50:25 -0500 )edit

@berak If I want to use opencv2/opencv.hpp, which library should add to command?

Nyamkhuub gravatar imageNyamkhuub ( 2019-10-02 06:46:14 -0500 )edit

hehe, unfortunately, opencv2/opencv.hpp is an "umbrella header" containing (almost) all other opencv headers, so, hmm -- everything you have ?

berak gravatar imageberak ( 2019-10-02 06:49:23 -0500 )edit

@berak, My fault I am a beginner on OpenCV. Perhaps, I get some mistake while installing :D

Nyamkhuub gravatar imageNyamkhuub ( 2019-10-03 01:18:15 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-10-01 03:32:18 -0500

Seen: 994 times

Last updated: Oct 01 '19