gcc Linking problem ?
Jonathan Wakely
jwakely.gcc@gmail.com
Sun Apr 17 17:35:00 GMT 2011
On 17 April 2011 09:11, Alireza Haghdoost wrote:
> I have solved the problem in this way:
>
> $g++ -c stack.cpp
> $gcc -c main.c
> $g++ -o heloo stack.o main.o
>
> //--- main.c
> #include "stack.h"
> // #include "stdio.h"
>
>
> int main(){
> find_in_map();
> return 0;
> }
>
>
> //---stack.h---
> #ifdef _cplusplus
> extern "C" {
> #endif
>
> void find_in_map();
> #ifdef _cplusplus
> }
> # endif
This change is correct, if you want C code to call a C++ function then
the function must be declared extern "C"
> //---stack.cpp---
> extern "C"{
> #include "stack.h"
> }
This is incorrect, you do not need to include the header in an extern
"C" block because the header itself already includes an extern "C"
block around the function declaration. In general putting extern "C"
around a #include is the wrong thing to do.
More information about the Gcc-help
mailing list