you'll have to include the definition in ur c++ prog within the extern
statements braces ...

extern "C" {
        extern void funky(void);
}

this is because C++ appends info redgarding the argument types to the fn
name, so that overloading and the likes can be performed. this is called
name mangling if u want the correct terms. by using the extern "C" you
tell the compiler to cut the name mangling from your fn as it has been
compiled externally from the C++ compiler, and thus has no such info.
regarding the argument types.
        

On Fri, 9 Apr 1999, John wrote:

> I have been trying for a couple of weeks now to compile a program that 
> consists of a C++ main function which calls a C function. I have tried 
> using the -c option to compile object code for both files using gcc and 
> g++, then linking them together (I've trued using both gcc and g++ to 
> link the object code). However when I try the final link together I get 
> an error saying that there was an undefined reference to the C function 
> in the main function. 
> 
> Here is the test code I have been using (I know there is no reason why 
> I can't compile them both as C or C++ but they are not the functions I 
> need to compile, only test ones. It makes sense to me. The final code I 
> create will involve RPC calls which I can only get working in C)
> 
> //C++ main function called main.cc
> extern void funky(void);
> 
> void main()
> {
>   funky();
> };
> 
> //C function called funky.c
> void funky()
> {
>   int x;
>   x = 0;
> };
> 
> 
> The commands I used were
> g++ -c main.cc
> gcc -c funky.c
> g++ main.o funky.o -o prog
> 
> I am sorry to bother you with this question but I don't know who else 
> to try, even my leactures at university don't know how to achieve this.
> --
> John, My reality check just bounced.
> 
> 
> 

          ####################################################
          # Blinston S. Fernandes    eMail:[EMAIL PROTECTED] #
          # System Software Development Group                #
          # Centre for Development of Advanced Computing     #
          # 2/1 Ramanashree Plaza                            #
          # Bangalore 560 025                               #
          # India                                          #
          # Tel: 91-080-5584271/982/143   ext:310         #
          # Fax: 91-080-5584893                          #   b2
          ###############################################    **



Reply via email to