www.digitalmars.com         C & C++   DMDScript  

c++ - Mangled C++ & C? Incompatibility! Symbol undefined?

reply "DMC" <tomer_sofer hotmail.com> writes:
I am total novice! I am writing my thesis and  I am trying to use a library
routine (Numerical Recipes, amebsa.c ). Supposedly it should include all
necessary files. Now the compiler spouts out the following error message:

link samain,,,user32+kernel32/noi;
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

samain.obj(samain)
 Error 42: Symbol Undefined ?free_vector  YAXPAMJJ Z (void cdecl
free_vector(flo
at *,long ,long ))
samain.obj(samain)
 Error 42: Symbol Undefined ?amotsa  YAMPAPAMPAM1H11P6AM1 ZH1M Z (float
cdecl am
otsa(float **,float *,float *,int ,float *,float *,float cdecl (*)(float
*),int
,float *,float ))
samain.obj(samain)
 Error 42: Symbol Undefined ?ran1  YAMPAJ Z (float cdecl ran1(long *))
samain.obj(samain)
 Error 42: Symbol Undefined ?idum  3JA (long idum)
samain.obj(samain)
 Error 42: Symbol Undefined ?vector  YAPAMJJ Z (float *cdecl vector(long
,long )
)

--- errorlevel 5


I tried finding the files free_vector.h and vector.h. The remaining ones I
actually do them in the include folder of my dmc!
Does anyone know how to handle this problem. Or where to find the files. Can
any difficulty arise due to the incorporation of older files that are not as
new as the ones used by DMC. (i.e. complex.h and older c routines)

Since this is the core of my thesis is of paramount importance. Thanks for
all postings!?

Tomer
Jan 27 2004
parent Ilya Minkov <minkov cs.tum.edu> writes:
So, you have a core application in C++ and libraries in C?

Try to add this to the beginning of the header files which belong to a C
library:

#ifdef	__cplusplus
extern "C" {
#endif

and this to the end:

#ifdef  __cplusplus
}
#endif


Alternatively, you can use something like this in your C++ application
files (*.cpp)

extern "C" {
//include your C libraries here
#include "blahblah.h"
#include "halbhalb.h"
}

As you can see, this is basically the same. Any of these steps makes
your C++ compiler know that the incuded declarations belong to a library
with C naming and calling convention.

-eye

DMC wrote:
 I am total novice! I am writing my thesis and  I am trying to use a library
 routine (Numerical Recipes, amebsa.c ). Supposedly it should include all
 necessary files. Now the compiler spouts out the following error message:
 
 link samain,,,user32+kernel32/noi;
 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved
 
 samain.obj(samain)
  Error 42: Symbol Undefined ?free_vector  YAXPAMJJ Z (void cdecl
 free_vector(flo
 at *,long ,long ))
 samain.obj(samain)
  Error 42: Symbol Undefined ?amotsa  YAMPAPAMPAM1H11P6AM1 ZH1M Z (float
 cdecl am
 otsa(float **,float *,float *,int ,float *,float *,float cdecl (*)(float
 *),int
 ,float *,float ))
 samain.obj(samain)
  Error 42: Symbol Undefined ?ran1  YAMPAJ Z (float cdecl ran1(long *))
 samain.obj(samain)
  Error 42: Symbol Undefined ?idum  3JA (long idum)
 samain.obj(samain)
  Error 42: Symbol Undefined ?vector  YAPAMJJ Z (float *cdecl vector(long
 ,long )
 )
 
 --- errorlevel 5
 
 
 I tried finding the files free_vector.h and vector.h. The remaining ones I
 actually do them in the include folder of my dmc!
 Does anyone know how to handle this problem. Or where to find the files. Can
 any difficulty arise due to the incorporation of older files that are not as
 new as the ones used by DMC. (i.e. complex.h and older c routines)
 
 Since this is the core of my thesis is of paramount importance. Thanks for
 all postings!?
 
 Tomer
 
 
Jan 27 2004