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 Wed 16 Apr 2014, 06:40
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Need examples of static compiling of various apps.
Post new topic   Reply to topic View previous topic :: View next topic
Page 4 of 4 [57 Posts]   Goto page: Previous 1, 2, 3, 4
Author Message
Ibidem

Joined: 25 May 2010
Posts: 428
Location: State of Jefferson

PostPosted: Tue 05 Jun 2012, 00:05    Post subject:  

sunburnt wrote:

0 ) Is it correct that none of these Cs will run apps. made on the other ones?
___ This could be a really serious problem for portable apps. ( hope not...)

Basically correct. Also largely irrelevant.
Almost every desktop linux (but not DeLi, pupngo, alpine, sabotage, a few other rarely used distros, or android) uses glibc2/libc6 or eglibc (a fork of glibc that's fully compatible)

musl is currently (0.9.1) working on LSB ABI support, which means a degree of interoperability with glibc.

uclibc doesn't even retain compatibility across versions (binaries built with 0.9.29 won't run on 0.9.30).

HOWEVER, if you compile statically (-static or -Bstatic), you can build one program and run it on just about any machine of the same architecture. You do not need ANY C library installed to run a static binary.

Quote:

1 ) "-nostdinc -I..." used only in CFLAGS and "-nostdlib -L..." in LDFLAGS ?
___ This seems to be a very critical piece of info...

I would use -nostdinc -I... in CFLAGS & CPPFLAGS; -nostdlib -L... would go in CFLAGS & LDFLAGS
This is because I've seen several subtly broken build systems that used gcc $CFLAGS for linking, or ran a preprocessor that ignored CFLAGS, or ignored CPPFLAGS altogether...
Quote:

2 ) To use -nostdinc or -nostdlib means all "ldd" lib. deps. are needed?

Yes, including -lc
Quote:

3 ) Used alone, -L locations are searched before the system`s lib. paths are?

Yes, as long as they come before the libraries that are searched for.
IIRC, gcc .... -L./ -labc would find ./libabc.a, while -labc -L./ would not.
If you had ./libm.so, the first pattern would link against it, while the second pattern would use /lib/libm.so

Quote:

4 ) -D(symbol) , but how to know what potentially unneeded items there are?

In advance? Find someone else's build scripts or read the source code.
It's simplest to try building, then look up whatever stops the build.
Quote:

5 ) -static is used with make? Need a clear picture of what it does exactly.

When using make or any normal build system,
Code:
export CFLAGS="-static $CFLAGS"

before configuring or building.
CFLAGS is extra options (flags) for the C compiler to use.
With a simple make-based build system,
make CFLAGS=-static
should be enough.

I'll try giving a simple example:
If compiling with gcc,
Code:
gcc -Os -static -D_XOPEN_SOURCE minimp3.c  -lm -o minimp3
will/"should" compile minimp3 fully static.
In other words, only .a libraries are searched for symbols/functions *; any code that the program needs will be linked into the binary. When I say linked into, I mean that the object files become part of the statically linked program/app/binary.
Dynamically linked (using shared libraries/ .so files) programs just request at runtime that the .so file be put in RAM with its code available for anything to call. Sometimes "linked into" is used to refer to this, but it doesn't quite fit what's happening.

(*it may fallback to shared libraries, according to technosaurus)
Quote:

6 ) Using downloaded .so files. is a gamble. Is there a good way to do it?



Quote:

7 ) The advantage to .a files is they compile with and into the app.?
___ Possible at the same time to compile .so files with and into the app.?

Not clear what you mean compile with and into.
Do you mean "Will running
Code:
make
produce the .so files and an app linked against them at the same time " ?

If so: yes

Long answer: a .so file contains code that is not included in the binary (app) linked against it. So no, it is not linked into the app.

Quote:

8 ) Method to make complete tree files for app. cataloging and statistics?
___ There`s no way to do this for uncompiled apps.? Need working app.?

### This is for "relatively" self contained Squash file apps.
# Target is: ./configure --prefix=/SqApp/mnt/( AppPackageNameNoExt.)

I'm guessing this would be like
Code:
make install DESTDIR=../pkg-temp
?
(if I understand correctly)
DESTDIR makes it install as if DESTDIR were /
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4978
Location: Arizona, U.S.A.

PostPosted: Tue 05 Jun 2012, 14:35    Post subject:  

Wow! Thanks Ibidem; Succinct answers, what a great tutorial.

1) So this answers the static Q, it includes the C lib. in with the binary.

4) Yep, that`s the conclusion I`ve come to. Let the errors fly, it`s the easy way.

6) I`ve found that Ubuntu Lucid libs. work well in Puppy Lucid. Same base.

7) Correct, the ".so" libs. and app. binaries are built together. And dyn. linked.

I want tree files as manifest files to track files and deps. in a build.
____ I found ldd-recursive.pl and it s great, I wrote one also but this is better.

