Operating System - Linux
1753882 Members
7642 Online
108809 Solutions
New Discussion юеВ

compile C program static, mysql

 
SOLVED
Go to solution
Pohling
New Member

compile C program static, mysql

Hello,

I'm writing a MySql Client for HPUX 11.11.
When I compile it dynamicly it all works fine.
But I need to compile it static because I want to use the same binaries on different systems without installing the mysql-API.
So I tried to compile it this way:

cc -noshared mysql-statement-send.c -o outputBinaary -I'/opt/mysql/include/mysql' -L'/opt/mysql/lib/mysql' -lmysqlclient -lcrypt -lnsl -lm

This is the errormessage I get:
/usr/ccs/bin/ld: Unsatisfied symbols:
shl_load (code)
shl_findsym (code)

How can I avoid this problem?

Thank you,
Matthias
2 REPLIES 2
Peter Nikitka
Honored Contributor
Solution

Re: compile C program static, mysql

Hi,

to create a runnable executable on another system without a mySQL-API installation (does this make sense?), there is no need to link a fully archived version. Just use the shared version of the mysql library and use the default (shared libs) for the rest of the libraries, e.g.:

cc mysql-statement-send.c -o outputBinaary -I'/opt/mysql/include/mysql' -L'/opt/mysql/lib/mysql' -Wl,-a,archive -lmysqlclient -Wl,-a,default -lcrypt -lnsl -lm

mfG Peter
PS: Untested
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Pohling
New Member

Re: compile C program static, mysql

Great!!!
Now it works fine.

Now I understand also the difference between static and dynamic libraries. I always thought, that I have to make them static to get an portable binary but it's all about archives. xD

Matthias Pohling