Could not compile a simple C demo program. [closed]

asked 2018-10-07 20:30:22 -0500

I installed opencv via pacman -S mingw-w64-i686-opencv in my MSYS2. Then I wrote a simple c demo program.

#include <cv.h>
#include <highgui.h>

int main() {
    IplImage* img = cvLoadImage("a4-paper.jpg");
    return 0;

I compiled it with

gcc `pkg-config --cflags opencv` -o opencv_demo opencv_demo.c `pkg-config --libs opencv`

The output was

Liu.D.H@desktop-ldh MINGW32 /c/Users/Liu.D.H/Desktop/helloC$ gcc `pkg-config --cflags opencv` -o opencv_demo opencv_demo.c `pkg-config --libs opencv`
In file included from C:/msys32/mingw32/include/opencv2/core/core_c.h:48:0,
                 from C:/msys32/mingw32/include/opencv/cv.h:63,
                 from opencv_demo.c:1:
C:/msys32/mingw32/include/opencv2/highgui/highgui_c.h:139:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 CVAPI(cv::Rect)cvGetWindowImageRect(const char* name);
opencv_demo.c: In function 'main':
opencv_demo.c:5:21: warning: implicit declaration of function 'cvLoadImage'; did you mean 'cvShowImage'? [-Wimplicit-function-declaration]
     IplImage* img = cvLoadImage("a4-paper.jpg");
opencv_demo.c:5:21: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
Liu.D.H@desktop-ldh MINGW32 /c/Users/Liu.D.H/Desktop/helloC$
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by berak
close date 2018-10-07 20:31:35.560420


opencv moved to c++ in 2010, the c-api is no more maintained, and you MUST NOT use that.

you will have to use c++ now. please have a look at the tutorials

berak gravatar imageberak ( 2018-10-07 20:32:16 -0500 )edit

Thanks for your reply.

liudonghua123 gravatar imageliudonghua123 ( 2018-10-11 04:01:39 -0500 )edit