恩山无线论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
当贝投影
查看: 158|回复: 2

手撸编译N2Nv3踩坑记!

[复制链接]
发表于 2022-5-5 21:33 | 显示全部楼层 |阅读模式
本帖最后由 wangsir6688 于 2022-5-5 22:21 编辑

每一步都根据官网提示操作,屡屡受挫!
Downloading a cross-compiling build environment
This usually comes down to the following steps:
  • Download and extract the SDK toolchain for your device. The toolchain must match the exact OpenWRT version installed in your device. Toolchain for official OpenWRT images can be downloaded from [color=var(--color-accent-fg)]https://downloads.openwrt.org
  • Build the toolchain: run make menuconfig, save the configuration, then run make to build the cross compiling tools
  • Download the feeds with ./scripts/feeds update -a


[color=var(--color-accent-fg)]Compilation
These instructions are for building the current checked out version of the n2n source (The generally used OpenWRT alternative is to download a tar.gz file of a specific n2n version, but that is not as suitable for development or local builds)
You need both the openwrt repository and the n2n repository checked out for this. In these instructions, we assume that openwrt is the directory where your openwrt checkout is located and n2n is the directory for the n2n repository.

git clone https://github.com/ntop/n2n n2n  #openwrt同级目录下载n2n源码


N2N_PKG_VERSION=$(n2n/scripts/version.sh)  #选择n2n版本,$(n2n/scripts/version.sh)删掉,手填版本。不删默认最新版本。


export N2N_PKG_VERSION


cp -r n2n/packages/openwrt openwrt/package/n2n #拷贝源码至package目录


cd openwrt
make menuconfig # select Network -> VPN -> n2n-edge and n2n-supernode make menuconfig菜单勾选,建议用<M>


make package/n2n/clean V=s #清理之前编译


make package/n2n/prepare USE_SOURCE_DIR=../n2n V=s#预编译


