MENU

构建开发天地:OpenWrt与Eclipse的完美结合

• May 7, 2024 • Openwrt阅读设置

在Debian 10.3环境下,结合Eclipse 2023和OpenWrt 22.03.5,我们搭建一个无与伦比的开发环境。这个指南以一个稳定的Docker构建项目docker-openwrt-build-env为基础,为你展示如何打造一个强大而稳定的开发平台。

z.webp.jpg

软件来源

我们从安装Debian 10.13开始,再下载Eclipse 2023的安装包。然后,按照《Using Eclipse for C/C++ Programming and Debugging》的官方教程安装以下四个必要的插件:

C/C++ Remote Launch Developer Resources
Remote System Explorer End-User Runtime
Remote Launch Targets Developer Resources
Terminal (Console) View Developer Resources
安装插件的方法是通过Help->Install New Software...进行,要注意的是选择全部站点,并取消"Contact all update sites during install to find required software"的选项。

下载OpenWrt

在开始下载OpenWrt源码之前,我们需要先在Debian上安装一些必要的软件包。然后,选择一个稳定版本的OpenWrt源码进行下载:

bash
Copy code
sudo apt-get update
sudo apt-get install -y time git-core subversion build-essential g++ bash make libssl-dev patch libncurses5 libncurses5-dev zlib1g-dev gawk flex gettext wget unzip xz-utils python python-distutils-extra python3 python3-distutils-extra python3-setuptools swig rsync curl libsnmp-dev liblzma-dev libpam0g-dev cpio rsync gcc-multilib
apt-get clean

git clone --branch v22.03.5 https://git.openwrt.org/openwrt/openwrt.git
cd openwrt
./scripts/feeds update -a
./scripts/feeds install -a
首次编译OpenWrt

首次编译OpenWrt时,只需确认目标板的型号即可。进入交互界面后,配置Target System、Subtarget和Target Profile即可。按照提示,保存退出,并执行编译指令:

bash
Copy code
make menuconfig
make V=99
添加OpenWrt开发组件

根据需要,可以添加以下组件:

C或C++开发:至少勾选libstdcpp。
LuCI:建议选择built-in。
SFTP:建议选择built-in。
gdbserver:建议选择built-in。
Eclipse创建C++项目

按照官方教程,创建一个C++ Managed Build项目。选择Cross GCC作为交叉编译器,创建一个Hello World C++ Project。

Eclipse远程调试

通过Eclipse的Debug Configurations新建一个C/C++ Remote Application。在配置过程中,要注意几个常见错误:

确保C/C++ Application指向可执行文件。
Connection选择SSH连接。
Remote Absolute File Path for C/C++ Application必须使用绝对路径。
GDB debugger必须使用OpenWrt提供的路径。
如果遇到网络问题,请探索OpenWrt路由器界面的网络配置,并检查Eclipse是否能够连接到OpenWrt路由器。
通过这个强大的开发环境,你将能够在Debian上使用Eclipse轻松进行OpenWrt开发,实现更高效的编程和调试。