制作Makefile
1 2 3 4 5 6 7 8 9 10 11 12
   | LIBDIR=-L/home/users/0927/systemc-2.3/lib-linux64 INCDIR=-I/home/users/0927/systemc-2.3/include LIB=-lsystemc FILES=main.cpp\ 	path_to_cpp1.cpp\ 	path_to_cpp2.cpp\ 	path_to_cpp3.cpp
  all: 	g++ -Wall -std=c++11 -o test $(FILES) $(LIBDIR) $(INCDIR) $(LIB) clean: 	rm -rf *.o
   | 
 
命令行使用:make 即可编译。
使用VSCode编译
根据上面的方法,添加 Makefile 文件,确保 make 能正常编译。
VSCode 打开项目文件,项目根目录添加 .vscode 文件夹及三个 json 文件,如下:
- .vscode/ (VSCode配置)
- settings.json
 
- launch.json
 
- tasks.json
 
 
- main.cpp (源码)
 
- Makefile
 
以下仅介绍这三个文件的用法。
settings.json
这是 VSCode 的单个项目的配置文件,此处用来添加 SystemC 及相关库的头文件等,用来实时纠错(不加也不影响编译)。
1 2 3 4 5
   | {     "C_Cpp.default.includePath": [         "/home/users/0927/systemc-2.3/src"     ] }
  | 
 
tasks.json
用来执行 make 命令,在 launch 时自动调用。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
   | {         "version": "2.0.0",         "tasks": [             {                 "label": "build",                 "type": "shell",                 "command": "make",                 "problemMatcher": [],                 "dependsOn": [                     "clean"                 ]             },             {                 "label": "clean",                 "type": "shell",                 "command": "make",                 "args": [                     "clean"                 ],                 "problemMatcher": [],             },         ]
  }
  | 
 
args 里面可以添加参数,如 make clean 可以设置为 “args": ["clean"]。
launch.json
用来打开需要调试的程序。
按 F5 一键执行,自动调用 tasks.json 中的 make 命令。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
   | {     "version": "0.2.0",     "configurations": [         {             "name": "debug hello world",             "type": "cppdbg",             "request": "launch",             "program": "${workspaceFolder}/test", // 要运行的程序             "args": [],             "stopAtEntry": false,             "cwd": "${workspaceFolder}",             "environment": [],             "externalConsole": false,             "MIMode": "gdb",             "setupCommands": [                 {                     "description": "Enable pretty-printing for gdb",                     "text": "-enable-pretty-printing",                     "ignoreFailures": true                 }             ],             "preLaunchTask": "build"         }     ] }
  | 
 
这里 type: cppdbg 需要依赖 C/C++-Linux 插件