报错: QQ图片20220505211322.jpg
(注意这步要改下 “USE_SOURCE_DIR=”路径,我这里是USE_SOURCE_DIR=/home/openwrt/n2n/,不改会报错。


make package/n2n/compile V=s
(这步也会报错)
QQ图片20220505211340.png QQ图片20220505211344.png
报错信息:
CFLAGS="-Os -pipe -fno-caller-saves -fno-plt -fhonour-copts
-Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/openwrt/openwrt/build_dir/target-x86_64_musl/n2n-HEAD=n2n-HEAD
-Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro  
-I/home/openwrt/openwrt/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/usr/include
-I/home/openwrt/openwrt/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/include/fortify
-I/home/openwrt/openwrt/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/include "
CXXFLAGS="-Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable
-Wno-error=unused-result -fmacro-prefix-map=/home/openwrt/openwrt/build_dir/target-x86_64_musl/n2n-HEAD=n2n-HEAD
-Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro
-I/home/openwrt/openwrt/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/usr/include
-I/home/openwrt/openwrt/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/include/fortify
-I/home/openwrt/openwrt/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/include
" LDFLAGS="-L/home/openwrt/openwrt/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/usr/lib
-L/home/openwrt/openwrt/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/lib -znow -zrelro "
make -j1 -C /home/openwrt/openwrt/build_dir/target-x86_64_musl/n2n-HEAD/.
AR="x86_64-openwrt-linux-musl-gcc-ar" AS="x86_64-openwrt-linux-musl-gcc -c -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts
-Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/openwrt/openwrt/build_dir/target-x86_64_musl/n2n-HEAD=n2n-HEAD
-Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" LD=x86_64-openwrt-linux-musl-ld NM="x86_64-openwrt-linux-musl-gcc-nm
" CC="x86_64-openwrt-linux-musl-gcc" GCC="x86_64-openwrt-linux-musl-gcc" CXX="x86_64-openwrt-linux-musl-g++" RANLIB="x86_64-openwrt-linux-musl-gcc-ranlib"
STRIP=x86_64-openwrt-linux-musl-strip OBJCOPY=x86_64-openwrt-linux-musl-objcopy OBJDUMP=x86_64-openwrt-linux-musl-objdump
SIZE=x86_64-openwrt-linux-musl-size CROSS="x86_64-openwrt-linux-musl-" ARCH="x86_64" ; make[3]: Entering directory '/home/openwrt/n2n'Build for version: 3.1.1-14-g3fa0fa1x86_64-openwrt-linux-musl-gcc -I./include -I/home/openwrt/openwrt/staging_dir/target-x86_64_musl/usr/include    -Wall     -c -o src/edge.o src/edge
.ccc1: note: someone does not honour COPTS correctly, passed 0 times
x86_64-openwrt-linux-musl-gcc -I./include -I/home/openwrt/openwrt/staging_dir/target-x86_64_musl/usr/include    -Wall     -c -o src/management.o src/management
.ccc1: note: someone does not honour COPTS correctly, passed 0 timesIn file included from src/management.h:11,                 
from src/management.c:17:./include/n2n_typedefs.h:425:5: error: unknown type name 'time_t'  425 |     time_t                           uptime;      |     ^~~~~~./include/n2n_typedefs.h:450:5: error: unknown type name 'time_t'  450 |     time_t                           last_seen;      |     ^~~~~~./include/n2n_typedefs.h:451:5: error: unknown type name 'time_t'  451 |     time_t                           last_p2p;      |     ^~~~~~./include/n2n_typedefs.h:452:5: error: unknown type name 'time_t'  452 |     time_t                           last_sent_query;      |     ^~~~~~./include/n2n_typedefs.h:457:5: error: unknown type name 'time_t'  457 |     time_t                           uptime;      |     ^~~~~~


#编译(这一步也会报错,方法是cp /openwrt/staging_dir/toolchain-x86_64_gcc-11.2.0_musl里的includelib文件夹到/openwrt/staging_dir/toolchain-x86_64_gcc-11.2.0_musl/usr目录,覆盖原文件。)
原因是gcc编译无法识别time_t 函数,查看GCC链接库文件位置没有头文件和库文件,手动COPY库文件、头文件进去。
n2n/include/n2n_typedefs.h文件打开添加一行  #include <time.h>

有不对的地方还请大佬指点。
安装包奉上
n2n-edge_3.0-1_x86_64.ipk.zip (161.36 KB, 下载次数: 2)
n2n-supernode_3.0-1_x86_64.ipk.zip (123.1 KB, 下载次数: 0)







我的恩山、我的无线 The best wifi forum is right here.
发表于 2022-5-6 02:46 | 显示全部楼层
本帖最后由 99010 于 2022-5-6 03:18 编辑

那用这么复杂。。。以编译mt7621为例


  1. #下载sdk
  2. wget https://mirrors.ustc.edu.cn/openwrt/releases/21.02.3/targets/ramips/mt7621/openwrt-sdk-21.02.3-ramips-mt7621_gcc-8.4.0_musl.Linux-x86_64.tar.xz
  3. #解压sdk
  4. tar xvJf openwrt-sdk-21.02.3-ramips-mt7621_gcc-8.4.0_musl.Linux-x86_64.tar.xz
  5. #进入sdk目录
  6. cd openwrt-sdk-21.02.3-ramips-mt7621_gcc-8.4.0_musl.Linux-x86_64
  7. #更新插件
  8. ./scripts/feeds update -a
  9. ./scripts/feeds install -a
  10. #克隆n2n源码
  11. git clone https://github.com/ntop/n2n n2n
  12. #复制n2n插件到package
  13. cp -r n2n/packages/openwrt package/n2n
  14. #修改n2n版本为3.0(注:版本看n2n的tags)
  15. sed -i 's#HEAD#3.0#g' package/n2n/Makefile
  16. sed -i 's#dev#3.0#g' package/n2n/Makefile
  17. #进入菜单,直接保存退出即可
  18. make menuconfig
  19. #编译ipk
  20. make package/n2n/{clean,compile} V=s
复制代码


点评

我试试!  详情 回复 发表于 2022-5-6 09:43
我的恩山、我的无线 The best wifi forum is right here.
 楼主| 发表于 2022-5-6 09:43 来自手机 | 显示全部楼层
99010 发表于 2022-5-6 02:46
那用这么复杂。。。以编译mt7621为例

我试试!
我的恩山、我的无线 The best wifi forum is right here.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )|网站地图

GMT+8, 2022-5-23 13:12

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表