chfakht
Posts: 30
Joined: Sat Jul 04, 2015 4:38 pm

#error header must be compiled as C++

Wed Jul 08, 2015 11:00 pm

Hi all ,
i want to install a librarie that support pi camera module with c++ and opencv i've found a support librarie of the pi Camera module
here :https://github.com/robidouille/ro ... aspicam_cv
when i arrive here
mkdir objs
make ## <==== here
I got this errors !
gcc -c -Wno-multichar -g -I/usr/include/opencv -I/home/pi/git/raspberrypi/userland/host_applications/linux/libs/bcm_host/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam -I/home/pi/git/raspberrypi/userland -I/home/pi/git/raspberrypi/userland/interface/vcos/pthreads -I/home/pi/git/raspberrypi/userland/interface/vmcs_host/linux -I/home/pi/git/raspberrypi/userland/interface/mmal -MD RaspiCamCV.c -o objs/RaspiCamCV.o
In file included from /usr/local/include/opencv2/core/core.hpp:48:0,
from /usr/include/opencv/cv.h:64,
from RaspiCamCV.c:40:
/usr/local/include/opencv2/core.hpp:49:4: error: #error core.hpp header must be compiled as C++
In file included from /usr/local/include/opencv2/core.hpp:54:0,
from /usr/local/include/opencv2/core/core.hpp:48,
from /usr/include/opencv/cv.h:64,
from RaspiCamCV.c:40:
/usr/local/include/opencv2/core/base.hpp:49:4: error: #error base.hpp header must be compiled as C++
/usr/local/include/opencv2/core/base.hpp:52:19: fatal error: climits: No such file or directory
compilation terminated.
Makefile:45: recipe for target 'objs/RaspiCamCV.o' failed
make: *** [objs/RaspiCamCV.o] Error 1

i googled it with finding a solution !!!
thanks for your help

User avatar
jeanleflambeur
Posts: 157
Joined: Mon Jun 16, 2014 6:07 am
Contact: Website

Re: #error header must be compiled as C++

Thu Jul 09, 2015 8:04 am

The problem seems to be that you're including a C++ header (hpp) in a C file. C files are compiled differently than C++ files and the compiler figures out which is which by the extension.

It's legal to include a C header in a C++ file as C++ is backwards compatible, but not legal to do the reverse.

So try to rename the RaspiCamCV.c to RaspiCamCV.cpp. Don't forget to modify the Makefile as well.

Yam
Posts: 68
Joined: Wed May 16, 2012 12:14 pm

Re: #error header must be compiled as C++

Mon Jul 13, 2015 4:52 pm

Yup legal C code is legal C++ code (except some very rare exceptions)
you don't need to learn anything new just write in C and compile with a C++ compiler.

Probably wise to make a note of it in a comment if its a public project.

robcrooky1994
Posts: 2
Joined: Thu Apr 07, 2016 7:09 pm

Re: #error header must be compiled as C++

Thu Apr 07, 2016 7:20 pm

Hi All,

Needing some help with overcoming this same error.

I'm new to programming but am currently needing it as part of a university project which involves using a raspberry pi to make an letter recognition system. I have also found this librarie to allow me to use the pi camera with my script and open cv.(https://github.com/robidouille/robidoui ... aspicam_cv)

But like chfakht I am getting the same error. To solve it I understand i need to rename the RaspiCamCV.c to RaspiCamCV.cpp and modify the make file.
But how do i modify the make file to compile in c++ instead of c?

Here is a copy of the make file:
OBJS = objs

CFLAGS_OPENCV = -I/usr/include/opencv
LDFLAGS2_OPENCV = -lopencv_highgui -lopencv_core -lopencv_legacy -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_imgproc -lpthread -lm

USERLAND_ROOT = $(HOME)/git/raspberrypi/userland
CFLAGS_PI = \
-I$(USERLAND_ROOT)/host_applications/linux/libs/bcm_host/include \
-I$(USERLAND_ROOT)/host_applications/linux/apps/raspicam \
-I$(USERLAND_ROOT) \
-I$(USERLAND_ROOT)/interface/vcos/pthreads \
-I$(USERLAND_ROOT)/interface/vmcs_host/linux \
-I$(USERLAND_ROOT)/interface/mmal \

LDFLAGS_PI = -L$(USERLAND_ROOT)/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host

BUILD_TYPE=debug
#BUILD_TYPE=release

CFLAGS_COMMON = -Wno-multichar -g $(CFLAGS_OPENCV) $(CFLAGS_PI) -MD

ifeq ($(BUILD_TYPE), debug)
CFLAGS = $(CFLAGS_COMMON)
endif
ifeq ($(BUILD_TYPE), release)
CFLAGS = $(CFLAGS_COMMON) -O3
endif

LDFLAGS =
LDFLAGS2 = $(LDFLAGS2_OPENCV) $(LDFLAGS_PI) -lX11 -lXext -lrt -lstdc++

RASPICAMCV_OBJS = \
$(OBJS)/RaspiCamControl.o \
$(OBJS)/RaspiCLI.o \
$(OBJS)/RaspiCamCV.o \

RASPICAMTEST_OBJS = \
$(OBJS)/RaspiCamTest.o \

TARGETS = libraspicamcv.a raspicamtest libraspicamcv.so

all: $(TARGETS)

$(OBJS)/%.o: %.c
gcc -c $(CFLAGS) $< -o [email protected]

$(OBJS)/%.o: $(USERLAND_ROOT)/host_applications/linux/apps/raspicam/%.c
gcc -c $(CFLAGS) $< -o [email protected]

libraspicamcv.a: $(RASPICAMCV_OBJS)
ar rcs libraspicamcv.a -o $+

libraspicamcv.so: $(RASPICAMCV_OBJS)
gcc -shared -o libraspicamcv.so $+ -Wl,-whole-archive $(LDFLAGS_PI) -lopencv_core -lopencv_highgui -Wl,-no-whole-archive

raspicamtest: $(RASPICAMTEST_OBJS) libraspicamcv.a
gcc $(LDFLAGS) $+ $(LDFLAGS2) -L. libraspicamcv.a -o [email protected]

clean:
rm -f $(OBJS)/* $(TARGETS)

-include $(OBJS)/*.d

Thanks for the help.

swampdog
Posts: 221
Joined: Fri Dec 04, 2015 11:22 am

Re: #error header must be compiled as C++

Sat Apr 09, 2016 12:17 am

I'm afraid you're git hub link doesn't work.

robcrooky1994
Posts: 2
Joined: Thu Apr 07, 2016 7:09 pm

Re: #error header must be compiled as C++

Sat Apr 09, 2016 4:34 pm

Oh sorry, hopefully this one should

https://github.com/robidouille/robidoui ... aspicam_cv

If not if you google " robidouille raspicam " it is the first link to appear

Return to “C/C++”