Undefined errors (C++)

Hi, I’am starting with OpenCV and installed it, but I have followed different tutorials and tried many things but my problem is I have those errors every time I call an openCV function :

undefined reference to cv::fastFree(void*)'* *undefined reference to cv::Mat::deallocate()’

I have the same problem with imread() for exemple.

The programm is really simple :
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(){
Mat image;// = imread(“image.jpg”);
cout << “Hello world!” << endl;
return 0;

For information, i’m using :

  • a protable version of codeblocks 20.03 32bit with mingw 64bit
  • tried with openCV 4.1.0 32 bits
  • tried with openCV 4.5.0 64 bits
  • tried with cmaker


Do you link it with the OpenCV lib files?

I don’t know how to do this in codeblocks, but in the build options you should have a list of linked libraries, where you should have the opencv_[something].lib (or -lopencv_[something]) files.
Note that in order to run the app, it should have access to the OpenCV DLL files.

I agree, this definitely looks like the linker wasn’t told to link the opencv libraries.

you need opencv_core450.lib (or other version) at the very least.

you need to also make sure you’ve built opencv with mingw. the official prebuilt package is for visual studio and its compiler, and it’s not compatible with mingw/gcc.

if you don’t want to build opencv yourself, you’ll have to figure out how to make codeblocks use the microsoft compiler… or find some package prebuilt for mingw.

cmake can help you build a visual studio project/solution.

or, if you have Visual Studio 2019 installed and can bear to run a command line:

  • open a command prompt
  • run "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\vc\Auxiliary\Build\vcvarsall.bat" x64 to set up the environment, so cl.exe can be found
  • (community edition has this script too, but I don’t know where)
  • run cl /EHsc /I p:\opencv\build\install\include YOURCODE.cpp /link /libpath:p:\opencv\build\install\x64\vc16\lib opencv_core450.lib opencv_highgui450.lib opencv_imgcodecs450.lib (with appropriate changes to paths)

that should also be possible if you only have VS community edition, or only MSVC without VS.

Thanks for your responses. I also think is that kind of problem but I don’t understand what I do wrong. I verified the config of my different tests and it seems good.

And the problem is I can’t use VS because it’s on a professionnal computer and I’m really really limited (it’s why I use a protable version of CodeBlocks…)

Do you see what may I forgot in the config ?

Why don’t you use cmake with codeblocks?

I tried for a few hours to use it with different versions of openCV and created CodeBlocks projects of openCV but I always have many “Mutex” errors when I try to compile it.
(ex : “Mutex in namespace std does not name a type”)

I suggest you use CodeBlocks with 32 bit MinGW compiler (the standard package) and get OpenCv 4.1 zip file from here:

…I use that myself, though from QtCreator. (64 bit compilers with CodeBlocks and the gcc world are still a bit of hassle…)

Thanks for all your responses that helped me a lot! My main problem is that I don’t have Admin rights on my professionnal computer. But I finnaly found a way to modify the PATH without rights, wich helped me to use correctly all my portbale applications (cmake, mingw…).

I made a test for my project and it works without errors!
Thanks again !! :slight_smile: