系统环境

  • CentOS 5.3 64bit
  • gcc 4.1
  • SystemC 2.2

 

操作目的

  • 将SystemC模块编译为.so由外部程序调用

 

出现故障

  • 编译的时候gcc显示需要将libsystemc.a使用-fPIC开关进行编译,同时显示模块找不到符号。

 

故障原因

  • 为了将SystemC模块打入.so需要将libsystemc.a编译为PIC代码。gcc4默认情况下不再启用-fPIC开关。

 

解决方法

  • 打开configure.in文件,在针对Linux x86_64平台下的-Wall开关后面加上-fPIC。执行config目录下的distinstall和boostrap脚本生成新的配置。然后正常./configure、make、make install、make clean。

 

实战演练

  • 声明一个名字叫做Trust的.so,然后在外部程序中执行这个.so(其实就是手动执行.so中的函数)。两个文件代码如下。
#include <iostream>
#include 
<systemc.h>

using namespace std;

SC_MODULE(first_counter)
{
    SC_CTOR(first_counter){
        cout
<<"Trust"<<endl;
    }
};

int sc_main(int argc, char* argv[])
{
    cout
<<"sc_main running!"<<endl;
    
for(int i=0; i<argc; ++i)
    {
        cout
<<'\t'<<argv[i]<<endl;
    }
    first_counter c1(
"c1");
    
return 0;
}


#define EXPORT __attribute__((visibility("default")))

extern "C"
{
    EXPORT
    
void Fork(int n, int m)
    {
        
char** argv = (char**)malloc(sizeof(void*)*2);

        
char buf[256];

        sprintf(buf,
"%d",n);
        argv[
0= strdup(buf);

        sprintf(buf,
"%d",m);
        argv[
1= strdup(buf);

        sc_main(
2,argv);
        
        free(argv[
0]);
        free(argv[
1]);
        free(argv);
    }
}



相关文章:

  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
  • 2021-07-20
  • 2022-02-24
  • 2021-06-03
猜你喜欢
  • 2022-12-23
  • 2021-08-17
  • 2021-10-24
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案