目录
一、背景
手头上的AUTOSAR工程一直是通过scons脚本调用本地安装的Tasking编译器进行编译,完全正常使用;理论上工程导入Tasking IDE编译也不会有什么问题,但导入后build会报上千个错误,一直没解决。仔细研读了脚本中对编译器的配置代码,总结了以下导入Tasking IDE需注意的问题。
二、Tasking IDE工程导入Guide
导入时需要勾选芯片型号相关的配置,此处以英飞凌TC397芯片举例:
1. 新建空白工程
在Tasking IDE中 File -> New -> Tasking Tricore C/C++ Project -> Empty Project -> Infineon TriCore 1 Family -> AURIX 2G Family -> TC39xB -> 取消勾选Add startup files 与 linker script(此处按需选择勾选与否,我的工程自己编辑好了启动文件与链接文件,故此处不需要IDE生成的文件),点击Finish;
2. 导入待编译代码
将待编译的所有代码拷贝至新生成的空白工程路径下,拷贝完成后,右键工程,选择Refresh更新工程代码;
3. 进行编译配置
右键工程 -> Properties -> C/C++ Build -> Settings,这里主要配置三个大模块:Compiler,Assembler,Linker。
1)Compiler
点击C/C++ Compiler,右侧All Options中会出现很多指令,这些指令不可编辑,是基于C/C++ Compiler之下的子选项自动生成的,所以我们需要在子选项中,按照脚本中的编译配置进行设置。此处只详细说明两个容易被忽略的配置:Preprocessing+Include Paths,其他配置按照脚本配置即可:
Preprocessing:配置宏。检查脚本,若其中有-D_xxx则为宏定义,需要在Defined symbols中新建“_xxx”,注意,不要把-D加进来,-D只是宏定义的标识符;
Include Paths:所有头文件的路径,可以使用脚本自动提取工程目录下所有的路径,再按照.cproject中的xml格式将所有路径都添加至.cproject文件中,如下示例代码:
①提取路径:
## The following codes are to extract paths under the project repository.
import os
from pathlib import Path
def get_all_dirs(root_path, exclude_dirs=None, relative=False):
root = Path(root_path).resolve()
dir_list = []
exclude = set(exclude_dirs) if exclude_dirs else set()
for dirpath, dirnames, _ in os.walk(root):
dirnames[:] = [d for d in dirnames if d not in exclude]
current_dir = Path(dirpath)
if relative:
dir_str = str(current_dir.relative_to(root))
else:
dir_str = str(current_dir)
dir_str = dir_str.replace('\\', '/')
dir_list.append(dir_str)
return dir_list
if __name__ == "__main__":
PROJECT_ROOT = "XXXXXXX" # set it to your project absolute path
OUTPUT_FILE = "project_paths.txt"
EXCLUDE_DIRS = ['.git', 'build', 'dist', '__pycache__']
# to get all the paths
all_dirs = get_all_dirs(PROJECT_ROOT, exclude_dirs=EXCLUDE_DIRS)
with open(OUTPUT_FILE, 'w', encoding='utf-8') as f:
for path in all_dirs:
f.write(f"{path}\n")
print(f"Finish generating!There are alltogether {len(all_dirs)} paths")
print(f"Output file: {OUTPUT_FILE}")
② 将提取到的路径改编为.cproject中xml的格式:
<listOptionValue buildIn="false" value="" xxxxxxxx""/>
同样使用脚本,将前一步骤中提取到的project_paths.txt中的所有路径转化成xml格式:
# Convert path to xml
input_file = "project_paths.txt"
output_file = "output.xml"
with open(input_file, 'r') as f_in, open(output_file, 'w', encoding='utf-8') as f_out:
for line in f_in:
clean_path = line.strip()
if not clean_path:
continue
escaped_path = clean_path
xml_line = f'<listOptionValue buildIn="false" value=""{escaped_path}""/>\n'
f_out.write(xml_line)
print(f"Finish converting! Generated file: {output_file}")
③ 将转化好的xml内容,添加至.cproject中:
打开工程目录下的.cproject,该文件包含工程配置,搜索name="Include paths",将上述生成的output.xml中的所有内容,添加至搜索到的下一行,并缩进一级。
④Refresh工程后,重新打开Properties -> C/C++ Build -> Settings -> C/C++ Compiler -> Include Paths,会看到刚才在.cproject中加入的所有路径,此时都被添加至该选项下。
2)Assembler
无特殊注意的,按照脚本配置即可。
3)Linker
Output Format中勾选Generate Intel Hex format File;
Libraries中添加工程中的.a文件,并勾选Link default libraries与Rescan libraries to solve unresolved externals;
Script File中勾选自己的链接文件;
Map File中勾选Generate map file(.map)
以上即为所需的配置操作,笔者在Include Path与Preprocessing的宏添加处卡了很久,Include Path若工程繁大,手动一个个添加非常低效,且容易漏选;Preprocessing的宏也是很容易忽略添加的内容。
三、编译速度:脚本 Vs IDE
通常来讲,脚本编译速度比IDE快很多,笔者的情况脚本只用10min,IDE需要半小时。可以通过
1. 在IDE中Setting->Compilation Speed选项中,勾选Cache generated code to improve the compilation speed;
2. C/C++ Build中Enable parallel build -> Use parallel jobs:24,加快编译速度。
Tasking软件的安装目录下,ctc->doc里,《ctc_user_guide.pdf》Chapter 11详细阐述了对编译时间长短的影响,可参考查阅。