当前位置:网站首页>Aiot application innovation competition - get better code completion and jump experience with clion

Aiot application innovation competition - get better code completion and jump experience with clion

2022-06-23 21:15:00 Yu Hanchen

background

stay Official website tutorial Some of them NXP RT1062 Of demo engineering , Use the recommended MCUXpresso IDE It's easy to get started after trying , But the only drawback is that the editing function is not powerful enough .

IDE It provides many necessary functions for embedded development , Such as compiling tool chain 、 Code editor 、 The debugger 、 Firmware download tool , But it is weak in the code editor , It is mainly reflected in the inability to complete automatically , That is, input the first few characters of the function , Auto complete function name (IDE Function jump can be realized , However, the auto completion function requires input . Number or :: No. triggers , For embedded c Programming is of little use ).

Usually, the coding is mostly CLion, So consider switching CLion As a code editor (vscode It's fine too , Better code completion requires clangd Support ), Other functions embedded specific functions ( compile 、 debugging ) Official use IDE.

Implementation steps

use MCUXpresso IDE Generate makefile

C/C++ There are currently two popular ways to build projects :make perhaps cmake, In embedded programming, we use make Mainly . When switching editors , There must be makefile To find the header file path 、 Source path 、 Link library path , Then do code analysis to support code jump and completion .

Open sample project , Click build project ,IDE Will generate makefile, As shown in the figure below :

Generate the compiled database

Compiling a database is a json file , The compilation steps and source code path of the project are described in detail , Accurate code completion and jump can be achieved in large projects .make Engineering and cmake Projects can generate compiled databases , And in CLion perhaps vscode Application compilation database .

First installation compiledb Tools

 pip3 install compiledb

stay makefile Run the command in the same directory , It will be generated in the current directory compile_commands.json

 compiledb -n make

The contents of the compiled database file are as follows :

because makefile The default with arm-none-eabi-gcc Tool chain , stay CLion No support method found in , Therefore, it can be replaced by gcc To avoid loading project errors .

use CLion Open the project

Because it's time to makefile Based on the project root directory , So you can copy it directly compile_commands.json To the project root directory , And then use CLion Open the json file , Will prompt open as project, Then you can index all the symbols , And bring more perfect code completion 、 Jump function .

Q&A

Why not CLion You can use makefile

CLion It does support makefile engineering , But does not support MCUXpresso IDE Generated makfile.

Observe MCUXpresso IDE The building process of , Found to be makefile The file in Project root /Debug Under the table of contents , And the directory has only the scripts needed to build , No source code . Use CLion(2021.2 edition ) After opening the project directory , open makefile file , choice load makefile,load Successful but unable to auto jump , The automatic completion function is not complete . Copying the full amount of compiled scripts to the source directory is too heavy , Therefore, consider compiling the database .

原网站

版权声明
本文为[Yu Hanchen]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/12/202112251540125325.html