当前位置: 技术问答>linux和unix
请教在solaris下,一动态库*.so动态链接多个静态库*.a时链接不正确
来源: 互联网 发布时间:2016-04-06
本文导语: 在solaris下,类有3层继承关系:Base->Child->Child1,其中Base是抽象类,把Child.cpp和Child1.cpp这2个子类编译成一个静态库libbasechild.a, 然后在一动态库bcProcess.so中链接这个静态库libbasechild.a,使用ldd -r bcProcess.so查看,发...
在solaris下,类有3层继承关系:Base->Child->Child1,其中Base是抽象类,把Child.cpp和Child1.cpp这2个子类编译成一个静态库libbasechild.a, 然后在一动态库bcProcess.so中链接这个静态库libbasechild.a,使用ldd -r bcProcess.so查看,发现能正确链接:
$ ldd -r bcProcess.so
libstdc++.so.5 => /usr/local/lib/libstdc++.so.5
libpthread.so.1 => /usr/lib/libpthread.so.1
libnsl.so.1 => /usr/lib/libnsl.so.1
libdl.so.1 => /usr/lib/libdl.so.1
libm.so.1 => /usr/lib/libm.so.1
libc.so.1 => /usr/lib/libc.so.1
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libmp.so.2 => /usr/lib/libmp.so.2
symbol not found: main (./bcProcess.so)
/usr/platform/SUNW,Ultra-60/lib/libc_psr.so.1
libthread.so.1 => /usr/lib/libthread.so.1
而把Child.cpp和Child1.cpp分别编译成2个静态库libbase.a和libchild.a, 然后在一动态库cProcess.so中链接这2个静态库,使用ldd -r bcProcess.so查看,发现链接不正确:
$ ldd -r cProcess.so
libstdc++.so.5 => /usr/local/lib/libstdc++.so.5
libpthread.so.1 => /usr/lib/libpthread.so.1
libnsl.so.1 => /usr/lib/libnsl.so.1
libdl.so.1 => /usr/lib/libdl.so.1
libm.so.1 => /usr/lib/libm.so.1
libc.so.1 => /usr/lib/libc.so.1
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libmp.so.2 => /usr/lib/libmp.so.2
symbol not found: main (./cProcess.so)
/usr/platform/SUNW,Ultra-60/lib/libc_psr.so.1
symbol not found: _ZN5Child4testEv (./cProcess.so)
symbol not found: _ZTI5Child (./cProcess.so)
symbol not found: _ZN5ChildC2Ev (./cProcess.so)
symbol not found: _ZN5ChildD2Ev (./cProcess.so)
libthread.so.1 => /usr/lib/libthread.so.1
环境:
SunOS sun 5.9 Generic_118558-06 sun4u sparc SUNW,Ultra-60
不知道为什么分别放在2个静态库中就链接不正确,是不是Makefile选项问题还是别的?
目前是希望能放在2个静态库中能正确链接,源文件及Makefile如下,好几天都没搞出头绪,诚心请教大家帮忙,非常谢谢!!!
Base.h:
#ifndef _BASE_H_
#define _BASE_H_
#include
using namespace std;
class Base
{
public:
Base()
{
cout
$ ldd -r bcProcess.so
libstdc++.so.5 => /usr/local/lib/libstdc++.so.5
libpthread.so.1 => /usr/lib/libpthread.so.1
libnsl.so.1 => /usr/lib/libnsl.so.1
libdl.so.1 => /usr/lib/libdl.so.1
libm.so.1 => /usr/lib/libm.so.1
libc.so.1 => /usr/lib/libc.so.1
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libmp.so.2 => /usr/lib/libmp.so.2
symbol not found: main (./bcProcess.so)
/usr/platform/SUNW,Ultra-60/lib/libc_psr.so.1
libthread.so.1 => /usr/lib/libthread.so.1
而把Child.cpp和Child1.cpp分别编译成2个静态库libbase.a和libchild.a, 然后在一动态库cProcess.so中链接这2个静态库,使用ldd -r bcProcess.so查看,发现链接不正确:
$ ldd -r cProcess.so
libstdc++.so.5 => /usr/local/lib/libstdc++.so.5
libpthread.so.1 => /usr/lib/libpthread.so.1
libnsl.so.1 => /usr/lib/libnsl.so.1
libdl.so.1 => /usr/lib/libdl.so.1
libm.so.1 => /usr/lib/libm.so.1
libc.so.1 => /usr/lib/libc.so.1
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libmp.so.2 => /usr/lib/libmp.so.2
symbol not found: main (./cProcess.so)
/usr/platform/SUNW,Ultra-60/lib/libc_psr.so.1
symbol not found: _ZN5Child4testEv (./cProcess.so)
symbol not found: _ZTI5Child (./cProcess.so)
symbol not found: _ZN5ChildC2Ev (./cProcess.so)
symbol not found: _ZN5ChildD2Ev (./cProcess.so)
libthread.so.1 => /usr/lib/libthread.so.1
环境:
SunOS sun 5.9 Generic_118558-06 sun4u sparc SUNW,Ultra-60
不知道为什么分别放在2个静态库中就链接不正确,是不是Makefile选项问题还是别的?
目前是希望能放在2个静态库中能正确链接,源文件及Makefile如下,好几天都没搞出头绪,诚心请教大家帮忙,非常谢谢!!!
Base.h:
#ifndef _BASE_H_
#define _BASE_H_
#include
using namespace std;
class Base
{
public:
Base()
{
cout