从Windows主机交叉编译/远程调试Raspberry的工具集(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/pi/toolset-to-cross-compile-remote-debug-raspberry-fr-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 9 分钟阅读 - 4049 个词 阅读量 0从Windows主机交叉编译/远程调试Raspberry的工具集(译文)
原文地址:https://www.codeproject.com/Articles/1279667/Toolset-to-Cross-Compile-Remote-Debug-Raspberry-fr
原文作者:fd9750
译文由本站 robot-v1.0 翻译
前言
Overview of required tools to cross compile/build/remote debug C/C++ projects on a Windows host ( 10 ) for a Raspberry PI 3B
在Raspberry PI 3B的Windows主机(10)上交叉编译/构建/远程调试C/C ++项目所需的工具概述
介绍(Introduction)
一行描述可以解释其中的大部分内容:我有一个Raspberry PI 3B,我想为其构建一些C/C ++项目.奇怪的是,很难从Windows(10)主机执行此操作以进行交叉编译/构建以及从主机进行远程调试.那里有很多信息,但是没有关于如何设置示例的摘要,"(The one line description explains most of it: I have a Raspberry PI 3B for which I have wanted to build some C/C++ projects. Oddly enough, how to do that from a Windows (10) host to do the cross compilation/ build and also do remote debugging from the host computer is very hard to find. There is lots of info out there but no summary of how to set up things to make an example “) Hello world
“来自远程Raspberry目标上的Windows主机.我认为主要原因是” C/C ++“在Raspberry PI上并不流行,Python似乎更受欢迎.(” from a Windows host on a remote Raspberry target. I think the main reason for that is that “C/C++” is not very popular on the Raspberry PI, Python appears to be much more popular.)
因为我已经能够组装所有必要的东西以完成它,所以我决定自己编写摘要.我的Raspberry PI正在运行Raspbian Linux发行版,因此在如何同时在运行各种Linux发行版的其他开发板上进行设置可能也不是一个坏例子(As I have been able to assemble all the necessary stuff to pull it off, I decided to make the summary myself. My Raspberry PI is running the Raspbian Linux distro so it is probably not a bad example on how to set things up on other development boards running various Linux distros as well)
背景(Background)
最近几年,我结合使用Eclipse和多种平台上的各种gcc/g ++开发工具链(在各种处理器上使用裸金属/FreeRTOS/Linux:ARMcortex M0 + … dual),完成了很多软件交叉开发.核心ARM9,ESP32,Power5等),因此我对这些东西的工作方式有基本的了解.(The last couple of years, I have done quite a lot of software cross development using a combination of Eclipse and various gcc/g++ development toolchains on multiple platforms (Bare metal/FreeRTOS/Linux on all sorts of processors: ARMcortex M0+…dual core ARM9, ESP32, Power5,…) so I do have a basic knowledge on how these things work.) 然后,我最近从Eclipse/ESP32工具链组合转到了Visual Studio Code/ESP32工具链,事实证明它比Eclipse/ESP32工具链要容易得多.当时,我有一些ESP32硬件可用,因此我可以在Windows(10),Linux和OSX主机上测试该设置,并且它可以在所有平台上运行.(Then, I recently went from an Eclipse/ESP32 toolchain combination to a Visual Studio Code/ESP32 toolchain which turned out to be much easier to set up than the Eclipse/ESP32 toolchain one. At the time, I had some ESP32 hardware available so I could test that setup on a Windows(10), Linux and an OSX host machine and it worked on all platforms.) 由于我现在只有Window 10主机和运行Raspbian的RaspBerry PI3B作为目标,因此我尝试并设法使其从Windows 10主机上运行,但总的来说,它应该与平台无关,因为许多脚本依赖于环境变量,这些变量在各种平台上需要稍有不同的设置,但是它们对于所有可能的平台都是通用的,特别是因为我在Windows计算机上使用Mingw32 shell.(As I now have only a Window 10 host and a RaspBerry PI3B running Raspbian as target, I have tried and managed to get it working from my Windows 10 host but all in all, it should be pretty much platform independent as a lot of the scripting relies on Environment variables which need a slightly different setup on the various platforms but they are common to all the possible platforms, particularly because I use the Mingw32 shell on my Windows machine.)
使用代码(Using the Code)
ZIP文件包含整个项目,并且由很少的文件组成.只要将它放在您喜欢的任何地方即可.注意;解压缩后,您会发现子目录下有一个子目录(The ZIP file contains the entire project and consists of very few files. Just put it anywhere you like. Note; once you unzip it, you will find that there is a subdirectory under subdirectory)**主要(main)**名称(with the name)**测试(test)**和一个文件(and a file)**测试(test.c)**在其中,后两个可以忽略,因为它们仅用于测试子目录中的文件是否也会生成;他们是这样.(in it, the latter two can be ignored as they are only there to test if files in subdirectories would build as well; they do.) 要构建项目,首先需要安装各种工具,因此需要安装以下工具:(To build the project, various tools need to be installed first so here is what needs to installed:)
MSYS2(MSYS2)
这提供了类似于Linux的终端外壳操作.通常,它安装在目录中(This provides Linux like terminal shell operation. Typically, it installs in directory)C:\ msys32(C:\msys32).(.) 跑(Run)**Mingw32.exe(Mingw32.exe)**在该目录中启动外壳程序.可以在以下位置找到安装(in that directory to start a shell. The install can be found at) https://www.msys2.org/(https://www.msys2.org/) .(.)
arm-linux-gnueabihf工具链(arm-linux-gnueabihf toolchain)
这是为树莓派PI构建C/C ++项目所需的工具链.如果要在撰写本文时为Raspbian的最新版本进行构建,则需要版本6.0.3.可以在Linux,OSX和Windows上找到它的预构建版本.我用过的一个可以在这里找到:(This is the required toolchain to build C/C++ projects for the raspberry PI. If you want to build for the latest, at the time of writing, “full stretch” edition of Raspbian, you need version 6.0.3 of it. Prebuilt versions of it can be found for Linux, OSX and Windows. The one I used can be found here:) http://gnutoolchains.com/raspberry/(http://gnutoolchains.com/raspberry/) .我在这里安装它:(. I installed it here:)C:\ msys32 \ home \ RPI \ SysGCC(C:\msys32\home\RPI\SysGCC).(.) 安装后,添加一个名为(Once installed, add a script file called)**RPI-gcc_toolchain.sh(RPI-gcc_toolchain.sh)**在目录中(in directory)C:\ msys32 \ etc \ profile.d(C:\msys32\etc\profile.d).内容应如下所示:(. The content should look something like this:)
export PATH="$PATH:/c/msys32/home/RPI/SysGCC/bin"
export RPI_IP="192.168.0.144"
export RPI_USER="pi"
export RPI_PASSWORD="my_Pi_password"
当然,IP地址取决于本地路由器提供的内容,将其设置为始终为RPI的MAC地址提供相同的IP地址绝对是个好主意.一旦完成,扩展(Of course, the IP address depends on what your local router provides, setting it up to always provide the same IP address for your RPI’s MAC address is definitely a good idea. Once done, the extended) PATH
数据和额外(data and the extra)环境变量(environment variables)每次您运行(will be defined each time you run a) mingw32
贝壳.(shell.)
额外的环境变量(Extra Environment Variable)
要在示例项目中启用VSCODE和makefile使用的某些功能,请添加环境变量(To enable some features used by VSCODE and the makefile in the example project, add environment variable) RPIDEV_LOC
Windows安装程序并将其设置为(to your Windows setup and set it to)c:/msys32/home/RPI/SysGCC(c:/msys32/home/RPI/SysGCC)(使用控制面板->系统->高级设置->环境变量).((Using Control Panel-> System->Advanced settings->Environment variables).)
命令行构建测试(Command Line Build Test)
完成上述操作后,您应该能够测试构建项目:(Once the above is done, you should be able to test building the project:)
- 开始一个(Start a)
mingw32
外壳并导航到(shell and navigate to the)**根(root)**示例项目的目录.(directory of the example project.) - 键入make开始交叉编译/构建,您应该看到它正在构建文件(Type make to start the cross compile/build and you should see it building files)**hello_world_main.c(hello_world_main.c)**和(and)测试(test.c).(.)
- 如果一切顺利,最后的行动是它将产生(If all is well, the final action is that it will produce the)**Hello_world_c(Hello_world_c)**该文件是可以在Raspberry PI上运行的ELF文件.如果可行,我们可以继续使用Visual Studio代码.(file which is an ELF file that can run on the Raspberry PI. If that works, we can get going with Visual Studio code.)
安装Visual Studio代码和扩展(Installing Visual Studio Code and Extensions)
对于尚未获得Visual Studio Code的用户,您需要安装以下各项:(For those who have not got Visual Studio Code yet, you need to install various items:)
- Visual Studio代码本身,可以在以下位置找到(Visual Studio code itself, to be found at) https://code.visualstudio.com/(https://code.visualstudio.com/)
- 延期(Extension)Microsoft的C/C ++(C/C++ by Microsoft)获得C/C ++支持的智能感知等(to get C/C++ support intellisense, etc.)
- 延期(Extension)本机调试(Native-Debug)获得跨平台GDB调试支持(to get Cross platform GDB debug support)
使用Visual Studio代码构建和调试示例代码(Using Visual Studio Code to Build and Debug the Example Code)
一旦安装了Visual Studio Code和扩展名,就可以从打开项目的文件夹开始.在该文件夹中,有(Once Visual Studio Code and the extensions are installed, you can start by opening the project’s folder. Within that folder, there is)**.vscode(.vscode)**文件夹,里面有所有必要(folder, in it are all the necessary)JSON格式(JSON)提供所有必要构建工具等的配置文件.按(configuration files which provide all of the necessary build tools, etc. the build tool list pops up by pressing)Ctrl + Shift + B(Ctrl+Shift+B).(.)
构建命令的数量不多,除了通常的清洁,构建和快速构建工具外,最重要的是(The number of build commands is not long, apart from the usual clean, build and fast build tools the most important one is the)转让…(Transfer…)该工具将文件传输到RPI并执行(tool which transfers the file to execute to the RPI and starts the) GDBSERVER
在那个单位上(on that unit with it)
实际调试是通过按(Actual debugging is started by pressing)F5(F5)它将尝试连接到RPI的"最近启动”(which will attempt to connect to the RPI’s Recently started) GDBSERVER
.从那时起,您可以完成调试.设置断点,调查变量等.就像应用程序在主机系统本身上运行一样.(. From that point on, you can do complete debugging; setting breakpoints, investigating variables, etc. just as if the application was running on your host system itself.)
就是这样了.在GUI之前的日子里,我已经做了很多CLI开发工作.有或没有某种形式的OS,某些嵌入式Linux应用程序,某些Windows开发工作以及大量其他嵌入式工作.我真的很喜欢这样做,因为它将很多东西整齐地绑在一起.我只是希望这对需要解决方案而不必亲自进行所有挖掘工作的人有用.(So, that’s it. I have done quite a bit of CLI development work in the pre GUI days. Some embedded Linux applications work, some windows development work and tons of other embedded work, with or without some form of OS. I really liked doing this as it ties a lot of stuff neatly together. I just hope this can be of use to someone who needs a solution without having to do all the digging personally.)
历史(History)
- 22(22)nd(nd)2019年3月:初始版本(March, 2019: Initial version)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C C++ Raspberry Windows JSON VS-Code shell 新闻 翻译