【发布时间】:2016-09-26 09:28:30
【问题描述】:
我正在尝试使用
创建具有相同功能的两个版本的库__asm__(".symver ......
接近
图书馆.h
#ifndef CTEST_H
#define CTEST_H
int first(int x);
int second(int x);
#endif
库.cpp
#include "simple.h"
#include <stdio.h>
__asm__(".symver first_1_0,first@LIBSIMPLE_1.0");
int first_1_0(int x)
{
printf("lib: %s\n", __FUNCTION__);
return x + 1;
}
__asm__(".symver first_2_0,first@@LIBSIMPLE_2.0");
int first_2_0(int x)
{
int y;
printf("lib: %d\n", y);
printf("lib: %s\n", __FUNCTION__);
return (x + 1) * 1000;
}
int second(int x)
{
printf("lib: %s\n", __FUNCTION__);
return x + 2;
}
这里是版本 scripf 文件
LIBSIMPLE_1.0{
global:
first; second;
local:
*;
};
LIBSIMPLE_2.0{
global:
first;
local:
*;
};
当使用 gcc 构建库时,一切正常,并且我能够链接到库二进制文件。使用 nm 工具,我看到 first() 和 second() 函数符号都已导出。 现在,当我尝试使用 g++ 时,没有导出任何符号。 所以我尝试使用 extern "C" 指令来包装两个声明
extern "C" {
int first(int x);
int second(int x);
}
nm 显示 second() 函数符号已导出,但 first() 仍保持未导出和损坏。
我在这里缺少什么才能使它起作用?还是用c++编译器不可能做到这一点?
【问题讨论】:
标签: gcc g++ shared-libraries linker-scripts