2025年3月11日 星期二

******systemc-3.0.1的安裝與Q&A

 安裝

1. Change to the top level directory (e.g., `systemc-3.0.1`)
2. export CXX=g++
3. ./config/bootstrap (??)
4. mkdir objdir
5. cd objdir
6. ../configure (../configure 'CXXFLAGS=-std=c++17') (../configure --prefix=/usr/local/systemc-3.0.1)
7. make
8. make check
9. make install
10. cd ..
11. rm -rf objdir

執行

1. 到資料夾底下(n26121779_hw3)

2. make all (執行Makefile)

3. make成功以後,在同個資料夾底下直接 ./Fulladder 才會有波型檔(.vcd)

Makefile:

SYSTEMC_DIR = /home/n26121779/systemc-3.0.1
PROJECT     = FullAdder HalfAdder
BUILDFLAGS  = -g3
CXX         = g++

INCFLAGS    = -I. -I${SYSTEMC_DIR}/include
LDFLAGS     = -L${SYSTEMC_DIR}/lib-linux64 -lsystemc -lm
SRC_CPPHEAD = FullAdder HalfAdder
SRC_CPP     =
HEADERS     =
MAIN        = main.cpp
OBJECTS     = $(SRC_CPPHEAD:=.o) $(SRC_CPP:cpp=o)

EXE = $(PROJECT)

all: $(EXE)

$(EXE): $(MAIN) $(OBJECTS) $(HEADERS)
    @echo "$@ building..."
    $(CXX) $(INCFLAGS) $(MAIN) $(OBJECTS) $(LDFLAGS) -o $@
    @echo ""
    @echo "$@ build done successfully..."
    @echo ""

%.o:%.cpp %.h
    @echo "Compiling $< ..."
    $(CXX) -c $< $(INCFLAGS)

clean:
    rm -f $(EXE)
    rm -f *.o

(Ref : https://blog.csdn.net/tristan_tian/article/details/109555823)--------------------- Q&A ----------------------------------------------------------

QA:

Q : sudo gedit ~/.bashrc

----> sudo: gedit: command not found

A :

    1.sudo apt-get remove gedit

    2.sudo apt-get install gedit


Q : ./FullAdder

-----> error while loading shared libraries: libsystemc-3.0.0.

so: cannot open shared object file: No such file or directory

A : sudo gedit ~/.bashrc #在最下面添加 export SYSTEMC_HOME=/自己安装的路径/systemc export LD_LIBRARY_PATH=/自己安装的路径/systemc/lib-linux64:$LD_LIBRARY_PATH #保存退出 source ~/.bashrc

(SYSTEMC_HOME=/home/n26121779/systemc-3.0.1)

Ref : https://blog.csdn.net/qq_42556934/article/details/108304720



--------------------------------------------------------

1.Download SystemC

以systemc-2.3.3為例
(1) 先檢查g++版本: g++ -v or gcc -v,沒有就安裝g++: sudo apt-get install gcc g++

檢查make版本: make -v,沒有就安裝make:sudo apt install make
(2) 下載systemc-2.3.3.tar.gz,並上傳至工作站或linux虛擬機

載點: https://www.accellera.org/downloads/standards/systemc

(3) 解壓縮: tar xvf systemc-2.3.3.tar.gz

(4) 移動至systemc-2.3.3資料夾: cd systemc-2.3.3

(5) 建立目錄build,以存放編譯檔案: mkdir build/

(6) 移動至build: cd build/

(7) 設定libsystenc安裝位置至build: ../configure --prefix=/usr/local/systemc-2.3.3

(8) 編譯systemc-2.3.3: make

(9) 安裝libsystenc: make install or sudo make install

(10)解決報錯: error while loading shared libraries: libsystemc-2.3.3.so: cannot open shared object file: No such file or directory

在terminal輸入: export LD_LIBRARY_PATH=/usr/local/systemc-2.3.0/lib-linux64:$LD_LIBRARY_PATH

2.環境測試

(1) 範例程式共4份檔案

切記include路徑要對

image

(2) code如下

hello_module.cpp:

#include "hello_module.h" 
  void hello_module::method_func() 
{
            if(clk){
                sc_time_stamp().print(); 
              printf(" Hello Word! \n"); 
              }
}

hello_module.h:

#include "/home/local/systemc-2.3.3/src/systemc.h"

SC_MODULE(hello_module)
{
	// signal declaration
	sc_in_clk		clk;

	// fuction declaration
	void method_func();

	//Constructor 
	SC_CTOR(hello_module) {
		SC_METHOD(method_func);
		sensitive << clk.pos();
	}
};

main.cpp:

#include "/home/local/systemc-2.3.3/src/systemc.h"
#include "hello_module.h"


int sc_main(int argc, char* argv[])
{
	// signal declaration
	sc_clock			clk("clk", 10, SC_NS, 0.5);

	// module declaration
	hello_module		module0("hello_word");

	// signal connection
	module0.clk(clk);

	// run simulation
	sc_start(1000, SC_NS);

	return 0;
}

Makefile:

LIB_DIR=-L/home/local/systemc-2.3.3/lib-linux64
INC_DIR=-I/home/local/systemc-2.3.3/include
LIB=-lsystemc-2.3.3
RPATH=-Wl,-rpath=/home/local/systemc-2.3.3/lib-linux64

APP=hello_module
BPP=main

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

clean:
	rm -rf $(APP)

(3) 編譯檔案: make all ,產生執行檔hello_module

image

image

(4) 執行檔案: ./hello_module

image

https://hackmd.io/@HankTsai/r1jAzGjh6

沒有留言:

張貼留言

*******【WSL教學】在Windows上執行Linux + VSCode

安裝WSL: 以管理員身份運行PowerShell來開啟此功能。要做到這一點,您可以在Windows搜索欄中輸入“PowerShell”,然後右鍵單擊Windows PowerShell,選擇“以管理員身份運行”。 在PowerShell中,輸入以下指令以安裝WSL。 wsl -...