在编译最新版本(12.04)的alljoyn的chat示例的时候,想使用bundle daemon,依照在以前的经验修改文件:alljoyn-14.02.00-src/build/linux/x86_64/debug/dist/samples/chat/makefile:

LIBS = -lalljoyn ../../lib/BundledRouter.o -lajrouter -lstdc++ -lcrypto -lpthread -lrt

1). 编译ok,但运行时报错:

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

原来../../lib/目录下有两个库:

ll ../../lib/
total 71552
drwxr-xr-x 2 z.rao CAF 4096 Apr 9 19:56 ./
drwxr-xr-x 6 z.rao CAF 4096 Apr 9 18:35 ../
-rw-r--r-- 1 z.rao CAF 529336 Apr 9 18:36 BundledRouter.o
-rw-r--r-- 1 z.rao CAF 38765950 Apr 9 18:36 libajrouter.a
-rw-r--r-- 1 z.rao CAF 24335844 Apr 9 18:35 liballjoyn.a
-rwxr-xr-x 1 z.rao CAF 9621229 Apr 9 19:56 liballjoyn.so*

默认连接的是动态库:liballjoyn.so*

虽然可以通过ldconfig搞定动态库的连接问题,但考虑到程序的发布问题,我决定连接静态库liballjoyn.a

2).于是,删除liballjoyn.so,这样程序就会连接到静态库liballjoyn.a了:

rm ../../lib/liballjoyn.so
make clean;make

很不幸报错:

