public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Static linking help please...!
@ 1999-11-08 15:56 Tom Gilbert
  1999-11-09  9:26 ` Lokesh Setia
  1999-11-30 23:28 ` Tom Gilbert
  0 siblings, 2 replies; 4+ messages in thread
From: Tom Gilbert @ 1999-11-08 15:56 UTC (permalink / raw)
  To: help-gcc

Hi there,

I'm porting some Windows code (free OpenGL screen savers from
http://www.AlteredWorlds.com ).
I have two libraries in my code which on Windows are compiled as both-

Loadable modules [DLL]    - loaded at run time
Static libraries       [.lib]       - used to build a statically linked
executable

The Linux version of the code is working when using '.so' loadable
libraries, but I'd rather distribute an all-in-one executable, and can't get
g++ to produce a statically linked version at the moment. Any help would be
greatly appreciated.

System setup - Caldera OpenLinux 2.3 [2.2.10 kernel] 'Developer' install,
includes egcs-c++ 2.91.66-5

DYNAMIC LIBRARY (this works):
Compiler options used to build shared version -
for object files:
Compile:
g++ -c -fPIC -Iwhatever somthing.cpp -o something.obj

link:
g++ -shared -fPIC list_of_.obj -o something.so

So this works without any problems.

STATIC LIBRARY:
object files-
g++ -c  -Iwhatever somthing.cpp -o something.obj

link:
FIRST TRY-
g++      list_of_.obj     -o something.a
this is obviously trying to produce an executable, as I get the following
error message -
/usr/lib/crt1.o (.text+0x18): undefined reference to 'main'

SECOND TRY-
g++    -static    list_of_.obj   -o something.a

this one fails as follows-
/usr/i386-linux/bin/ld: cannot open -lstdc++: No such file or directory

Any ideas on how to proceed?

Thanks for any help - I'd be grateful if you'd reply via email also, to
tom@alteredworlds.com

Tom Gilbert
Owner, Lead Engineer, AlteredWorlds
http://www.AlteredWorlds.com




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

* Re: Static linking help please...!
  1999-11-08 15:56 Static linking help please...! Tom Gilbert
@ 1999-11-09  9:26 ` Lokesh Setia
  1999-11-30 23:28   ` Lokesh Setia
  1999-11-30 23:28 ` Tom Gilbert
  1 sibling, 1 reply; 4+ messages in thread
From: Lokesh Setia @ 1999-11-09  9:26 UTC (permalink / raw)
  To: help-gcc

>>>>> "Tom" == Tom Gilbert <tom@alteredworlds.com> writes:

<snipped>

    Tom> DYNAMIC LIBRARY (this works): Compiler options used to build
    Tom> shared version - for object files: Compile: g++ -c -fPIC
    Tom> -Iwhatever somthing.cpp -o something.obj

    Tom> link: g++ -shared -fPIC list_of_.obj -o something.so

    Tom> So this works without any problems.

    Tom> STATIC LIBRARY: object files- g++ -c -Iwhatever somthing.cpp
    Tom> -o something.obj

    Tom> link: FIRST TRY- g++ list_of_.obj -o something.a this is
    Tom> obviously trying to produce an executable, as I get the
    Tom> following error message - /usr/lib/crt1.o (.text+0x18):
    Tom> undefined reference to 'main'

    Tom> SECOND TRY- g++ -static list_of_.obj -o something.a

    Tom> this one fails as follows- /usr/i386-linux/bin/ld: cannot
    Tom> open -lstdc++: No such file or directory

For creating libraries for static linking, you need to use "ar" to
archive the files in a ".a" file.  An ar archived file is just a
simple collection of object files, there's no information needed to
resolve so you don't need gcc/ld to create the library. The syntax for
"ar" is somewhat similar to "tar". You need something like:

ar rc something.a list_of_.obj

then link your program with -lsomething


Regards,
Lokesh.

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

* Re: Static linking help please...!
  1999-11-09  9:26 ` Lokesh Setia
