![]() |
| | #1 |
| Wannabe Coding God Join Date: Mar 2003
Posts: 259
| Compiling Library Into Program. I have some memory of you being able to link a library statically if you want to make sure that the program runs on other computers, even if they do not have the library they use installed. I have searched google, the forums and the gcc website, but I can't find out how this is done, so I'm simply asking: if this is possible and if it is how you do it?
__________________ They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows. |
| Shogun is offline | |
| | #2 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,630
| Read the manual on the linker (ld) Read about the "-static" linker option |
| Salem is offline | |
| | #3 |
| Wannabe Coding God Join Date: Mar 2003
Posts: 259
| so I should for example use: Code: ld -llib -static -o test.o
__________________ They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows. |
| Shogun is offline | |
| | #4 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,630
| The manual page suggests that -static should be earlier on the command line |
| Salem is offline | |
| | #5 |
| Wannabe Coding God Join Date: Mar 2003
Posts: 259
| so Code: ld -static -o test.o -llib so the "-llib" is in the [file....] in the: Code: ld [ option ... ] [ file ... ]
__________________ They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows. |
| Shogun is offline | |
| | #6 |
| Obsessed with C Join Date: Jan 2003
Posts: 501
| You are right, but why don't use just link allowing gcc to pass the linker the options, such as this Code: gcc -static test.c -o test -lblah http://www.advancedlinuxprogramming....x-software.pdf
__________________ Help populate a c/c++ help irc channel server: irc://irc.efnet.net channel: #c |
| chrismiceli is offline | |
| | #7 |
| Wannabe Coding God Join Date: Mar 2003
Posts: 259
| When I try this I get the following: Code: ld: can't locate file for: -lcrt0.o I have now made a sarch for "crt" and I found crt1.o and crt2.o but no crt0.o, is this important and how do I fix it?
__________________ They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows. Last edited by Shogun; 11-30-2004 at 07:45 AM. |
| Shogun is offline | |
| | #8 |
| Obsessed with C Join Date: Jan 2003
Posts: 501
| Take off the .o in the -l part, like this Code: gcc -o file file.c -lblah /*not*/ gcc -o file file.c -lblah.o
__________________ Help populate a c/c++ help irc channel server: irc://irc.efnet.net channel: #c |
| chrismiceli is offline | |
| | #9 |
| Wannabe Coding God Join Date: Mar 2003
Posts: 259
| I don't have the .o in the library, I'm not even calling it,no clue where it came from, I search my SDK when I saw the message and I don't have that very library but I have crt1 and crt2...
__________________ They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows. |
| Shogun is offline | |
| | #10 |
| Wannabe Coding God Join Date: Mar 2003
Posts: 259
| I made some more searching and I found the following: guess I can't link stuff statically.. I wounder if there is any other way to do it, I'll have to do some more lookin around...
__________________ They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows. |
| Shogun is offline | |
| | #11 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,630
| Driving the linker directly sucks, there is too much to get right. If you really want to know, just compile a small program with the -v option, and see how complex a linker command line can be. This works just fine here Code: $ gcc generic.c && ls -l a.out && file a.out -rwxrwxr-x 11586 Nov 30 19:28 a.out a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), not stripped $ gcc generic.c -static && ls -l a.out && file a.out -rwxrwxr-x 447193 Nov 30 19:28 a.out a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped |
| Salem is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help Needed with Compiling C program | girishaneja | C Programming | 2 | 05-20-2009 08:10 AM |
| Client-server system with input from separate program | robot-ic | Networking/Device Communication | 3 | 01-16-2009 03:30 PM |
| Stray Error while compiling | Mankthetank19 | C Programming | 4 | 12-02-2008 05:55 AM |
| compiling a program that has no configure script | serfurj | Linux Programming | 9 | 02-09-2005 10:53 AM |
| Help compiling a program | jjj93421 | C++ Programming | 1 | 03-08-2004 06:38 PM |