NetBeans 7.2 MinGW installing for OpenCV

2019-01-12 05:19发布

问题:

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?

回答1:

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 ...

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".

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"

  • Set and click "ok"

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.

A possible error: CMAKE_MAKE_PROGRAM is not set

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

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

Now it should work. Cmake searches the compiler environment

Cmake shows the option page

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

Let's generate the Makefiles

  • click "Generate"

Building openCV

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

Please wait!

It takes about 4 hours on my computer

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"

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:

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

Use settings as described below.

Created Project

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

Create new folder

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

The projects folder now looks like ..

Build the project

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)

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

    17 cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);

  • Click the Debug button

Program stops on Line 17

Unresolved Identifier

If the source of the .cpp file looks like this

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

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

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


回答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