So gathering source libs. into a dir. as they`re needed will make a large enough
lib. base that eventually only the apps. + other deps. will need to be downloaded.
Time to clear a little hd space and gather more apps.

Again many thanks... Terry B.

Last edited by sunburnt on Tue 05 Jun 2012, 16:58; edited 1 time in total
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4133

PostPosted: Tue 05 Jun 2012, 16:47    Post subject:  

when doing a static build it does not include the entire library (though it may as well be with gnu libc) only the required symbols (basically the needed functions and data) - but sometimes the compiler has a difficult time telling which are really needed. Fortunately there _are_ a couple of helper flags for this.
Recent versions of gcc use -flto (and others releated to it), but it is not supported in puppy; however you can use -ffunction-sections -fdata-sections in CFLAGS and -Wl,--gc-sections in LDFLAGS so long as the app does not use plugins (if a function is only used in a plugin or only called from an XML UI file then the linker can't see it and will discard the symbol)

ldd is "recursive" too, so I am not sure how a perl script helps except for different formatting

use ldd <binary> to know _all_ dependencies - this is what static libs you need for building that binary.

use objdump -x <binary> | grep NEEDED to know only the direct dependencies - this is what minimum shared libs you will need
If you tell gcc to link to any additional libraries and do not include the --as-needed LDFLAG, then a recompile of a library or an indirect dependency such as libxcb can and often will break the app - relying on packages' makefiles and configure scripts will cause this issue 99% of the time and sometimes --as-needed can cause an issue (particularly in apps that can use plugins) If --as-needed won't work there is a hack you can get away with most of the time. Delete the binary and run a verbose make again - then copy the gcc command (or deduce it from the crappy libtool command) and just remove the unneeded libs
For gtk1 apps, you can remove -lglib -lgdk etc.. because just doing -lgtk will automatically take care of all of its dependencies and have the side effect of being significantly smaller due to not storing the locations of symbols in the indirect dependencies which has the additional side effect that when those symbols change, it doesn't break the binary (see numerous issues with xcb and the broken behavior of linking directly to it instead of just -lX11 because of pkgconfig shortcomings).

another note on this is that quite often you will see one library linked multiple times (especially X11) - this is often unnecessary and can reduce binary size by removing additional instances and changing the order that the -l<libs> appear (hint the proper order is related to the dependency chain).

there is one other thing you may want to know about when trying to package a standalone app - the other files that it uses such as config files and resources like fonts, images or UI files. This can be accomplished by running lsof (not included in puppy, but configurable in recent versions of busybox)

Some tips specifically for building static _binaries_:
see --gc-sections above (savings between 20 and 80%)
objects in .a archives that will be used for static linking _binaries_ (a.k.a. static libs) should not be built with -fpic or -fPIC (savings of up to 5%)
The symbols will not need to be visible at all, since the user will only directly be calling main, so you can use -fvisibility=hidden in your CFLAGS. This also reduces the size of the elf headers, GOT, etc... as much as 20%
Note: if they will be used for building into libraries, ignore all but the --gc-sections part (very uncommon, - I tried it with GTK2, but its build system fought me too much)

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4978
Location: Arizona, U.S.A.

PostPosted: Tue 05 Jun 2012, 17:25    Post subject:  

Wow again! Thanks technosaurus; This really gives learned detail to it all.
I`ll have to reread it as I go through the steps myself.

I looked at the 2 outputs from ldd and ldd-recursive.pl
It looks like you`re right that ldd does give a binary`s deps. and the dep`s. deps.
I thought it just output the binary`s deps. only, leaving out a bunch of lib. deps.

ldd-recursive.pl outputs the tree with lots of duplicate libs.
A line count for the 2 outputs:
Code:
sh-4.1# ldd /mnt/sdb3/ubuntu_apps/lbreakout2_2.6.1/usr/bin/lbreakout2 |wc -l
19
sh-4.1# ldd-recursive.pl /mnt/sdb3/ubuntu_apps/lbreakout2_2.6.1/usr/bin/lbreakout2 |wc -l
840

As I said, most of the 840 dep. lines are dups., but it outputs a complete dep. tree.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4133

PostPosted: Tue 05 Jun 2012, 21:42    Post subject:  

