How to install static libraries for compilation

General support questions
Post Reply
afalanga
Posts: 96
Joined: 2013/01/31 00:29:05

How to install static libraries for compilation

Post by afalanga » 2013/01/31 14:41:06

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

afalanga
Posts: 96
Joined: 2013/01/31 00:29:05

Re: How to install static libraries for compilation

Post by afalanga » 2013/01/31 16:17:43

[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.

deirfto
Posts: 1
Joined: 2014/11/18 17:11:28

Re: How to install static libraries for compilation

Post by deirfto » 2014/11/18 17:18:06

Code: Select all

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

Post Reply