2

I created a new question because I've substantially the same problem as this one, but I tried to compile a C example (not C++) automatically generated with S2i Harpia, using this command:

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

Compilation fails because of this problem, so compilation completes successfully if I rename the source file with ".mm" extension. However, I installed everythin from scratch (I'm starting a new project) and it doesn't work from the beginning; instead I would want to work with the usual ".c" files.

The code I'm writing is in C -- not Objective-C and not C++ -- how can I tell the compiler to use the "old" OpenCV C interface?

EDIT: no problems with newest Ubuntu 12.04.

Community
  • 1
  • 1
Alfatau
  • 233
  • 2
  • 8

3 Answers3

0

Use the following command, it worked for me:

gcc `pkg-config --cflags opencv` opencv.c -o open_cv `pkg-config --libs opencv`
Ry-
  • 218,210
  • 55
  • 464
  • 476
Dhruv Baldawa
  • 158
  • 1
  • 10
0

I tried to use Harpia, and to compile the source code auto generated. I had the same problem. I succeed replacing gcc by g++:

g++ pkg-config --cflags opencv test.c -o test pkg-config --libs opencv

What I understand from this example is that gcc is only for C code, as g++ is for C++ code.

Ry-
  • 218,210
  • 55
  • 464
  • 476
tromera
  • 11
  • Alessandro asked for a way to tell the compiler to use a different interface for parsing C. Since you are suggesting to use a different compiler, your answer doesn't fit the question. – markusschmitz Dec 26 '11 at 18:48
  • Last line seems wrong to me too: **gcc is not only for C and g++ not only for C++**. Edit would be nice. – markusschmitz Dec 26 '11 at 18:49
0

You should put the libraries at the end of the row.

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

It took me three days of installing and reinstalling opencv and dependancies until I found out the problem is with gcc. Somehow the order of which you write stuff in the command args is important now.

EDIT: The problem is not with the old interface or not. The compiler just doesn't link properly.

Dimitar Slavchev
  • 1,597
  • 3
  • 16
  • 20