User forums > Using Code::Blocks

opencv 2.3 and codeBlocks on windows 7 64

(1/5) > >>

kukolog:
Hello

I am trying to make the most basic example of open cv to compile, but looks like something is terrible wrong.

Info about what I am using:

OS: windows ultimate 7 64

Codeblocks 10:05 installed from "codeblocks-10.05mingw-setup.exe"
into d:\develop\codeblocks

opencv2.3 installed from "OpenCV-2.3.0-win-superpack.exe"
into d:\develop\OpenCV2.3

This is the code  I am trying to compile

--- Code: ---#include "cv.h"
#include "highgui.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>

const char* cascade_name = "D:\\develop\\OpenCV2.3\\opencv\\data\\haarcascades\\haarcascade_frontalface_alt.xml";
void detect_and_draw( IplImage* image );

int main( int argc, char** argv )
{
    IplImage *img = cvLoadImage("face.jpg");
    detect_and_draw(img);
    cvWaitKey();
    cvReleaseImage(&img);
    cvDestroyWindow("result");
    return 0;
}

void detect_and_draw( IplImage* img )
{
    static CvMemStorage* storage = 0;
    static CvHaarClassifierCascade* cascade = 0;
    int scale = 1;
    IplImage* temp = cvCreateImage( cvSize(img->width/scale,img->height/scale), 8, 3 );
    CvPoint pt1, pt2;
    int i;
    cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
    if( !cascade )
    {
        fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
        return;
    }

    storage = cvCreateMemStorage(0);
    cvNamedWindow( "result", 1 );

    cvClearMemStorage( storage );
    if( cascade )
    {
        CvSeq* faces = cvHaarDetectObjects( img, cascade, storage,1.1, 2, CV_HAAR_DO_CANNY_PRUNING,cvSize(40, 40) );
        for( i = 0; i < (faces ? faces->total : 0); i++ )
        {
            CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
            pt1.x = r->x*scale;
            pt2.x = (r->x+r->width)*scale;
            pt1.y = r->y*scale;
            pt2.y = (r->y+r->height)*scale;
            cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 );
        }
    }
    cvShowImage( "result", img );
    cvReleaseImage( &temp );
}

--- End code ---

What I added into my C::B config :

into the Project Build options -> Linker settings tab , I added all Libs from D:\develop\OpenCV2.3\build\x86\mingw\lib\*.dll.a
( I tried with ...\x64\... also )

nto the Project Build options -> Search Directories , I added:
D:\develop\OpenCV2.3\build\include
D:\develop\OpenCV2.3\build\include\opencv
D:\develop\OpenCV2.3\build\include\opencv2

This cause :

--- Code: ----------------- Build: Release in opencv ---------------

Compiling: main.cpp
Linking console executable: bin\Release\opencv.exe
obj\Release\main.o:main.cpp:(.text+0x2d): undefined reference to `cvCreateImage'
obj\Release\main.o:main.cpp:(.text+0x55): undefined reference to `cvLoad'
obj\Release\main.o:main.cpp:(.text+0x6e): undefined reference to `cvCreateMemStorage'
obj\Release\main.o:main.cpp:(.text+0x87): undefined reference to `cvNamedWindow'
obj\Release\main.o:main.cpp:(.text+0x94): undefined reference to `cvClearMemStorage'
obj\Release\main.o:main.cpp:(.text+0xfa): undefined reference to `cvHaarDetectObjects'
obj\Release\main.o:main.cpp:(.text+0x12f): undefined reference to `cvGetSeqElem'
obj\Release\main.o:main.cpp:(.text+0x1c4): undefined reference to `cvRectangle'
obj\Release\main.o:main.cpp:(.text+0x1e7): undefined reference to `cvShowImage'
obj\Release\main.o:main.cpp:(.text+0x1f2): undefined reference to `cvReleaseImage'
obj\Release\main.o:main.cpp:(.text+0x256): undefined reference to `cvLoadImage'
obj\Release\main.o:main.cpp:(.text+0x26e): undefined reference to `cvWaitKey'
obj\Release\main.o:main.cpp:(.text+0x27a): undefined reference to `cvReleaseImage'
obj\Release\main.o:main.cpp:(.text+0x286): undefined reference to `cvDestroyWindow'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)

--- End code ---

Then
I added into the linker options  -lhighgui  to see what happens and I got a "cannot find -lhighthui"
I added into the linker options -lopencv_highgui "cannot find -lopencv_hightgui"

I really need some help here.

I know how to use google.
I know how to use search here , there are just a few topics on opencv here I and read all of them.

this:
http://opensourcecollection.blogspot.com/2011/04/how-to-setup-opencv-22-in-codeblocks.html  <- dont help
http://opencv.willowgarage.com/wiki/CodeBlocks <- don't help.

But
It worked with this configuration with a windowsXP Sp3, C::B 10.05 without mingw ( installed from mingw installer into c:\minGW ) and opencv 2.2
But I need that working on the w7 box

I am accepting suggestions. Lots of them. I am trying this for more than 2 weeks.

Thanks

Luis

oBFusCATed:
Read this: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_I_would_like_to_compile_a_project_using_some_non-standard_libraries._How_can_I_indicate_to_CodeBlocks_that_these_libraries_and_include_files_exist.3F
And this: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

Specifying libraries is a two step process:
1. specify the path to the lib
2. specify the name of the lib (no prefix and no extension)

If you combine 1 and 2 in one step it won't work...

paflechien:
hi,

i'm new to code::blocks, and i think i've found a great (and free!) alternative to the combo visual C++/visual assist. so far, it's a pleasure to use it.
anyway, i've been trying to compile a simple program using opencv 2.3 under windows 7 32bits, and i've installed code::blocks from "codeblocks-10.05mingw-setup.exe" in program files dir, and opencv from "OpenCV-2.3.0-win-superpack.exe" in d:\dev\. everything is set up like kukolog did. here is the code:

--- Code: ---#include <iostream>
#include "opencv/cv.h"
#include "opencv/highgui.h"

using namespace std;

int main()
{
    cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
    return 0;
}
--- End code ---
it's fairly minimal, just to be sure the project setup is ok. actually, i'm getting the following error :
undefined reference to `cvNamedWindow'

i've tried a lot of things concerning opencv previous versions, including setting libs in project build options, global settings, relative path, absolute path, and so on. nothing worked.
i think the issue might be due to the lib format (.dll.a), different from previous versions (.lib).

if anyone has a clue about a solution, you're greatly welcome :)

oBFusCATed:
As stated many times, MinGW doesn't support .lib files, it expects .a files (ar archives) and newer versions (I think) support .dll-s directly.
So the only thing you need to do is put the dlls in the search path for libraries...

ollydbg:
Mostly, you need a OpenCV 2.3 library for MinGW (Not the library for Visual C++)
If it does not exist, then you should build from OpenCV source your self. (using Cmake+mingw)

Navigation

[0] Message Index

[#] Next page

Go to full version