blue1025的个人空间 https://blog.eetop.cn/mj8051 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

SystemC Linux開發環境配置

已有 3298 次阅读| 2009-3-15 21:11 |个人分类:MJ8051

SystemC Linux開發環境配置

SystemC的開發工具有很多種,不過原則上SystemC只是在C++裏增加一個Class,因此基本上任何一個符合ANSI標準的C++編譯工具都可以對systemC程式進行編譯連結來產生可執行檔。
在此我們將介紹如何在Linux環境裏,使用g++來編譯SystemC的程式。我是用4.1.2的g++。

首先請到OSCI網站下載systemc-2.2.0.tgz
http://www.systemc.org/downloads/standards

下載時需要帳號才行下載,所以就申請一個,啟動帳後再回來下載
下載回來後,找個地方把你的systemc-2.2.0.tgz解開

tar xvf systemc-2.2.0.tgz
然後
cd systemc-2.2.0
然後
mkdir /usr/systemc
然後
./configure --prefix=/usr/systemc
最後
make
make install
做到這裏,我們已經把SystemC的開發環境做好了,我最後在make install時有發生錯誤,但由於是example的部份,所以我就不管它了

接下來寫個範例程式來測看看
hello.h
#ifndef _HELLO_H
#define _HELLO_H
#include "systemc.h"

SC_MODULE(hello){
SC_CTOR(hello){
cout<<"Hello,SystemC!"<<endl;
}
};
#endif
hello.cpp
#if 1

#include "hello.h"

#else
#include "systemc.h"

class hello : public sc_module{
public:
hello(sc_module_name name) : sc_module(name){
cout<<"Hello,SystemC!"<<endl;
}
};
#endif

int sc_main(int argc,char** argv){
hello h("hello");
return 0;
}
上面的hello有2種寫法,但意思是一樣的啦!

Makefile
LIB_DIR=-L/usr/systemc/lib-linux
INC_DIR=-I/usr/systemc/include
LIB=-lsystemc

APP=hello

all:
g++ -o $(APP) $(APP).cpp $(LIB_DIR) $(INC_DIR) $(LIB)

clean:
rm -rf $(APP)
你也可以使用g++ hello.cpp -I/usr/systemc/include -L/usr/systemc/lib-linux -o hello -lsystemc直接下命令編譯
參數說明:
    -I/usr/systemc/include 告訴g++去/usr/systemc/include底下尋找include檔案,也就是我們寫的systemc.h路徑
    -L/usr/systemc/lib-linux 告訴ld去/usr/systemc/lib-linux底下尋找library檔案
    -o hello 最後輸出一個執行檔,檔名為hello
    -lsystemc 靠訴ld要引用libsystemc.a這個函式庫
如果你在編譯時,發生了類似下面的錯誤時
g++ -o hello hello.cpp -L/usr/systemc/lib-linux -I/usr/systemc/include -lsystemc
hello.cpp:16: error: new types may not be defined in a return type
hello.cpp:16: note: (perhaps a semicolon is missing after the definition of 'hello')
hello.cpp:16: error: two or more data types in declaration of 'sc_main'
hello.cpp: In function 'hello sc_main(int, char**)':
hello.cpp:16: error: new declaration 'hello sc_main(int, char**)'
/usr/systemc/include/sysc/kernel/sc_externs.h:49: error: ambiguates old declaration 'int sc_main(int, char**)'
hello.cpp: In function 'hello sc_main(int, char**)':
hello.cpp:18: error: conversion from 'int' to non-scalar type 'hello' requested
make: *** [all] Error 1

千萬不要以為是sc_main參數有問題,或是回傳值有問題,其實真正的問題點很有可能是沒有加";"喔!
比如:
SC_MODULE(hello){
SC_CTOR(hello){
cout<<"Hello,SystemC!"<<endl;
}
}
就是在最後的"}"後面,還必需接一個";",才不會有錯誤。

執行結果如下:
[root@svn hello]# ./hello

SystemC 2.2.0 --- Oct 3 2008 11:10:01
Copyright (c) 1996-2006 by all Contributors
ALL RIGHTS RESERVED
Hello,SystemC!


如果是用Windows的可以參考底下這篇文章或 Installing SystemC

 

source html: http://stenlyho.blogspot.com/search/label/SystemC


点赞

发表评论 评论 (1 个评论)

回复 dai.image 2009-3-21 22:19
好東西,我頂,謝謝。

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 13

    粉丝
  • 16

    好友
  • 15

    获赞
  • 23

    评论
  • 2824

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-26 11:22 , Processed in 0.014232 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部