This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc -x c does link with -ljpeg, gcc -x c++ does not


On Friday 28 March 2003 10:57, Matthieu Moy wrote:
> Stefan Hetzl <shetzl at chello dot at> writes:
> > Hi,
> >
> > I want to compile and link a small program (c code) that uses libjpeg.
> > When I invoke "gcc -x c -v readcoeff.c -ljpeg" everything works fine, but
> > invoking "gcc -x c++ -v readcoeff.c -ljpeg" gives "undefined
> > reference..."-error messages for every function from libjpeg (see the
> > attached outputs).
> >
> > Any Ideas what could be causing this ?
>
> I suppose this is a mangling problem :
>
> In C,  a function is uniquely defined  by its name, so,  the symbol in
> the object code can be just the name of the function.
>
> In  C++,  you can  use  function overloading,  so,  you  need to  have
> different  symbols for  f(int) and  f(int, int)  for example.  This is
> called mangling.
>
> The solution is to tell your program that the functions in libjpeg are
> C functions compiled with a C compiler by using the
>
> extern "C"
>
> directive.
>
> Something like
>
> extern "C" {
> #include "jpeg.h"
> }
>
> May do.
With extern "C" it works. Thank You!

Regards,
Stefan Hetzl


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]