Page 1 of 1

How to install static libraries for compilation

Posted: 2013/01/31 14:41:06
by afalanga
Hi everyone,

My project must link statically, its a requirement, and there are two libraries that don't appear on my installation of CentOS. These are pthread and rt. Which yum package, or whatever, do I need to install them?

My project build line looks something like this:
g++ -g -static -I -lpthread -lrt -o

I found in /usr/local that instead of libpthread.a, I have libpthread_nonshared.a. From a command line, if I change -lpthread to -lpthread_nonshared the build works for that library, but it fails for -lrt. I did some poking around /usr/lib and there is no librt.a at all. I found a symlink pointing to the shared object file /lib/librt.so.1, but no static object files for linking. I actually have two questions:

1) How do I install the static library for rt?
2) Because others may need to build on different linux systems, is it sound to set a symlink in /usr/lib for pthread: i.e. /usr/lib/libpthread.a --> /usr/lib/libpthread_nonshared.a? Or, does this lead me to "dire" consequences?

Thanks for any help.

Andy

Re: How to install static libraries for compilation

Posted: 2013/01/31 16:17:43
by afalanga
[quote]
afalanga wrote:

1) How do I install the static library for rt?
2) Because others may need to build on different linux systems, is it sound to set a symlink in /usr/lib for pthread: i.e. /usr/lib/libpthread.a --> /usr/lib/libpthread_nonshared.a? Or, does this lead me to "dire" consequences?

[/quote]

Wow, it took some doing (a couple of hours of searching) but I finally figured out that the package I needed was glibc-static.xxxxxxx. Figuring out how to use the yum program was among the more difficult steps. (Having been out of linux for ~5 years hasn't helped 1 bit ... a very sad day when my company transitioned to Windows). In the process, I discovered that this one glibc static package contained both the static versions of the runtime and the pthread library. So, I've effectively answered both questions. Making a symlink to libpthread_nonshared.a was *not* a good idea (the two files: libpthread_nonshared.a and libpthread.a are quite different).

Hopefully, if someone else has this same question, my little thread here will help.

Re: How to install static libraries for compilation

Posted: 2014/11/18 17:18:06
by deirfto

Code: Select all

 yum install glibc-static  
solved my problem of a missing static pthread library. :D Thanks for writing this thread.