免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1520 | 回复: 5
打印 上一主题 下一主题

求助:shared library (急) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-01-14 17:58 |只看该作者 |倒序浏览
#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,为什么链接不成功?

论坛徽章:
0
2 [报告]
发表于 2005-01-14 18:26 |只看该作者

求助:shared library (急)

将/usr/local/lib 加入LD_LIBARAY_PATH

论坛徽章:
0
3 [报告]
发表于 2005-01-14 18:59 |只看该作者

求助:shared library (急)

还是不行啊!

论坛徽章:
0
4 [报告]
发表于 2005-01-14 19:26 |只看该作者

求助:shared library (急)

看看/etc/ld.so.conf是否包含了/usr/local/lib,如果没有,就请加上,然后执行ldconfig。

论坛徽章:
0
5 [报告]
发表于 2005-01-14 19:49 |只看该作者

求助:shared library (急)

加进去之后,你source了吗? 可以echo $LD_LIBRARY_PATH看一看。

或者,如kj501所说。

论坛徽章:
0
6 [报告]
发表于 2005-01-15 14:20 |只看该作者

求助:shared library (急)

是我搞错了,两种方法都可以,谢谢大家!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP