MySQL and C Applications

When creating an application that accesses the MySQL database on Linux using C / C ++, I have to dynamically link to the mysql client library. Is there a way by which I can statically link the application so that the mysql client libraries are no longer needed?

What is the best practice regarding developing C \ C ++ to include fairly long queries in an application, but outside the code? Using stored procedures is not possible because the database runs on a MySQL 4 server.

+3
source share
2 answers

It should be easy to create static mysql client libraries. If you downloaded the source code, you just need to configure it accordingly:. / configure --enable-static This should build libmysql / libmysqlclient.a (or perhaps libmysql / .libs / libmysqlclient.a), which should be easy to statically link to your executable.

You will need your executable file, which will be licensed in the GPL, or you will need to buy the appropriate license from MySQL users.

+1
source

The following compiling command line helped me statically link mysql client libraries:

gcc -I/usr/include/mysql -c mysql.c
gcc -o mysql mysql.o -static -lmysqlclient -static-libgcc -lm -lz -lpthread

, . , , glibc, .

/usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../lib/libmysqlclient.a(mf_pack.o): In function `unpack_dirname':
(.text+0x6cc): 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.2.4/../../../../lib/libmysqlclient.a(libmysql.o): In function `read_user_name':
(.text+0x5ed7): 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.2.4/../../../../lib/libmysqlclient.a(mf_pack.o): In function `unpack_dirname':
(.text+0x6e1): 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.2.4/../../../../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.2.4/../../../../lib/libmysqlclient.a(libmysql.o): In function `mysql_server_init':
(.text+0x695d): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
0

Source: https://habr.com/ru/post/1699413/


All Articles