FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo User

 
 
LinkBack Thread Tools
 
Old 12-13-2009, 06:18 PM
Renat Golubchyk
 
Default Building static libraries

Hi everyone!

I need to build a static binary of a program I wrote. The problem is
that most packages only install dynamic version of the libraries. There
are the "static" and "static-libs" USE flags, but only a tiny fraction
of packages support them. Modifying every relevant ebuild is not really
a viable solution since the list of packages is quite long and could
change later.

So what can I do if I'd like to avoid compiling every package manually?


Cheers,
Renat

--
Probleme kann man niemals mit derselben Denkweise loesen,
durch die sie entstanden sind.
(Einstein)
 
Old 12-13-2009, 07:40 PM
Albert Hopkins
 
Default Building static libraries

On Sun, 2009-12-13 at 20:18 +0100, Renat Golubchyk wrote:
> Hi everyone!
>
> I need to build a static binary of a program I wrote. The problem is
> that most packages only install dynamic version of the libraries.
> There
> are the "static" and "static-libs" USE flags, but only a tiny fraction
> of packages support them. Modifying every relevant ebuild is not
> really
> a viable solution since the list of packages is quite long and could
> change later.
>
> So what can I do if I'd like to avoid compiling every package
> manually?

There is no easy answer to your question. I think because, with a lot of
programs it "just depends". Some packages already include static
libraries (e.g. python and it doesn't make sense to compile the python
package statically because it will break a great many things). Some
programs just weren't designed to be static (e.g. imagemagick or
apache). GTK+, i believe, can't be built statically as it uses dynload
for themes, input methods, etc etc. Even most proprietary gtk-based
software that I know of (e.g. Adobe Flash and VMWare) either are
distributed with GTK+ linked dynamically or they provide their own GTK
libs).

You can apply "-static" to CFLAGS, but make sure you have a binpkg built
first, as there is a chance you may break something. You can also try
passing "--enable-static" to EXTRA_ECONF. That's probably safer than
the former, but the same caveat applies.

Most of the things where static is "useful" and safe already have a
static flag though or provide static libs by default. I think the only
exception I've encountered was e2fsprogs. For that I usually compile my
own static executables.

HTH,
-a
 
Old 12-13-2009, 09:47 PM
walt
 
Default Building static libraries

On 12/13/2009 11:18 AM, Renat Golubchyk wrote:

Hi everyone!

I need to build a static binary of a program I wrote. The problem is
that most packages only install dynamic version of the libraries. There
are the "static" and "static-libs" USE flags...


I'm confused (not unusual). Do you want to create a Gentoo package of
your program that can be added to portage?

USE flags are used only by the Gentoo portage system, not by the compiler
or linker that compiles and links your source code.

If you wrote the program, then you have complete control over the linker
flags (e.g. -static, as Albert mentioned) and those flags usually are
defined in a Makefile (which you create, being the programmer).

I can't be sure, but I think you are confusing Gentoo's USE flags with
gcc's (or ld's) flags, which are entirely different.

Please give more details about what you want to do.
 
Old 12-13-2009, 11:27 PM
Renat Golubchyk
 
Default Building static libraries

On Sun, 13 Dec 2009 15:40:34 -0500
Albert Hopkins <marduk@letterboxes.org> wrote:
> GTK+, i believe, can't be built statically as it uses dynload for
> themes, input methods, etc etc. Even most proprietary gtk-based
> software that I know of (e.g. Adobe Flash and VMWare) either are
> distributed with GTK+ linked dynamically or they provide their own
> GTK libs).

Hmm, I'll test that because I use GTK+ although it is not a GUI app.

> You can apply "-static" to CFLAGS, but make sure you have a binpkg
> built first, as there is a chance you may break something. You can
> also try passing "--enable-static" to EXTRA_ECONF. That's probably
> safer than the former, but the same caveat applies.

Ah, in all the years using Gentoo I have never needed EXTRA_ECONF,
although I've heard a lot about it on this list. It is, of course,
listed in make.conf man page, but since everything works here I usually
do not need to look at it.

Anyway, thanks for the pointer. I'm testing it right now, and it seems
to work so far. I'll report back when emerge is finished.


Cheers,
Renat

--
Probleme kann man niemals mit derselben Denkweise loesen,
durch die sie entstanden sind.
(Einstein)
 
Old 12-13-2009, 11:27 PM
Renat Golubchyk
 
Default Building static libraries

On Sun, 13 Dec 2009 14:47:04 -0800
walt <w41ter@gmail.com> wrote:
> On 12/13/2009 11:18 AM, Renat Golubchyk wrote:
> > I need to build a static binary of a program I wrote. The problem is
> > that most packages only install dynamic version of the libraries.
> > There are the "static" and "static-libs" USE flags...
>
> I'm confused (not unusual). Do you want to create a Gentoo package of
> your program that can be added to portage?
>
> USE flags are used only by the Gentoo portage system, not by the
> compiler or linker that compiles and links your source code.
>
> If you wrote the program, then you have complete control over the
> linker flags (e.g. -static, as Albert mentioned) and those flags
> usually are defined in a Makefile (which you create, being the
> programmer).

