limin0108 2013-09-09 02:32
浏览 857

linux动态库静态库问题,大牛请进

/////// static.h
void static_print();
///////static.cpp
#include
#include "static.h"
void static_print() {
std::cout<<"This is static_print function"< }
////// shared.h
void shared_print();
////// shared.cpp
#include
#include "shared.h"
#include "static.h"
void shared_print() {
std::cout<<"This is shared_print function";
static_print();
}

#include
#include
#include
#include
#include "static.h"

using namespace std;

int main()
{
typedef void (*FUN_ADD)(void);
FUN_ADD fun = NULL;
void* plib;
plib = dlopen("./libshared.so", RTLD_NOW | RTLD_GLOBAL);
if( NULL == plib )
cout << "Can't open the libshared.so\n";
else
cout << "Open the libshared.so!\n";

fun = (void (*)(void))dlsym(plib, "shared_print");
if( NULL == fun )
    cout << "Can't load function 'shared_print'\n";

fun();

dlclose(plib);
return 0;

}
g++ -c static.cpp
ar -r libstatic.a static.o
g++ shared.cpp -shared -fPIC -o libshared.so
g++ test.cpp -o test libstatic.a -ldl

测试每次失败,请大牛指示。。。。

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!