To answer a previous question, it is perfectly legitimate to mix static and shared libs. Check the Gparted thread that ttuuxxx and I had a couple years back, all of the gtkmm related libs are built-in statically (barry does this too, but his static libs aren't optimized for it). Usually this is done on direct dependencies only, but occasionally an indirect dependency sneaks in statically because the .so symlink is unintentionally missing from the devx.
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4978
Location: Arizona, U.S.A.

PostPosted: Tue 05 Jun 2012, 23:21    Post subject:  

Amazingly I`m actually starting to understand ( I think...) most of the conversations.

We always tend to complicate things when we`re new to them.
I understand this and attempt to look at it simply, but it usually doesn`t help.

Experience is the best teacher ( but a rough one...), I need to get my game on.
Then I`ll have a whole new list of Qs, but they`ll come from actual problems.

Thanks technosaurus, Ibidem, jpeps, penguinpowerppp, and all who helped.
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4978
Location: Arizona, U.S.A.

PostPosted: Wed 06 Jun 2012, 01:34    Post subject:  

### Guys, Qs...


### Q #1

Upon running an app. it errors:

The package file:LLK_DATA_PATH/pak/Classical does not exists.

# There is this file: share/llk_linux/Classical.pak

It seems this is what it`s looking for, but the /path/file is wrong.

# How do I set LLK_DATA_PATH, or supply the missing file?


### Q #2:

I`ve gotten this error from a few apps. I`ve tried:

/mnt/sdb3/ubuntu_apps/usr/games/pinball: /usr/lib/libjpeg.so.62: no version information available (required by /root/my-applications/lib/libSDL_image-1.2.so.0)

Lib`s. there, but it doesn`t like it for some reason.
Back to top
View user's profile Send private message 
Ibidem

Joined: 25 May 2010
Posts: 428
Location: State of Jefferson

PostPosted: Thu 07 Jun 2012, 03:35    Post subject:  

sunburnt wrote:
### Guys, Qs...


### Q #1

Upon running an app. it errors:

The package file:LLK_DATA_PATH/pak/Classical does not exists.

# There is this file: share/llk_linux/Classical.pak

It seems this is what it`s looking for, but the /path/file is wrong.

# How do I set LLK_DATA_PATH, or supply the missing file?


### Q #2:

I`ve gotten this error from a few apps. I`ve tried:

/mnt/sdb3/ubuntu_apps/usr/games/pinball: /usr/lib/libjpeg.so.62: no version information available (required by /root/my-applications/lib/libSDL_image-1.2.so.0)

Lib`s. there, but it doesn`t like it for some reason.

1: Check with strace (strace ... 2>&1 |grep /pak/)
If it's a variable, try export ...

2:No idea...except that you should see how LD_LIBRARY_PATH=/mnt/... works
Back to top
View user's profile Send private message 
jamesbond

Joined: 26 Feb 2007
Posts: 1872
Location: The Blue Marble

PostPosted: Thu 07 Jun 2012, 04:28    Post subject:  

sunburnt wrote:

### Q #2:

I`ve gotten this error from a few apps. I`ve tried:

/mnt/sdb3/ubuntu_apps/usr/games/pinball: /usr/lib/libjpeg.so.62: no version information available (required by /root/my-applications/lib/libSDL_image-1.2.so.0)

Lib`s. there, but it doesn`t like it for some reason.

This should not stop the app from running. The message is just a warning that means libjpeg in your system is built differently from the one used to compile pinball. See here and here.

_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13
Back to top
View user's profile Send private message 
muggins

Joined: 20 Jan 2006
Posts: 6666
Location: lisbon

PostPosted: Thu 07 Jun 2012, 09:39    Post subject:  

Re: Q1, if you download the compiled llk_linux-2.0.tar.gz it will give that error as the binary has been compiled to look for the wav & .pak files in /usr/local/llk_linux/pak directory.

If I run turma on the extracted tarball directory, it shows the binary has only one reference to /usr/local/llk_linux.
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4978
Location: Arizona, U.S.A.

PostPosted: Fri 08 Jun 2012, 15:39    Post subject:  

Thanks again Ibidem; I know Tiny Core`s SCM files use LD_... to fix paths.

Thanks jamesbond; The links you gave verified that it`s not critical.
It`s the only error reported in some of the apps. I`ve made.
Obviously the best solution is to find the correct lib.

And thanks muggins; I`ll look into fixing that path, but what about the file?

It doesn`t seem to be a config. file that`s generated.
And I don`t think I missed downloading a Data pak. file for it.

# Maybe a link: local/llk_linux/pak/Classical => share/llk_linux/Classical.pak ?

I couldn`t figure out what path it wanted, how did you find it?. With Turma?

I need to make a SqApp of Turma, do you have a .pet or SFS file?
Back to top
View user's profile Send private message 
muggins

Joined: 20 Jan 2006
Posts: 6666
Location: lisbon

PostPosted: Sat 09 Jun 2012, 02:43    Post subject:  

Yes, I used turma. I'm also not sure where the path is being set but, if you ran ./configure --prefix=/usr then, before running make, you could try running turma to see if there are any instances of /usr/local and, if there are, change them to /usr.

gtk1-based turma is in the puppy ibiblio repository for the pre-gtk2 base pups. Or, if you want to try gtk2-based turma2, just do a forum search of the additional software section.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 4 of 4 [57 Posts]   Goto page: Previous 1, 2, 3, 4
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1011s ][ Queries: 12 (0.0053s) ][ GZIP on ]