@ 1999-11-30 23:28   ` Lokesh Setia
  0 siblings, 0 replies; 4+ messages in thread
From: Lokesh Setia @ 1999-11-30 23:28 UTC (permalink / raw)
  To: help-gcc

>>>>> "Tom" == Tom Gilbert <tom@alteredworlds.com> writes:

<snipped>

    Tom> DYNAMIC LIBRARY (this works): Compiler options used to build
    Tom> shared version - for object files: Compile: g++ -c -fPIC
    Tom> -Iwhatever somthing.cpp -o something.obj

    Tom> link: g++ -shared -fPIC list_of_.obj -o something.so

    Tom> So this works without any problems.

    Tom> STATIC LIBRARY: object files- g++ -c -Iwhatever somthing.cpp
    Tom> -o something.obj

    Tom> link: FIRST TRY- g++ list_of_.obj -o something.a this is
    Tom> obviously trying to produce an executable, as I get the
    Tom> following error message - /usr/lib/crt1.o (.text+0x18):
    Tom> undefined reference to 'main'

    Tom> SECOND TRY- g++ -static list_of_.obj -o something.a

    Tom> this one fails as follows- /usr/i386-linux/bin/ld: cannot
    Tom> open -lstdc++: No such file or directory

For creating libraries for static linking, you need to use "ar" to
archive the files in a ".a" file.  An ar archived file is just a
simple collection of object files, there's no information needed to
resolve so you don't need gcc/ld to create the library. The syntax for
"ar" is somewhat similar to "tar". You need something like:

ar rc something.a list_of_.obj

then link your program with -lsomething


Regards,
Lokesh.

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

* Static linking help please...!
  1999-11-08 15:56 Static linking help please...! Tom Gilbert
  1999-11-09  9:26 ` Lokesh Setia
@ 1999-11-30 23:28 ` Tom Gilbert
  1 sibling, 0 replies; 4+ messages in thread
From: Tom Gilbert @ 1999-11-30 23:28 UTC (permalink / raw)
  To: help-gcc

Hi there,

I'm porting some Windows code (free OpenGL screen savers from
http://www.AlteredWorlds.com ).
I have two libraries in my code which on Windows are compiled as both-

Loadable modules [DLL]    - loaded at run time
Static libraries       [.lib]       - used to build a statically linked
executable

The Linux version of the code is working when using '.so' loadable
libraries, but I'd rather distribute an all-in-one executable, and can't get
g++ to produce a statically linked version at the moment. Any help would be
greatly appreciated.

System setup - Caldera OpenLinux 2.3 [2.2.10 kernel] 'Developer' install,
includes egcs-c++ 2.91.66-5

DYNAMIC LIBRARY (this works):
Compiler options used to build shared version -
for object files:
Compile:
g++ -c -fPIC -Iwhatever somthing.cpp -o something.obj

link:
g++ -shared -fPIC list_of_.obj -o something.so

So this works without any problems.

STATIC LIBRARY:
object files-
g++ -c  -Iwhatever somthing.cpp -o something.obj

link:
FIRST TRY-
g++      list_of_.obj     -o something.a
this is obviously trying to produce an executable, as I get the following
error message -
/usr/lib/crt1.o (.text+0x18): undefined reference to 'main'

SECOND TRY-
g++    -static    list_of_.obj   -o something.a

this one fails as follows-
/usr/i386-linux/bin/ld: cannot open -lstdc++: No such file or directory

Any ideas on how to proceed?

Thanks for any help - I'd be grateful if you'd reply via email also, to
tom@alteredworlds.com

Tom Gilbert
Owner, Lead Engineer, AlteredWorlds
http://www.AlteredWorlds.com




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

end of thread, other threads:[~1999-11-30 23:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-08 15:56 Static linking help please...! Tom Gilbert
1999-11-09  9:26 ` Lokesh Setia
1999-11-30 23:28   ` Lokesh Setia
1999-11-30 23:28 ` Tom Gilbert

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).