I tried extern "C", but it didn't work.
Below is a small sample code I created that reproduces the problem.
foo.h:
Expand|Select|Wrap|Line Numbers
- #ifndef __FOO_H
- #define __FOO_H
- typedef struct
- {
- int namespace;
- int this;
- } foo_st;
- void printfoo( foo_st* st );
- void setfoo( foo_st* st, int n, int t );
- #endif
Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- #include "foo.h"
- void setfoo( foo_st* st, int n, int t )
- {
- st->namespace = n;
- st->this = t;
- }
- void printfoo( foo_st* st )
- {
- printf("foo->namespace = %d, foo->this = %d\n", st->namespace, st->this );
- }
Expand|Select|Wrap|Line Numbers
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- #include "foo.h"
- #ifdef __cplusplus
- }
- #endif
- int main()
- {
- foo_st myfoo;
- setfoo( & myfoo, 4, 5 );
- printfoo( & myfoo );
- return 0;
- }
gcc foo.c -c
gcc bar.cpp foo.o
The error I get is:
In file included from bar.cpp:5:
foo.h:6: error: declaration does not declare anything
foo.h:6: error: syntax error before `namespace'
foo.h:7: error: declaration does not declare anything
(if I change bar.cpp to bar.c, it works as it should)
Can anyone help with that?