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

Re: g++ / ld / publib linking problem



Hi

On Thu, 10 Jul 1997, Oliver Elphick wrote:

> Date: Thu, 10 Jul 1997 16:49:31 +0100
> From: Oliver Elphick <olly@lfix.co.uk>
> To: debian-user@lists.DEBIAN.org
> Subject: g++ / ld / publib linking problem
> Resent-Date: Thu, 10 Jul 1997 16:47:47 +0000
> Resent-From: debian-user@lists.DEBIAN.org
> Resent-cc: recipient list not shown: ;
> 
> No-one has attempted an answer to this yet; if you have any ideas,

hmm...

this is first time i saw this

> please let me know!
> 
> ------- Repeated Message
> 
> Date:    Fri, 04 Jul 1997 22:21:39 +0100
> From:    "Oliver Elphick" <olly@lfix.co.uk>
> To:      debian-user@lists.debian.org
> Subject: Problem linking with publib library and g++
> 
> I have a linking problem when I try to include functions from the
> publib library in a C++ program.  This worked before I upgraded
> to the new releases (see below).
> 
> An easy example:
>  #include <publib.h>
>  main()
>  {
>   char *x = "This   is  a string     with   spaces     ";
>   char y[256];
> 
>   strcpy(y, x);
>   strtrim(y);
>   strmtrim(y);
>   printf ("%s-\n%s-\n", x, y);
>  }
> 
> When I try to compile this as C++:
>  linda:~/cprogs$ g++ main.c -lpub        
>  /tmp/cca132571.o: In function `main':
>  /tmp/cca132571.o(.text+0x2b): undefined reference to `strtrim(char *)'
>  /tmp/cca132571.o(.text+0x3a): undefined reference to `strmtrim(char *)'
> 
> but as C, it's fine:
>  linda:~/cprogs$ gcc main.c -lpub
>  linda:~/cprogs$ 
> 
> I can't work out what has changed and why this no longer works.
> 
> System:     Pentium Pro
> Kernel:     2.0.30
> Debian:     1.3 from unstable
> gcc:        2.7.2.2-4
> binutils:   2.8.1-1
> publib-dev: 0.26-1
> libc6:      2.0.3-4
> 
> ------- End of Repeated Message

obviously, C++ name mangling in all it's glory...

> 
> Even if I include the library directly on the command line, it doesn't
> work:
> 
> linda:~/cprogs$ g++ main.c /usr/lib/libpub.a
> /tmp/cca122331.o: In function `main':
> /tmp/cca122331.o(.text+0x2b): undefined reference to `strtrim(char *)'
> /tmp/cca122331.o(.text+0x3a): undefined reference to `strmtrim(char *)'
> 
> but again, gcc finds it:
> 
> linda:~/cprogs$ gcc main.c /usr/lib/libpub.a
> linda:~/cprogs$ 
> 
> so it must be something different about the ways that gcc and g++ expect
> to find things in libraries???

yep...

gcc look for strtrim, while g++ looks for
something like strtrim$pc4


> Since the original message, I have tried loading the source of publib
> and recompiling it; this made no difference (there was no reason why
> it should, but I'm clutching at straws now...)

put 

#ifdef __cplusplus
extern "C" {
#endif

#include <publib.h>

#ifdef __cplusplus
}
#endif


in your main.cc instead of #include <publib.h>



cheers

OK



--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: