mysql header file dir : /usr/local/mysql/include/mysql
mysql library file dir : /usr/local/mysql/lib/mysql
$ uname -a
Linux linux 2.4.22 #1 Mon Mar 22 16:01:12 KST 2004 i686 unknown
$ mysql --version
mysql Ver 11.18 Distrib 3.23.57, for pc-linux (i686)
$ cat connect.c
#include <stdio.h>
#include <mysql.h>
int main() {
MYSQL sql;
mysql_init(&sql);
if (!mysql_real_connect(&sql, NULL, "db_user", "db_pw", NULL, 3306, (char*)NULL, 0)) {
printf("Connect is fail -.-;;;;;;;\n");
exit(100);
} else {
printf("Connect is success ㅋㅋㅋ !!!\n");
}
mysql_close(&sql);
return 0;
}
^D
$ gcc -o connect connect.c -I/usr/local/mysql/include/mysql -L/usr/local/mysql/lib/mysql -lmysqlclient
$ echo $?
0
$ ./connect
/home/xxx/src/c++/connect: error while loading shared libraries:
libmysqlclient.so.10: cannot load shared object file: No such file or
directory
$ ls -l /usr/local/mysql/lib/mysql
...
lrwxrwxrwx 1 root mysql 24 Aug 18 2003 libmysqlclient.so -> libmysqlclient.so.10.0.0*
lrwxrwxrwx 1 root mysql 24 Aug 18 2003 libmysqlclient.so.10 -> libmysqlclient.so.10.0.0*
-rwxr-xr-x 1 root mysql 169525 Aug 18 2003 libmysqlclient.so.10.0.0*
...
$
Oh, Shit !!!!!!!!!!!!
| Posted by Richard Adams on February 3 2004 7:02am | [Delete] [Edit] |
If you are learning to use the c API and your
executable produces an error like "ld.so.1: test: fatal:
libmysqlclient.so.12: open failed: No such file or directory"
then you need to set the environment variable $LD_LIBRARY_PATH to read the shared library file. E.g., for csh /tcsh
setenv LD_LIBRARY_PATH /opt/gnu/lib:/export/local/mysql/lib/mysql
$ cd ~
$ vi . .bash_profile
...
LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql
...
export LD_LIBRARY_PATH
:wq
$ . .bash_profile
$ cd ~/src/c++
$ gcc -o connect connect.c -I/usr/local/mysql/include/mysql -L/usr/local/mysql/lib/mysql -lmysqlclient
$ ./connect
Connect is success ㅋㅋㅋ !!!
$
///////////////////////////////////////////////////////
Attention !!!
The 'connect' that executable file's owner is xxx, and use shared library. Because of user xxx set environment variable, the variable 'LD_LIBRARY_PATH' will be loading, while system init process is begining.
This mean that execute file only user xxx can be running.
If other user execute this file, you will suffer a -.- like me in runtime...

댓글을 달아 주세요