4

i have installed minGW on my PC according to http://netbeans.org/community/releases/72/cpp-setup-instructions.html, and i have "restored defaults" using NetBeans 7.2 who has found all necessary files.

But when I made test sample C++ app i got following error:

c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find   -ladvapi32 
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lshell32 
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -luser32 
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lkernel32 
collect2: ld returned 1 exit status 
make[2]: *** [dist/Debug/MinGW-Windows/welcome_1.exe] Error 1 
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

Can anyone give me a hand with installing openCV and minGW for NetBeans?

moskito-x
  • 11,832
  • 5
  • 47
  • 60
Gligorijevic
  • 75
  • 1
  • 10
  • Well, yes they are... and i referenced them... – Gligorijevic Sep 12 '12 at 20:37
  • Ok first of all, problem i described above was solved simply by reinstalling mingw. But then I tried to work with OpenCV, using their precompiled libs, I used this tutorial: http://www.thirumal.in/2012/01/using-opencv-231-with-netbeans-7-ide.html And now i have similar problem to the problem above: c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lopencv_calib3d242.dll (and the list goes on for all .dll files i included) NOTE: i have added everything to system path that i should... – Gligorijevic Sep 13 '12 at 06:55
  • Ok, I have done so and now I got some errors concerning includes: undefined reference to `cv::imread(std::string const&, int)' What do you think I shuld change with references? – Gligorijevic Sep 13 '12 at 21:32
  • you wrote "OpenCV, using their precompiled libs" looks like you must compile OpenCV by yourself. – moskito-x Sep 13 '12 at 21:41

2 Answers2

7

How to build and use openCV with Netbeans 7.2 . Step by step

Preparations

In the "c:\mingw\bin" and "c:\mingw\lib"

  • Search and delete all libopencv*.dll , libopencv*.dll.a , libopencv*.a

Tested with the following programs

Download OpenCV-2.4.2.exe (222.9 MB) http://sourceforge.net/projects/opencvlibrary/files/
Download mingw-get-inst-20120426.exe (662.7 kB) http://sourceforge.net/projects/mingw/files/
Download cmake-2.8.9-win32-x86.zip http://www.cmake.org/files/v2.8/cmake-2.8.9-win32-x86.zip

All references used in this manual:

All references in this manual begin with "T: \". Please change to the actual drive letter! ( mostly "c:\" )

  • C:\msys\1.0\src --- (If no "msys" exists, create or use "C:\mingw\src").
  • C:\mingw\bin

Note:
I use for new projects in the msys-mingw environment always the "C:\msys\1.0\src" directory.
To have the same conditions, gcc should also be "4.7.0" not "4.6.2"

  • Put at the front of your PATH "C:\mingw\bin;C:\msys\1.0\bin;"

As you've probably noticed, you can not use the libraries that come with OpenCV-2.4.2.exe.
Ignore so the folder "...\opencv\build\x86\mingw\bin" and "...\opencv\build\x86\mingw\lib" completely.

Let's get the new mingw files.

Start mingw-get-inst-20120426.exe

Use : Download latest repository ...

enter image description here

Make sure that the specified directory is correct, usually "C:\mingw".
Check as described below.
If you also need msys, then also select "MinGW Developer Toolkit".

MinGW Install

Now MinGW-Get downloads all new files. ( 4.7.0 )

Run "OpenCV-2.4.2.exe".

The folder where the files go should be "c:\msys\1.0\src".
That writes all the files in the new directory "opencv".
The new folder : "C:\msys\1.0\src\opencv". From now on, this is our top-level directory

Open "cmake-2.8.9-win32-x86.zip" and copy the files to your cmake folder.

Creating the Makefiles

Run "C:\cmake\bin\cmake-gui.exe"

  • A: Set the required fields, click "configure"
  • B: Set, click "next" enter image description here

  • Set and click "ok" enter image description here

A possible error: sh.exe was found in your PATH

  • A: Error "sh.exe was found in your PATH"
  • B: Search for sh.exe in "C:\msys\1.0\bin" or "C:\mingw\bin" and rename to "shxx.exe"

  • click "configure" again.

enter image description here

A possible error: CMAKE_MAKE_PROGRAM is not set

  • mark "CMAKE_MAKE_PROGRAM" and copy, click "Add Entry"

enter image description here

  • Paste, Set and click "ok"
  • click "configure" again.

enter image description here

Now it should work. Cmake searches the compiler environment

enter image description here

Cmake shows the option page

  • Scroll through the red options. Don't change anything
  • click "configure" again

enter image description here

Let's generate the Makefiles

  • click "Generate"

enter image description here

Building openCV

  • Run "cmd" go to the directory "C:\msys\1.0\src\opencv\build\mingw". There typing "make"

enter image description here

Please wait!

It takes about 4 hours on my computer

enter image description here

Check that all files are in the right place

  • B: *.dll in "C:\msys\1.0\src\opencv\build\mingw\bin"
  • C: *.dll.a in "C:\msys\1.0\src\opencv\build\mingw\lib"

enter image description here

Building an opencv program

  • create a new folder "OpenCV-MakeC" in "C:\msys\1.0\src\opencv"
  • create in the folder "OpenCV-MakeC" a "Makefile" and "imgdisplay.cpp".

To avoid copy and paste error. Here are the 2 files for download:

enter image description here

Makefile

MKDIR_P = C:/msys/1.0/bin/mkdir -p
DESTDIRB = build/Debug
DESTDIRD = dist/Debug
LIBDIRCV = ../build/mingw/lib
CFLAGS = -O2
CXX = C:/mingw/bin/g++.exe
Applic = imgdisplay

ALL: imgdisd

imgdisd:
    $(CXX) $(CFLAGS) -c -g $(Applic).cpp -I../build/include -MMD -MP -MF $(DESTDIRB)/$(Applic).o.d -o $(DESTDIRB)/$(Applic).o
    $(CXX) $(CFLAGS) -o $(DESTDIRD)/$(Applic) $(DESTDIRB)/$(Applic).o -L../build/mingw/bin $(LIBDIRCV)/libopencv_calib3d242.dll.a $(LIBDIRCV)/libopencv_contrib242.dll.a $(LIBDIRCV)/libopencv_core242.dll.a \
    $(LIBDIRCV)/libopencv_features2d242.dll.a $(LIBDIRCV)/libopencv_flann242.dll.a $(LIBDIRCV)/libopencv_gpu242.dll.a $(LIBDIRCV)/libopencv_highgui242.dll.a $(LIBDIRCV)/libopencv_imgproc242.dll.a \
    $(LIBDIRCV)/libopencv_legacy242.dll.a $(LIBDIRCV)/libopencv_ml242.dll.a $(LIBDIRCV)/libopencv_nonfree242.dll.a $(LIBDIRCV)/libopencv_objdetect242.dll.a $(LIBDIRCV)/libopencv_photo242.dll.a \
    $(LIBDIRCV)/libopencv_stitching242.dll.a $(LIBDIRCV)/libopencv_ts242.a $(LIBDIRCV)/libopencv_video242.dll.a $(LIBDIRCV)/libopencv_videostab242.dll.a 
md:
    $(MKDIR_P) "$(DESTDIRB)"
    $(MKDIR_P) "$(DESTDIRD)"

imgdisplay.cpp

/* 
 * File:   imgdisplay.cpp
 * Author: Administrator
 *
 * Created on 14. September 2012, 01:12
 */

#include <cstdlib>
#include <opencv/cv.h>
#include <opencv/highgui.h>

using namespace std;

int main( int argc, char* argv[] ) 
{

    cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
    cvMoveWindow("mainWin", 100, 100);
    IplImage* img;
    img = cvLoadImage("D:/grafik/Lightroom/light01.jpg");
    if (!img) {
        std::cout << "Could not open the image file" << std::endl;
        return -1;
    }
    cvShowImage("My Picture", img); 
    cvWaitKey(0);
    cvReleaseImage(&img);
    return 0;
}

Netbeans 7.2 create a project

  • File -- New Project

enter image description here

Use settings as described below.

enter image description here

Created Project

enter image description here

Create a new target

  • Click with the right mouse button on "Makefile"

Note: If you get an error : Makefile:12: *** missing separator. Stop.

Mostly a copy and paste error ! (Make sure no spaces at the start lines. But 2 tab set).

enter image description here

Create new folder

  • Click with the right mouse button on "Makefile"
  • Use the new target "md"

enter image description here

The projects folder now looks like ..

enter image description here

Build the project

enter image description here

Debug the project

  • Copy needed dll's ( C:\msys\1.0\src\opencv\build\mingw\bin to T:\msys\1.0\src\opencv\OpenCV-MakeC\dist\Debug)

enter image description here

  • Open imgdisplay.cpp (double click)
  • Set breakpoint Line 17

    17 cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);

  • Click the Debug button

enter image description here

Program stops on Line 17

enter image description here

Unresolved Identifier

If the source of the .cpp file looks like this

enter image description here

Click with the right mouse button on your project.
Check C/C++ Code As...
Run Reparse Project.

enter image description here

If that is not enough.
Go to Project Properties
Fill in the Include input field as described.

enter image description here

Clean Up

  • If you renamed sh.exe to shxx.exe ! Rename it back !
  • If you have spaces in your PATH Variable, put quotation marks around spaces (only around relevant programs like visual studio and so).
    I know that they are not necessary but one or two programs can't handle the spaces
    in the PATH !!
  • On a
moskito-x
  • 11,832
  • 5
  • 47
  • 60
  • OK, I have tried this and got following error during building in CMake: CUDA_TOOLKIT_ROOT_DIR not found or specified Also i dont hame make.exe in my c:\mingw\bin folder at all! – Gligorijevic Sep 25 '12 at 12:15
  • no no what you did. It looks like you have done a "dir *.*" ! Type PATH and hit enter. THE OUTPUT must look like `PATH=c:\mingw\bin;c:\msys\1.0\bin;....` and so on! – moskito-x Sep 25 '12 at 18:39
  • Oh, i misunderstood you, sorry. I have c:\mingw\bin; C:\msys\1.0\bin; Paths work fine... – Gligorijevic Sep 25 '12 at 18:57
  • Go to the directory "C:\msys\1.0\src\opencv\build\mingw". Open cmd . Controlling whether the Command Prompt is `C:\msys\1.0\src\opencv\build\mingw>` and there typing `make` and hit enter. In my answer look at chapter **Building openCV** – moskito-x Sep 25 '12 at 20:55
  • I am doing that all the time, there is the problem when i do command cd C:\msys\1.0\src\opencv\build\mingw>, and after that i just type make i get: Microsoft Windows [Version 6.1.7601] and next line is copyright note... thats only output that i'm getting, there is no building whatsoever... (and i am using cmd as administrator) – Gligorijevic Sep 25 '12 at 21:23
  • I don't know how can he find the wrong make.exe since there is no make.exe in mingw\bin... only in msys\1.0\bin... and I think the problem lies there... And to answer to your question there is "Makefile" type "File"... from it i copied the code in question. :/ (I guess that's the file i call when i use make command but nothing happens) – Gligorijevic Sep 25 '12 at 22:11
  • You wrote `and after that i just type make i get: Microsoft Windows [Version 6.1.7601] and next line is copyright note...` Can you make a sreenshot and put the image to your question ? – moskito-x Sep 25 '12 at 22:24
  • I tried it before, I have copied it to mingw\bin and them tried with no luck, then i added entry CMAKE_MAKE_PROGRAM and referenced to mingw\bin\make.exe and still didn't work, then referenced it with just make.exe and didn't work... The File Makefile is "Makefile" (no capital F, was typing error before)... I'm kinda out of ideas :S – Gligorijevic Sep 25 '12 at 22:27
  • Please, you have so many changes made they are all different from the manual in my answer. Do everything as described in the tutorial. Have you now GNU 4.7.0 ? And make a screenshot of the output in cmd-window after the make command. – moskito-x Sep 25 '12 at 22:37
  • I have done everything according to your tutorial, and every number appears to be right, i can't find any difference (and i tried your tutorial couple of times), i can't post images so take look at this link: http://i50.tinypic.com/2w2is1e.png – Gligorijevic Sep 25 '12 at 22:42
  • I tried and I still got the same output. Size of Makefile file is 87kb. – Gligorijevic Sep 25 '12 at 23:10
  • Our Makefile files are completely same!!!! I checked it via diffchecker.com... I am totally confused. – Gligorijevic Sep 25 '12 at 23:55
  • They can not be completely the same !! In My Makefile there are lines pointing to CMake folder `C:\cmake\bin\cmake.exe` and in your Makefile pointing to `C:\Program Files (x86)\cmake-2.8.9-win32-x86\bin\cmake.exe` HOW CAN THIS BE THE SAME ??? – moskito-x Sep 26 '12 at 00:06
  • cmake.exe is what is important, besides only difference is where we put CMake folder on filesystem, can it be that that is the problem? I seriously doubt that. And all other lines are same, only i have 2 lines more than you considering python.. and one is echo @python, or something like that... It cannot possibly be the bug.. – Gligorijevic Sep 26 '12 at 00:24
  • Create the Directory `C:\cmake` copy your folders bin, doc, man and share from your `cmake-2.8.9-win32-x86` to that. Rename your Makefile to Makefile.bak . Create a new Makefile, copy the content from my Makefile into the just created. Run `make` . – moskito-x Sep 26 '12 at 00:38
  • I have tried that too , no go. I think it has something to do with Windows adjusments.. here is my entire path variable, take a look, you may see something i don't : [path](http://pastebin.com/uMGvbuDU) – Gligorijevic Sep 26 '12 at 00:56
  • Ordering in path seems to have nothing to do with it, i put those two at start of path variable, saved to registry, restarted PC and still cant run ´make´ ... – Gligorijevic Sep 26 '12 at 01:32
  • 1
    First now that we change the PATH Variable. You must run Cmake-gui.exe again. Don't forget to go to File .. Delete Cache first. Run Configure again and again until there are no red fields. Then Run `Generate`. Only If that does not work Rename both `make.exe` to `make-orig.exe` in both folder `C:\mingw\bin` and `C:\msys\1.0\bin` Download http://www.moskito-x.de/stack/files/make.exe and copy it to both folder. Run `make` – moskito-x Sep 26 '12 at 01:45
  • OK, it builds now that I use your make.exe!!!! Only thing is, my msys is broken somehow... and it didn't updated it with mingwget... and on sourceforge its kinda hard to find right instalation.. (note that i have checked MinGW developer toolkit) – Gligorijevic Sep 26 '12 at 08:30
  • Ok good thing is I am at a final step: but when I go right click om Makefile and go to `Make target -> md` i get following error: `Makefile:12: *** missing separator. Stop. MAKE FAILED (exit value 2, total time: 153ms) ` – Gligorijevic Sep 26 '12 at 09:40
  • 1
    Looks like a "Copy and Paste" error. Only rename `Makefile.zip` to `Makefile` after Download! http://moskito-x.de/stack/files/Makefile.zip and put it in the Project folder. – moskito-x Sep 26 '12 at 19:32
  • 1
    JESUS, that actually worked!! NetBeans shows a lot of error but still it works, its great. I will try with setting parameters on NetBeans with newly compiled libs. but anyway it's so great to make it run finally! And moskito-x, thank you so much for your patience and help, and especially for this great answer above (although I even had bad luck going through it)... You have been most helpful!! – Gligorijevic Sep 26 '12 at 20:57
  • `All good things are worth waiting for`. Please can you make a screenshot of the errors and give me a link to the image! Now let's put out not useful comments. 35 comments a really to much ;-) – moskito-x Sep 26 '12 at 21:34
  • Here it is [picture](http://i49.tinypic.com/p54rm.png) , I believe it's because no properties have been set in NetBeans, ill try to make cpp project in NetBeans and work with its properties, ill post aditional answer if I'm lucky. – Gligorijevic Sep 26 '12 at 22:36
  • Great, I have done that already. But i got some weird bug with including `cstdlib` and resolving identifier `std`. I came up with the same issue working on Visual Studio 2010 form time to time, here is [screenshot](http://i46.tinypic.com/99ffhh.png), and if you had any experience with this too it would be great to share.. :) – Gligorijevic Sep 27 '12 at 08:32
  • 1
    Put also `;C:/mingw/lib/gcc/mingw32/4.7.0/include/c++` to the Code Assistance..C++ Compiler..Include Directories after `;../build/include` – moskito-x Sep 27 '12 at 22:31
  • Am, when I try to make a new project no matter using wizard in NetBeans or doing it your way i get same error: `C:/msys/1.0/bin/mkdir -p "build/Debug" 0 [main] us 0 init_cheap: VirtualAlloc pointer is null, Win32 error 487 AllocationBase 0x0, BaseAddress 0x71110000, RegionSize 0x4C0000, State 0x10000 C:\msys\1.0\bin\sh.exe: *** Couldn't reserve space for cygwin's heap, Win32 error 0 make: *** [md] Error 1 MAKE FAILED (exit value 2, total time: 212ms)` This is so weird, i havent touched anything since last time i builded it! – Gligorijevic Oct 01 '12 at 12:10
  • As we have already noted, the "msys" environment is wrong. We exchanged make.exe. This is no permanent solution. Install the win32 version of msys new. Be careful not to delete the src directory. – moskito-x Oct 01 '12 at 14:17
2

It happened to me too but instead of using make I used mingw32-make, then it worked.

You can install mingw32-make using mingw-get install mingw32-make

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
sujit
  • 21
  • 1