Trouble in Adding cpp header in C file.

225 views
Skip to first unread message

Atul Raut

unread,
Apr 23, 2012, 2:54:54 AM4/23/12
to andro...@googlegroups.com
Trouble in adding, cpp header in c file.

Hi,

I am facing trouble in adding CPP header in C file.

I have main.c, of native NDK, was trying to
call cpp functions from this main.c, but while
adding cpp header on to c file its throwing error. 
Error :
jni/main.c:35: error: expected identifier or '(' before string constant
jni/main.c: In function 'android_main':

My main.c file has : 
/*c_file.h*/
#ifndef __cplusplus
extern "C++" {              /*Line 35: Getting error at this line */
#endif
//#include "cpp_file.h"  /*My CPP header file*/
#include "libcam.h"
#ifndef __cplusplus

Any pointer will help
 
Thanks,
----------------------------------------------------------------------------------------------------------------------------------
Atul Raut

http://rautatul.weebly.com/

Tor Lillqvist

unread,
Apr 23, 2012, 4:10:43 AM4/23/12
to andro...@googlegroups.com
C++ and C are different languages.

--tml

Thomas Martitz

unread,
Apr 23, 2012, 4:12:19 AM4/23/12
to andro...@googlegroups.com
Am 23.04.2012 08:54, schrieb Atul Raut:
> Trouble in adding, cpp header in c file.
>
> Hi,
>
> I am facing trouble in adding CPP header in C file.
>
> I have main.c, of native NDK, was trying to
> call cpp functions from this main.c, but while
> adding cpp header on to c file its throwing error.
> Error :
> jni/main.c:35: error: expected identifier or '(' before string constant
> jni/main.c: In function 'android_main':
>
> My main.c file has :
> /*c_file.h*/
> #ifndef __cplusplus
> extern "C++" { /*Line 35: Getting error at this line */
> #endif
> //#include "cpp_file.h" /*My CPP header file*/
> #include "libcam.h"
> #ifndef __cplusplus
> }
>

You need "#ifdef __cplusplus" (not ifndef) so that the extern C++ line
is only compiled in C++ mode.

Best regards.

Thomas Martitz

unread,
Apr 23, 2012, 4:16:10 AM4/23/12
to andro...@googlegroups.com

It needs to be 'extern "C"' too. There exists no "extern C++" for C.

Reply all
Reply to author
Forward
0 new messages