# Undefined errors (C++)

**URL:** <https://forum.opencv.org/t/undefined-errors-c/884>\
**Category:** Uncategorized\
**Created:** [January 15, 2021, 2:45pm UTC](https://forum.opencv.org/t/undefined-errors-c/884 "2021-01-15T14:45:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jojo666](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@jojo666](https://forum.opencv.org/u/jojo666)\
**Post date:** [January 15, 2021, 2:45pm UTC](https://forum.opencv.org/t/undefined-errors-c/884/1 "2021-01-15T14:45:39Z")

</div>

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   
#include   
#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

Thanks

---

<div class="post-metadata">

**Author:** ![kbarni](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/kbarni/32/26_2.png) [@kbarni](https://forum.opencv.org/u/kbarni)\
**Post date:** [January 15, 2021, 3:12pm UTC](https://forum.opencv.org/t/undefined-errors-c/884/2 "2021-01-15T15:12:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [January 15, 2021, 3:59pm UTC](https://forum.opencv.org/t/undefined-errors-c/884/3 "2021-01-15T15:59:36Z")

</div>

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](http://forums.codeblocks.org/index.php?topic=23635.0)… 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.

---

<div class="post-metadata">

**Author:** ![jojo666](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@jojo666](https://forum.opencv.org/u/jojo666)\
**Post date:** [January 16, 2021, 10:32am UTC](https://forum.opencv.org/t/undefined-errors-c/884/4 "2021-01-16T10:32:41Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/1X/bc971381cd4e6f8455b70031a329c8d58961ac1c.png)

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 ?

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [January 16, 2021, 11:01am UTC](https://forum.opencv.org/t/undefined-errors-c/884/5 "2021-01-16T11:01:49Z")

</div>

Why don’t you use [cmake with codeblocks](https://cmake.org/cmake/help/latest/generator/CodeBlocks.html)?

---

<div class="post-metadata">

**Author:** ![jojo666](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@jojo666](https://forum.opencv.org/u/jojo666)\
**Post date:** [January 16, 2021, 2:07pm UTC](https://forum.opencv.org/t/undefined-errors-c/884/6 "2021-01-16T14:07:20Z")

</div>

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”)

---

<div class="post-metadata">

**Author:** ![matti.vuori](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@matti.vuori](https://forum.opencv.org/u/matti.vuori)\
**Post date:** [January 16, 2021, 8:26pm UTC](https://forum.opencv.org/t/undefined-errors-c/884/7 "2021-01-16T20:26:50Z")

</div>

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

> **[huihut/OpenCV-MinGW-Build](https://github.com/huihut/OpenCV-MinGW-Build)**
>
> 👀 MinGW 32bit and 64bit version of OpenCV compiled on Windows. Including OpenCV 3.3.1, 3.4.1, 3.4.1-x64, 3.4.5, 3.4.6, 3.4.7, 3.4.8-x64, 3.4.9, 4.0.0-alpha-x64, 4.0.0-rc-x64, 4.0.1-x64, 4.1.0, 4.1....

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

---

<div class="post-metadata">

**Author:** ![jojo666](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@jojo666](https://forum.opencv.org/u/jojo666)\
**Post date:** [January 19, 2021, 2:22pm UTC](https://forum.opencv.org/t/undefined-errors-c/884/8 "2021-01-19T14:22:33Z")

</div>

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 !! 🙂
