mysql++编译问题解决(转)

来源:互联网 发布:mac照片隐藏怎么显示 编辑:程序博客网 时间:2024/05/22 17:12

mysql++-2.1.1.tar.gz

安装步骤:
1
make clean
2
./configure
3
su
4
make
5
make install
6
ln -s /usr/local/lib/libmysqlpp.so /usr/lib/libmysqlpp.so

6步很关键,建立符号连接,否则运行程序将出现如下错误:

./test: error while loading shared libraries: libmysqlpp.so: cannot open shared object file: No such file or directory

此处步骤占去了整个过程99%的时间。

Makefile:
这个文件临时写的,可以简化,请高手不要见笑。

test:test.o
   g++ test.o -o test -L/usr/lib/mysql -lmysqlclient -lmysqlpp
test.o:test.c
   g++ -c test.c -I/usr/include/mysql -I/usr/local/include/mysql++
.PHONY:clean
clean:
   -rm -f *.o test   

测试代码:
test.c
#include <iostream>
#include <mysql++.h>

using namespace std;

int main()
{
   cout<<"hello"<<endl;

 getchar();
   return 0;

}

如果还是不行,查看/etc/ld.so.conf文件,看是否包含了/usr/local/libmysql++lib文件夹),如果没有,就加上,然后执行ldconfig

或者将/usr/local/lib 加入LD_LIBARAY_PATH , 可以echo $LD_LIBRARY_PATH看一看,source下。

编译(注意格式和包含的内容):

g++ -Wno-deprecated -L/usr/lib/mysql -lmysqlclient -L/usr/local/lib -lmysqlpp -Ilib -I/usr/include/mysql -I/usr/local/include/mysql++ -o test test.c


如果能够编译成功,且不出现运行错误。

则下一步可进行数据库的各种操作了。

原创粉丝点击