Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 02 Jul 2015, 04:10
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Vala: compiling without linking; linking later
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message

Joined: 01 Dec 2009
Posts: 3

PostPosted: Tue 01 Dec 2009, 04:50    Post_subject:  Vala: compiling without linking; linking later
Sub_title: linking libraries into the binaries

Is anyone here an expert on linking? I'm pretty new to it (except as it is done automatically).

I'm making a project planned to be GNU GPL licensed, however there are several libraries that are GPL that I want to use. It'll be a lot of hassle for me if people who use my program have to install the libraries separately. The auto-linking at compile time doesn't make them a part of the binary (i.e. it links them dynamically).

So, since I want to make it GPL and release the source, it shouldn't a problem to make it all one binary file (to link them statically). So, how do I do this? I figure I need to use ld or something, but I really have no idea how, especially as valac -c fileName still produces binaries instead of object files.

Also, I don't mind using dynamic linking if I can change the path it searches for the libraries to my program's folder, or a subfolder.
Back to top
View user's profile Send_private_message 

Joined: 02 Apr 2007
Posts: 2380

PostPosted: Tue 01 Dec 2009, 13:22    Post_subject:  

LDFLAGS=-static usually will do the trick if the static libs are indeed present. If when finished, the 'file' utility identifies it as 'satically linked', them you can be sure that everything was linked statically. if even one static lib is not present, then the shard version will be linked in and the finished object will be listed as 'shared object'

To make the linker look somewhere besides the standard locations, use LD_LIBRARY_PATH.
You can create a wrapper script which will start your program(or lib) by renaming the real binary to something like 'proggie-bin'. Then, create a shell wrapper name 'proggie' with something like this in it:
LD_LIBRARY_PATH=/path (to the libs you want to be used)
# and if, needed:

As I said, this trick will even work for using libraries instead of programs, since dynamically-liinked libraries get 'run' just like programs -by being executed by /lib/ld-linux.so.2
Back to top
View user's profile Send_private_message 

Joined: 18 May 2008
Posts: 4519

PostPosted: Thu 10 Dec 2009, 18:41    Post_subject:  

There are a couple things you can do:

for something that looks like this:
gcc -c -o myprogram myprogram.c -lz -L/tmp/myprogram_install/lib -lmystaticlib -lmysharedlib -liberty .....

you can do something like this
gcc -c -o myprogram.o myprogram.c

and later do this
gcc -o myprogram myprogram.o /lib/libz.so /tmp/myprogram_install/lib/mystaticlib.a /usr/lib/mysharedlib.so -liberty .....

this will link in only the libz in /lib
and link in static library mystaticlib.a from /tmp/myprogram_install/lib
and dynamically link shared library /usr/lib/mysharedlib.so (but only if it is in /usr/lib)
and try to find libiberty.so in /lib /usr/lib /usr/local/lib and whatever else is in the library search path (you can add -L/<whatever>/lib to specify additional paths)... if it doesn't find libiberty.so then it will try to find and statically link in libiberty.a

the problem with waiting until install to do this is that the user would need gcc, but using combinations of the above methods it is possible to change things up to do a partial static compile (useful if you do not have all of the *.a files)

Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot attach files in this forum
You can download files in this forum

Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0461s ][ Queries: 11 (0.0041s) ][ GZIP on ]