public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Use +z or +Z to recompile...
@ 2002-10-21 10:47 Venkatakrishnan, V
  2002-10-21 10:55 ` Jeff Law
  0 siblings, 1 reply; 5+ messages in thread
From: Venkatakrishnan, V @ 2002-10-21 10:47 UTC (permalink / raw)
  To: 'law@redhat.com'; +Cc: gcc-help

Using -fPIC gives the same error.

-----Original Message-----
From: Jeff Law [mailto:law@porcupine.cygnus.com] 
Sent: Monday, October 21, 2002 12:34 PM
To: Venkatakrishnan, V
Cc: gcc-help@gcc.gnu.org
Subject: Re: Use +z or +Z to recompile... 


In message
<8229C4577A00D511ABC00090277A45A0012361B1@us0111-ch-ms1.sdi.xcdg.xer
ox.com>, "Venkatakrishnan, V" writes:
 >Hi,
 >	I'm using gcc ver 3.2 20020708 (experimental) on my HPUX 11.0 box.
 >	When building a shared library I get an error as follows....
 >
 >/usr/ccs/bin/ld: DP relative code in file /var/tmp//ccCoJZUg.o - shared
>library must be position independent.  Use +z or +Z to recompile.  >
 >	Now I'm already using the -fpic option while compiling my .c to .o
 >using which I then try to build my .sl, so I guess my object file is
already  >position independent.  Why the error during link though?
 >	Is there something I'm missing here??
Use -fPIC rather than -fpic.
jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Use +z or +Z to recompile...
  2002-10-21 10:47 Use +z or +Z to recompile Venkatakrishnan, V
@ 2002-10-21 10:55 ` Jeff Law
  2002-10-21 17:50   ` Nagu
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Law @ 2002-10-21 10:55 UTC (permalink / raw)
  To: Venkatakrishnan, V; +Cc: gcc-help

In message <8229C4577A00D511ABC00090277A45A0012361B2@us0111-ch-ms1.sdi.xcdg.xer
ox.com>, "Venkatakrishnan, V" writes:
 >Using -fPIC gives the same error.
Did you use it when linking your shared library as well?
jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Use +z or +Z to recompile...
  2002-10-21 10:55 ` Jeff Law
@ 2002-10-21 17:50   ` Nagu
  2002-10-22  2:27     ` multiple function definition (was: RE: Use +z or +Z to recompile...) Claudio Bley
  2002-10-23  3:45     ` Use +z or +Z to recompile Andrea Bocci
  0 siblings, 2 replies; 5+ messages in thread
From: Nagu @ 2002-10-21 17:50 UTC (permalink / raw)
  To: law, 'Venkatakrishnan, V'; +Cc: gcc-help


Hi all,
I have this problem of linking error using gcc, I have 4 simple files
first.c (where main function is defined), and myfunc1, myfunc2 and
incl.h (which defines another function called basefunc). When I compile,
I get fatal error saying that multiply defined "basefunc". How to get
rid of this? 
Thanks
Best
nagu

^ permalink raw reply	[flat|nested] 5+ messages in thread

* multiple function definition (was: RE: Use +z or +Z to recompile...)
  2002-10-21 17:50   ` Nagu
@ 2002-10-22  2:27     ` Claudio Bley
  2002-10-23  3:45     ` Use +z or +Z to recompile Andrea Bocci
  1 sibling, 0 replies; 5+ messages in thread
From: Claudio Bley @ 2002-10-22  2:27 UTC (permalink / raw)
  To: Nagu; +Cc: gcc-help

[ please start a new thread with an appropriate subject line instead
  of replying to other random messages ]

>>>>> "Nagu" == Nagu  <thogiti@usc.edu> writes:

    Nagu> Hi all, I have this problem of linking error using gcc, I
    Nagu> have 4 simple files first.c (where main function is
    Nagu> defined), and myfunc1, myfunc2 and incl.h (which defines
    Nagu> another function called basefunc). When I compile, I get
    Nagu> fatal error saying that multiply defined "basefunc". How to
    Nagu> get rid of this?  Thanks Best nagu

This question is not really a GCC question - it's more a C programming
question. Anyway, you just shouldn't define functions in header files
(except for inline functions). The usual modus operandi is something
like this:

,----[ foo.h ]
| #ifndef FOO_H
| #define FOO_H
| 
| int bar (int);
| 
| #endif /* FOO_H */
`----

,----[ foo.c ]
| #include "foo.h"
| 
| int bar (int x) {
| 	return (x * x);
| }
`----

,----[ main.cc ]
| #include "foo.h"
| 
| int main () {
| 	bar (3);
| 	return 0;
| }
`----

I suggest that you read a good book about programming. Have a look at
http://www.advancedlinuxprogramming.com/. Don't be afraid reading a
book titled "advanced" programming, it just starts with the basics and
is not only applicable for linux.

HTH
-- 
Claudio Bley                                 ASCII ribbon campaign (")
Debian GNU/Linux advocate                     - against HTML email  X 
http://www.cs.uni-magdeburg.de/~bley/                     & vCards / \

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Use +z or +Z to recompile...
  2002-10-21 17:50   ` Nagu
  2002-10-22  2:27     ` multiple function definition (was: RE: Use +z or +Z to recompile...) Claudio Bley
@ 2002-10-23  3:45     ` Andrea Bocci
  1 sibling, 0 replies; 5+ messages in thread
From: Andrea Bocci @ 2002-10-23  3:45 UTC (permalink / raw)
  To: Nagu; +Cc: law, 'Venkatakrishnan, V', gcc-help

At 17.52 21/10/2002 -0700, Nagu wrote:

>Hi all,
>I have this problem of linking error using gcc, I have 4 simple files
>first.c (where main function is defined), and myfunc1, myfunc2 and
>incl.h (which defines another function called basefunc). When I compile,
>I get fatal error saying that multiply defined "basefunc". How to get
>rid of this?
>Thanks
>Best
>nagu

put

#ifndef INCL_H
#define INCL_H

at the top of incl.h

and

#endif // ifndef INCL_H

ad the end


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-10-23 10:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-21 10:47 Use +z or +Z to recompile Venkatakrishnan, V
2002-10-21 10:55 ` Jeff Law
2002-10-21 17:50   ` Nagu
2002-10-22  2:27     ` multiple function definition (was: RE: Use +z or +Z to recompile...) Claudio Bley
2002-10-23  3:45     ` Use +z or +Z to recompile Andrea Bocci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).