As you said, you really are confused. :-) Maybe I wasn't clear enough.
Anyway, I've written a program, and I need it as a statically linked
binary. In order to link statically the linker (ld) needs all the used
libraries in static form, i.e. as a .a and not as a .so file. Since
portage does not build static libraries by default I need a way to tell
portage that I really do want to have .a files built.

I do _not_ want to create a Gentoo package, at least not at this stage
of development.


Cheers,
Renat

--
Probleme kann man niemals mit derselben Denkweise loesen,
durch die sie entstanden sind.
(Einstein)
 
Old 12-14-2009, 12:53 AM
Albert Hopkins
 
Default Building static libraries

On Mon, 2009-12-14 at 01:27 +0100, Renat Golubchyk wrote:
> Since portage does not build static libraries by default...

But portage *does*. I think it does build static libs for packages that
provide them, it's just that I don't think many do (for the reasons I
mentioned in the previous post). In fact:

$ equery l *| while read l; do equery f $l|grep '.a$' |
sed 's/^/'"${l/"/"//} "'-> /' ; done |wc -l

Shows I have 756 static libs on my system (cut off the "|wc -l" to see
what they are).
 
Old 12-14-2009, 01:19 AM
Renat Golubchyk
 
Default Building static libraries

On Sun, 13 Dec 2009 20:53:15 -0500
Albert Hopkins <marduk@letterboxes.org> wrote:

> On Mon, 2009-12-14 at 01:27 +0100, Renat Golubchyk wrote:
> > Since portage does not build static libraries by default...
>
> But portage *does*. I think it does build static libs for packages
> that provide them, it's just that I don't think many do (for the
> reasons I mentioned in the previous post).

That's what I actually meant.


--
Probleme kann man niemals mit derselben Denkweise loesen,
durch die sie entstanden sind.
(Einstein)
 
Old 12-14-2009, 05:28 PM
walt
 
Default Building static libraries

Renat Golubchyk wrote:

> As you said, you really are confused. :-) Maybe I wasn't clear enough.
> Anyway, I've written a program, and I need it as a statically linked
> binary. In order to link statically the linker (ld) needs all the used
> libraries in static form, i.e. as a .a and not as a .so file. Since
> portage does not build static libraries by default I need a way to tell
> portage that I really do want to have .a files built.
>
> I do _not_ want to create a Gentoo package, at least not at this stage
> of development.

Still confused (

Portage is for building Gentoo packages -- if you don't want to build a
Gentoo package then why is portage involved? You can compile and link
your program with any flags you want to, so as to get static binaries.
 
Old 12-14-2009, 07:19 PM
Allan Gottlieb
 
Default Building static libraries

At Mon, 14 Dec 2009 10:28:21 -0800 walt <w41ter@gmail.com> wrote:

> Renat Golubchyk wrote:
>
>> As you said, you really are confused. :-) Maybe I wasn't clear enough.
>> Anyway, I've written a program, and I need it as a statically linked
>> binary. In order to link statically the linker (ld) needs all the used
>> libraries in static form, i.e. as a .a and not as a .so file. Since
>> portage does not build static libraries by default I need a way to tell
>> portage that I really do want to have .a files built.
>>
>> I do _not_ want to create a Gentoo package, at least not at this stage
>> of development.
>
> Still confused (
>
> Portage is for building Gentoo packages -- if you don't want to build a
> Gentoo package then why is portage involved? You can compile and link
> your program with any flags you want to, so as to get static binaries.

Portage is also for (indeed, is primarily used for) fetching and
installing Gentoo packages. The OP wants portage to install the
statically linked version of libraries for which it currently installs
only the dynamically linked versions.

allan
 
Old 12-14-2009, 07:25 PM
Alan McKinnon
 
Default Building static libraries

On Monday 14 December 2009 20:28:21 walt wrote:
> Renat Golubchyk wrote:
> > As you said, you really are confused. :-) Maybe I wasn't clear enough.
> > Anyway, I've written a program, and I need it as a statically linked
> > binary. In order to link statically the linker (ld) needs all the used
> > libraries in static form, i.e. as a .a and not as a .so file. Since
> > portage does not build static libraries by default I need a way to tell
> > portage that I really do want to have .a files built.
> >
> > I do _not_ want to create a Gentoo package, at least not at this stage
> > of development.
>
> Still confused (

Yes, I'm not surprised. you read the OPs post upside down. He does not want to
*generate* static binaries, he wants to *use* them. Presumably he has written
an app (that possibly must be distributed as a contained unit) that must
statically link the libs it uses. Those libs would have been put there by
portage, but he needs portage to build .a's, not only .so's
>
> Portage is for building Gentoo packages -- if you don't want to build a
> Gentoo package then why is portage involved? You can compile and link
> your program with any flags you want to, so as to get static binaries.

OP,

I'm not sure why you have a problem. A quick search on my box shows that most
libs (of the small number I checked) have .a and .so

Please post emerge --info and details of which libs you know at this point you
do need.

--
alan dot mckinnon at gmail dot com
 

Thread Tools




All times are GMT. The time now is 01:11 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org