Chinaunix
标题:
求助:shared library (急)
[打印本页]
作者:
jianfenghong
时间:
2005-01-14 17:58
标题:
求助:shared library (急)
#include <iostream>;
#include <mysql++.h>;
#include <connection.h>;
using std::cout;
using std::endl;
using namespace mysqlpp;
int main(int argc, char **argv)
{
try
{
Connection conn("mysql", "localhost", "root", ""
;
cout << conn.client_info() << endl;
cout << conn.host_info() << endl;
cout << conn.server_info() << endl;
cout << conn.stat() << endl;
cout << "-------------------------------" << endl;
Query query = conn.query();
query << "select host, user from user";
cout << query.preview() << endl;
Result res = query.store();
Result::iterator pos;
Row row;
for (pos = res.begin(); pos != res.end(); ++pos)
{
row = *pos;
cout << row[0] << '\t' << row[1] << endl;
}
conn.close();
}
catch (std::exception &e)
{
cout << e.what() << endl;
}
return 0;
}
这是用mysql++包访问mysql数据库的程序,程序名xaa.cpp
mysql数据库自带:
头文件:
/usr/include/mysql
库:
/usr/lib/mysql
mysql++包:
头文件:
/usr/local/include
库:
/usr/local/lib
编译、链接命令为:
g++ -I/usr/include/mysql -I/usr/local/include -c xaa.cpp
g++ -L/usr/local/lib -lmysqlpp -L/usr/lib/mysql -lmysqlclient xaa.o -o xaa
编译、链接都成功。
执行时失败,提示以下信息:
xaa: error while loading shared libraries: libmysqlpp.so.4: cannot open shared object file: No such file or directory
在/usr/local/lib目录下有libmysqlpp.a libmysqlpp.la libmysqlpp.so.4.0.0 libmysqlpp.so(符号链接) libmysqlpp.so.4(符号链接),为什么程序执行还会失败?
如果链接命令改为:libtool --mode=link --tag=CXX g++ -o xaa xaa.o /usr/local/lib/libmysqlpp.la,则程序可以正常执行。
如果改为静态链接 g++ -static -L/usr/local/lib -lmysqlpp -L/usr/lib/mysql -lmysqlclient xaa.o -o xaa,为什么链接不成功?
作者:
精简指令
时间:
2005-01-14 18:26
标题:
求助:shared library (急)
将/usr/local/lib 加入LD_LIBARAY_PATH
作者:
jianfenghong
时间:
2005-01-14 18:59
标题:
求助:shared library (急)
还是不行啊!
作者:
kj501
时间:
2005-01-14 19:26
标题:
求助:shared library (急)
看看/etc/ld.so.conf是否包含了/usr/local/lib,如果没有,就请加上,然后执行ldconfig。
作者:
精简指令
时间:
2005-01-14 19:49
标题:
求助:shared library (急)
加进去之后,你source了吗? 可以echo $LD_LIBRARY_PATH看一看。
或者,如kj501所说。
作者:
jianfenghong
时间:
2005-01-15 14:20
标题:
求助:shared library (急)
是我搞错了,两种方法都可以,谢谢大家!
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2