SytemC on CentOS 5.3 64bit

來源:互聯網
上載者:User
文章目錄
  • 系統內容
  • 故障原因
  • 解決方案
  • 實戰演練
系統內容
  • 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);
    }
}

 

代碼#include <dlfcn.h>
#include <iostream>

using namespace std;

typedef void (*PFNVOIDINT)(int,int);

int main(int argc, char* argv[])
{
    void* Handle = dlopen("/home/Bo/Projects/Trust/libTrust.so",RTLD_LAZY);

    PFNVOIDINT ForkFunc = (PFNVOIDINT)dlsym(Handle,"Fork");

    if( ForkFunc )
        ForkFunc(1234567890,1122334455);

    dlclose(Handle);
    return 0;
}

執行結果完全正常,參數正確傳入SystemC的模組.so內。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.