Using a C++ class in C source file

L

Laszlo

Hi all,

I created a C1.hpp and C1.cpp, compiled and linked into a C1.a
file. I did copy the C1.a file into /usr/local/apache2/lib and
C1.hpp into /usr/local/apache2/include. This class provides
some usefull methods to process a request.

OK. Now I would like to use it in my module mod_xyz.
Entering the command

/usr/local/apache2/bin/apxs -c -i -a mod_xyz.c

returns these lines:

/usr/local/apache2/build/libtool --silent --mode=compile gcc3
-prefer-pic
-DAP_HAVE_DESIGNATED_INITIALIZER -DLINUX=2 -D_REENTRANT
-D_XOPEN_SOURCE=500 -D_BSD_SOURCE
-D_SVID_SOURCE -D_GNU_SOURCE -g -O2 -pthread
-I/usr/local/apache2/include
-I/usr/local/apache2/include -I/usr/local/apache2/include -c -o
mod_xyz.lo mod_xyz.c && touch
mod_xyz.slo
In file included from mod_xyz.c:4:
/usr/local/apache2/include/C1.hpp:6: parse error before "C1"
/usr/local/apache2/include/C1.hpp:7: syntax error before '{' token
/usr/local/apache2/include/C1.hpp:20: syntax error before "int"
/usr/local/apache2/include/C1.hpp:27: syntax error before "int"
/usr/local/apache2/include/C1.hpp:33: syntax error before "int"
/usr/local/apache2/include/C1.hpp:39: syntax error before "void"
/usr/local/apache2/include/C1.hpp:46: syntax error before "int"
/usr/local/apache2/include/C1.hpp:53: syntax error before "char"
/usr/local/apache2/include/C1.hpp:55: parse error before ':' token
apxs:Error: Command failed with rc=65536
..

How can I fix it?
 
E

EventHelix.com

You cannot have a C++ class in a C source file. Just rename the .c file
to
..cpp and compile again.

Also need to be careful about sharing globals between C and C++. Use
extern "C" in C++ code for any variables that are shared with C code.

Deepa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top