g++ -c -Wall -pipe -std=c++98 -fno-rtti -fno-exceptions -Wno-long-long -Wno-deprecated -g -DQCC_OS_LINUX -DQCC_OS_GROUP_POSIX -DQCC_CPU_X86 -I../../inc -o chat.o chat.cc
g++ -o chat chat.o -L../../lib -lalljoyn ../../lib/BundledRouter.o -lajrouter -lstdc++ -lcrypto -lpthread -lrt
../../lib/BundledRouter.o: In function `BundledRouter::Start(ajn::NullTransport*)':
/home/z.rao/work/Library/alljoyn-14.02.00-src/alljoyn_core/router/bundled/BundledRouter.cc:263: undefined reference to `qcc::LoggerSetting::GetLoggerSetting(char const*, int, bool, _IO_FILE*)'
../../lib/BundledRouter.o: In function `ajn::PasswordManager::GetPassword()':
/home/z.rao/work/Library/alljoyn-14.02.00-src/alljoyn_core/inc/alljoyn/PasswordManager.h:65: undefined reference to `ajn::PasswordManager::password'
../../lib/BundledRouter.o: In function `ajn::PasswordManager::GetAuthMechanism()':
/home/z.rao/work/Library/alljoyn-14.02.00-src/alljoyn_core/inc/alljoyn/PasswordManager.h:71: undefined reference to `ajn::PasswordManager::authMechanism'
../../lib/libajrouter.a(TCPTransport.o): In function `ajn::TCPTransport::GetListenAddresses(ajn::SessionOpts const&, std::vector<qcc::String, std::allocator<qcc::String> >&) const':
/home/z.rao/work/Library/alljoyn-14.02.00-src/alljoyn_core/router/TCPTransport.cc:1193: undefined reference to `qcc::IfConfig(std::vector<qcc::IfConfigEntry, std::allocator<qcc::IfConfigEntry> >&)'
../../lib/libajrouter.a(TCPTransport.o): In function `ajn::TCPTransport::Connect(char const*, ajn::SessionOpts const&, qcc::ManagedObj<ajn::_BusEndpoint>&)':

没有定义?

看看导出了哪些符号?

nm -C ../../lib/liballjoyn.a |grep GetLoggerSetting
0000000000000476 T qcc::LoggerSetting::GetLoggerSetting(char const*, int, bool, _IO_FILE*)
0000000000000000 W qcc::LoggerSetting::GetLoggerSetting()

明明已经定义了啊.....哭。。。

之前连接动态库liballjoyn.so就可以,静态库liballjoyn.a为什么不行呢?。。。。百思不得其解

3).想来想去,可能是静态库的连接顺序导致了循环依赖,除此以外似乎没有其他可能了。

于是网上猛搜一通,发现

http://www.cnblogs.com/wujianlundao/archive/2012/06/06/2538125.html

将makefile修改为如下形式:

LIBS = -Xlinker "-(" -lalljoyn ../../lib/BundledRouter.o -lajrouter -Xlinker "-)" -lstdc++ -lcrypto -lpthread -lrt

果然搞定了!

要问-Xlinker干啥的?。。。。哈哈啊

g++ 静态库连接顺序的巨坑的更多相关文章

  1. 再议GCC编译时的静态库依赖顺序问题

    相关博文1:http://blog.chinaunix.net/uid-20682147-id-76330.html相关博文:http://blog.chinaunix.net/uid-2068214 ...

  2. CMake和静态库顺序

    目录 目录 1 前言 1 方法 1 附1:链接静态库的顺序问题 2 附2:再议GCC编译时的静态库依赖次顺问题 3 附3:gcc链接参数--whole-archive的作用 4 附4:让有些“-l”链 ...

  3. gcc/g++链接时.o文件及库的顺序问题

    折腾gcc/g++链接时.o文件及库的顺序问题 链接静态库的顺序问题 GCC 编译使用动态链接库和静态链接库--及先后顺序----及环境变量设置总结

  4. 技巧:Linux 动态库与静态库制作及使用详解

    技巧:Linux 动态库与静态库制作及使用详解 标准库的三种连接方式及静态库制作与使用方法 Linux 应用开发通常要考虑三个问题,即:1)在 Linux 应用程序开发过程中遇到过标准库链接在不同 L ...

  5. 详细讲解 关于Linux静态库和动态库的分析

    基本概念 库有动态与静态两种,动态通常用.so为后缀,静态用.a为后缀. 例如:libhello.so libhello.a 为了在同一系统中使用不同版本的库,可以在库文件名后加上版本号为后缀,例如: ...

  6. Linux 静态库&动态库调用

    1.什么是库在windows平台和linux平台下都大量存在着库.本质上来说库是一种可执行代码的二进制形式,可以被操作系统载入内存执行.由于windows和linux的本质不同,因此二者库的二进制是不 ...

  7. Linux 使用静态库注意事项

    1. 静态库一定要放在生成文件后面 gcc main.c -o main libhello.a 2. 使用静态库时一定要连接所有用到的静态库 gcc main.c -o main liba.a lib ...

  8. Android:JNI与NDK(二)交叉编译与动态库,静态库

    欢迎关注公众号,第一时间获取最新文章: 本篇目录 一.前言 本篇主要以window开发环境为背景介绍一下NDK开发中需要掌握的交叉编译等基础知识,选window系统主要是照顾大多数读者,mac ,li ...

  9. linux中C的静态库和动态库分析

    从开始学C语言写第一个"hello world"历程到现在,我依然困惑于到底这个程序完整的执行流程是什么样的.不过,现在我正在尝试一点一点的揭开它的面纱.现在,我尝试分析linux ...

随机推荐

  1. 596. Classes More Than 5 Students

    There is a table courses with columns: student and class Please list out all classes which have more ...

  2. jquery&javascript 跨域jsonp

    $(function(){ $.ajax({ type: "get", async: false, url: "http://flightQuery.com/jsonp/ ...

  3. LoadRunner运行中的mmdrv和mdrv

    在LoadRunner运行脚本过程中,在任务管理器中我们可以看到有一个或多个名为“mmdrv”的进程在运行,与此同时当我们查看LoadRunner\bin目录下的文件时还会看到一个“mdrv.exe” ...

  4. 数据库的主从复制常用Xshell命令

    mysql配置 1.设置数据库用户名和密码 mysqladmin -u root password "root" 2.打开3306端口号 iptables -I INPUT -p ...

  5. Maven 管理的WEB项目发布到Tomcat上

    1.需要Tomcat服务器 这里可以使用已下载好的Tomcat也可以使用Maven来自动引入Tomcat插件. 通过Maven引入Tomcat服务器 在项目的pom.xml文件中project 标签中 ...

  6. [THINKPHP] 模板可用三元操作符

    <td>{$vo['realname'] ? $vo['realname'] : $vo['nickname']}</td>

  7. Web页面中两个listbox的option的转移

    Html: <div><span>所选时间:</span><select id="xuanyongTimelb" style=" ...

  8. NBUT 1218 You are my brother

    $dfs$. 记录一下每一个节点的深度就可以了. #include<cstdio> #include<cstring> #include<cmath> #inclu ...

  9. POJ1456 supermarket [堆]

    题目传送门 Supermarket Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15192   Accepted: 685 ...

  10. 现代CSS清除浮动

    清除浮动 排除远古时代的hack解决方案,比如那些要兼容IE6~8的方法.其实总结起来,大致有三种方法: overflow 原理解析:块级格式上下文规定了页面必须自动包含突出的浮动元素! 而overf ...