4
votes

I am building a C application that uses OpenCV.

when compiling, I get the following error:

fatal error C1189: #error :  core.hpp header must be compiled as C++

I did not find how to resolve this error.

How to use OpenCV from a C project?

2
Compiler is telling you that you cannot compile c++ source with c compiler..LPs
... But OpenCV has pure C bindings. So you need to adjust your build process to use those.StoryTeller - Unslander Monica
How to change it to c++ compiler using visual studio, I tried but I cannot.ProEns08
You have to build your OpenCV source in C , what you are using is compiled in C++ and you are using in CATul Singh
I'm not a VS expert but this is the first googled linkLPs

2 Answers

3
votes
  1. Select the required file.
  2. Launch its properties window
  3. Goto C/C++ -> Advanced, and change Compile as to Compile as C++ Code (/TP)

enter image description here

2
votes

I am not sure how much helpful will this be, but recently I faced with similar issue trying to compile the 'darknet' open source tool. The source includes a header files from OpenCV but needs to be compiled with C compiler and not with C++.

The codes were using the following headers and I have just changed the header names: instead of:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

use the following:

#include "opencv2/highgui/highgui_c.h"
#include "opencv2/imgproc/imgproc_c.h"