Author Topic: How To Link Statically?  (Read 8041 times)

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
How To Link Statically?
« on: June 27, 2006, 04:42:01 am »
Hello,

I'm not a development guru, but from time to time I compile programs on the zaurus.
One questions, because there are often problems with unresolved dependencies when distributing programs which are linked dynamically:

How can I switch to statical linking

a. when using the normal Makefile stuff most sources come with
b. when compiling without having a makefile, i.e. directly with
gcc -o binary source.c

And:
Is really everything linked in statically then, or only the direct dependencies,  but dependencies of dependencies still dynamically, e.g. if a library needs a library...

Thanks
daniel
« Last Edit: June 27, 2006, 04:43:16 am by daniel3000 »
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

dinorex

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • http://dinorex.mocasting.com
How To Link Statically?
« Reply #1 on: June 27, 2006, 04:54:37 am »
if you configure the zgcc cramfs package  correctly, your line is ok to go....  for standard ANSI C stuff (under default environment)... to generate the .o (object) file

for linking out the binary, you need to link function... from the object file to binary...

for extra libs and / or languages, you may need to specify other include dirs and lib dirs....

you can try by the examples included in the cramfs package - hello dir

the Makefile in fact consists only 2 lines :

object file generation: g++ -c .... -o hello.o hello.cpp
binary file generation: g++ -o ... -o hello hello.o

hope this helps.
« Last Edit: June 27, 2006, 05:34:51 am by dinorex »
Dinorex corner: -
Chinese: http://dinorex.mocasting.com/
English: http://dinorex-redoxin.blogspot.com/
Website: http://dinorex.no-ip.biz/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Zauri SL-C3100 (1 black & 1 grey)
black - Qtopia / Cacko (for notes taking in meetings) :)
grey - ROM wild tester....

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
How To Link Statically?
« Reply #2 on: June 27, 2006, 05:52:28 am »
Quote
if you configure the zgcc cramfs package  correctly, your line is ok to go....  for standard ANSI C stuff (under default environment)... to generate the .o (object) file

for linking out the binary, you need to link function... from the object file to binary...

for extra libs and / or languages, you may need to specify other include dirs and lib dirs....

you can try by the examples included in the cramfs package - hello dir

the Makefile in fact consists only 2 lines :

object file generation: g++ -c .... -o hello.o hello.cpp
binary file generation: g++ -o ... -o hello hello.o

hope this helps.
[div align=\"right\"][a href=\"index.php?act=findpost&pid=132987\"][{POST_SNAPBACK}][/a][/div]

hm - no cramfs package. Im simply using the devel image by Silvio Iaccatino with a few own enhancements.
Not sure what to configure there, though.
I thought it must be some command line switch for gcc or similar?

daniel
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

miskinis

  • Sr. Member
  • ****
  • Posts: 348
    • View Profile
    • http://
How To Link Statically?
« Reply #3 on: June 27, 2006, 06:54:21 am »
Quote
I thought it must be some command line switch for gcc or similar?
[div align=\"right\"][a href=\"index.php?act=findpost&pid=132993\"][{POST_SNAPBACK}][/a][/div]

Yes, if you have the static libraries (they end in .a) for everything you
are trying to link with, use the "-static" option to gcc.  If you have a
desktop linux machine execute "man gcc" and it will spit out about
8000 lines of information.   Very useful stuff.

Not everything out there provides static object libraries however, recently
on the Zaurus, I found that lesstif (a Motif clone) did not offer a static object
library.

John
_John Miskinis_