I'm using Lua, mysqlclient and boost. Static linking with boost goes
fine, but when I try to link Lua and mysqlclient I get the following
warnings:
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/liblua5.1.a(loadlib.o):
In function `ll_loadfunc':
(.text+0xa7c): warning: Using 'dlopen' in statically linked applications
requires at runtime the shared libraries from the glibc version used for
linking
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/libmysqlclient.a(mf_pack.o):
In function `unpack_dirname':
(.text+0x75b): warning: Using 'getpwnam' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/libmysqlclient.a(libmysql.o):
In function `read_user_name':
(.text+0x6081): warning: Using 'getpwuid' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/libmysqlclient.a(mf_pack.o):
In function `unpack_dirname':
(.text+0x76a): warning: Using 'endpwent' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/libmysqlclient.a(ssl.o):
In function `yaSSL::read_file(yaSSL::SSL_CTX*, char const*, int,
yaSSL::CertType)':
(.text+0x29f3): warning: memset used with constant zero length
parameter; this could be due to transposed parameters
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/libmysqlclient.a(my_gethostbyname.o):
In function `my_gethostbyname_r':
(.text+0x3c): warning: Using 'gethostbyname_r' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/libmysqlclient.a(libmysql.o):
In function `mysql_server_init':
(.text+0x6b22): warning: Using 'getservbyname' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
I build my program using g++:
g++ *.cpp -static -o output -I/home/src -I/usr/include/mysql
-I/usr/include/lua5.1 -llua5.1 -ldl -ldlm -lmysqlclient -lssl -lz
-lcrypt -lnsl -lm -lboost_program_options-mt -lboost_thread-mt
-lboost_system-mt -lpthread
Is it possible to build it statically? Can you give me some advise?
Regards,
Vanier
> Is it possible to build it statically? Can you give me some advise?
No, it's impossible. Here are some reasons why it's impossible:
1) Your code uses 'dlopen'. How can a statically-linked program call
into the dynamic linker that it doesn't have?
2) Your code uses 'gethostbyname_r'. What happens when you run a
program that uses a host naming scheme that's not on the machine you
compile on? How will your code contain statically the correct
function?
3) Your code calls 'getpwuid'. What if your code runs on a system that
uses some bizarre scheme to get uid mappings (they might use LDAP,
they might use Kerberos, they might use anything at all). How can your
program contain the code to do that now -- that scheme may not even
exist yet.
Your program will compile and will run. But if you ever call into the
listed functions, they may fail or provide incorrect results.
DS
Thanks for quick answer. So what is the best solution now to
port my application to other machines, as it would be quite
difficult for different users to install Lua and other
libraries on their machines on their own. Is it the only way
to link it dynamically or to distribute source for other
people, so that they will build application themselves?
Regards,
Vanier
Hello!
If you want to simplify installation process you can include
1) application binary
2) "hard-to-build" libraries (boost, lua, libmysqlclient) and (if you
use another gcc version) libstdc++ and libgcc_s.
in the distribution tarball.
The only thing users have to do is to unpack the tarball and set some
environment variables (PATH, LD_LIBRARY_PATH).
Your application will use system libraries (libpthread.so, libc.so, etc)
provided by users system and application-specific libraries provided by you.
I don't know any problems with this approach (are there any?).
It works fine for me.
Many of my C++ programs are distributed with
* boost libraries
* ACE library
* ICU library
* libstdc++ and libgcc_s (because I use newer gcc than target systems
usually have).
If you do have some static library, you can of course link-edit it
statically with your executable.
A static library is just an archive of .o, so you can link with it as
you would link with your own object files.
Howevera, as indicated by David, your executable will still be a
dynamically linked one, since it depends also on dynamic system
libraries.
--
__Pascal Bourguignon__
> Thanks for quick answer. So what is the best solution now to
> port my application to other machines, as it would be quite
> difficult for different users to install Lua and other
> libraries on their machines on their own. Is it the only way
> to link it dynamically or to distribute source for other
> people, so that they will build application themselves?
>
You may statically link some libraries and dynamically link other libraries.