Re: gcc Linking problem ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux