Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Static linking of libraries

23 views
Skip to first unread message

Paulo Matos

unread,
Mar 21, 2006, 5:03:11 AM3/21/06
to
Hi all,

I'm using gentoo linux and I have a program in C++, built with
autotools, that links to log4cpp and glpk. However, when I move the
binary if I don't have this libraries there the binary won't run since
the linking was done dinamically. How can I do static linking?

Cheers,

Paulo Matos

Paulo Matos

unread,
Mar 21, 2006, 8:21:04 AM3/21/06
to

Found the -static flag... Hope it does the trick! :)

> Cheers,
>
> Paulo Matos

Paul Pluzhnikov

unread,
Mar 21, 2006, 10:07:36 AM3/21/06
to
"Paulo Matos" <pocm...@gmail.com> writes:

> Found the -static flag... Hope it does the trick! :)

This is *the* wrong way to solve this problem.
Your binary may crash and/or not work correctly when moved to a
different machine.

See this thread for gory details:
http://groups.google.com/group/comp.os.linux.development.apps/browse_frm/thread/f664f8f7c19a4a7b

Correct way to ensure that you don't depend on dynamic versions of
log4cpp and glpk, while still making your binary portable to other systems:

g++ ... -o myapp mayapp.o ... -Wl,-Bstatic -llog4cpp -lglpk -Wl,-Bdynamic

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.

0 new messages