平台:RV1126
系统:buildroot
交叉编译了一个名为astrometry.net的工程,这个工程依赖C库和Python
1.错误尝试,但是设置依赖库可以参考这个方式
测试在Ubuntu中源码编译需要依赖下面的库
sudo apt-get install libbz2-dev
sudo apt-get install libcfitsio-dev
sudo apt-get install libjpeg-dev
其中bz2和jpeg在buildroot中已经存在,libcfitsio没有,需要手动添加
在Buildroot的package/目录下创建一个新目录,比如package/libcfitsio/,在其中创建一个Config.in文件,内容如下:
config BR2_PACKAGE_LIBCFITSIO
bool "libcfitsio"
depends on BR2_INSTALL_LIBSTDCPP
help
Library for manipulating FITS files.
comment "libcfitsio needs a toolchain w/ C++, threads"
depends on !BR2_INSTALL_LIBSTDCPP || !BR2_TOOLCHAIN_HAS_THREADS
这个配置文件描述了libcfitsio的Buildroot包,指定了它的依赖关系和简短的帮助信息。
在Buildroot中添加libcfitsio的构建文件:
在package/libcfitsio/目录中创建一个libcfitsio.mk文件,内容如下:
LIBCFITSIO_VERSION = 3.47
LIBCFITSIO_SOURCE = libcfitsio-$(LIBCFITSIO_VERSION).tar.gz
LIBCFITSIO_SITE = https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c
$(eval $(autotools-package))
在package下的Config.in中添加包含libcfitsio的Config.in
在Buildroot的主目录中运行以下命令:
make ARCH=arm rockchip_rv1126_rv1109_defconfig
make menuconfig
在菜单中找到并选择 Target packages -> Libraries -> libcfitsio。
选择后make savedefconfig
在SDK根目录运行
./build.sh rootfs
Buildroot将会自动下载libcfitsio的源代码,构建并将其包含到生成的根文件系统中。
同样的在~/workspace/RV1126SDK/buildroot/package/astrometry下增加
config BR2_PACKAGE_ASTROMETRY
bool "astrometry"
help
This is a demo to add local app.
astrometry.mk
################################################################################
#
# ASTROMETRY
#
################################################################################
ASTROMETRY_VERSION:= 1.0.0
ASTROMETRY_SITE:= $(TOPDIR)/../app/astrometry
ASTROMETRY_SITE_METHOD:=local
ASTROMETRY_INSTALL_TARGET:=YES
define ASTROMETRY_BUILD_CMDS
$(MAKE) CC="$(TARGET_CC)" LD="$(TARGET_LD)" -C $(@D) all
endef
define ASTROMETRY_INSTALL_TARGET_CMDS
$(INSTALL) -D -m 0755 $(@D)/astrometry $(TARGET_DIR)/bin
endef
define ASTROMETRY_PERMISSIONS
/bin/astrometry f 4755 0 0 - - - - -
endef
$(eval $(generic-package))
将astrometry源码放到~/workspace/RV1126SDK/app/下
在package下的Config.in中添加包含astrometry的Config.in
在Buildroot的主目录中运行以下命令:
make ARCH=arm rockchip_rv1126_rv1109_defconfig
make menuconfig
在菜单中找到并选择 Target packages -> Libraries -> astrometry
选择后make savedefconfig
在SDK根目录运行
./build.sh rootfs
编译报错
报错是因为astrometry.net所依赖的环境不对,如果全部往buildroot的框架里配置astrometry.net的环境会很复杂,而且有可能会把原来的正常的系统给配置坏
2、脱离rockchip SDK的buildroot框架,手动交叉编译测试(测试成功)
在网上查找交叉编译astrometry.net的资料,信息很少
关于交叉编译astrometry.net的内容
https://groups.google.com/g/astrometry/c/2jf-d4j_MBM
尝试不在buildroot框架里编译,直接交叉编译工程,然后移植到系统里
在~/workspace/astrometry.net-0.93/Makefile里找到一些关于CC的信息
通过export来设置CC,
export $(CC),可以看到设置成了交叉编译工具链
declare -x CC="arm-linux-gnueabihf-gcc"
在gsl-an下执行
CC=arm-linux-gnueabihf-gcc LD=arm-linux-gnueabihf-ld ./configure --enable-shared=no --prefix=$(pwd)/stage --host=arm-linux-gnueabihf
直接make编译
hya@ubuntu:~/workspace/astrometry.net-0.93$ make
make -C gsl-an
make[1]: 进入目录“/home/hya/workspace/astrometry.net-0.93/gsl-an”
arm-linux-gnueabihf-gcc -g -Wall -ffinite-math-only -fno-signaling-nans -pthread -m64 -O3 -fomit-frame-pointer -DNDEBUG -fpic -fPIC -Winline -I../include -I../include/astrometry -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -DAN_GIT_REVISION='"0.93"' -DAN_GIT_DATE='"Mon_Dec_19_16:41:15_2022_-0500"' -DAN_GIT_URL='"https://github.com/dstndstn/astrometry.net"' -I. -c -o blas/blas.o blas/blas.c
arm-linux-gnueabihf-gcc: 错误: unrecognized command line option ‘-m64’
<内置>: recipe for target 'blas/blas.o' failed
make[1]: *** [blas/blas.o] Error 1
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/gsl-an”
Makefile:92: recipe for target 'gsl-an' failed
make: *** [gsl-an] Error 2
打印报错有 -m64的选项,这个是arm64架构的编译信息,但是查找Makefile没有找到 -m64的信息,
查找发现在另一个文件里,直接屏蔽掉这个选项
hya@ubuntu:~/workspace/astrometry.net-0.93$ grep -rn "m64"
util/makefile.common:206: #FLAGS_DEF += -m64
util/ctmf.c:146: *(__m64*) &y[0] = _mm_add_pi16( *(__m64*) &y[0], *(__m64*) &x[0] );
util/ctmf.c:147: *(__m64*) &y[4] = _mm_add_pi16( *(__m64*) &y[4], *(__m64*) &x[4] );
util/ctmf.c:148: *(__m64*) &y[8] = _mm_add_pi16( *(__m64*) &y[8], *(__m64*) &x[8] );
util/ctmf.c:149: *(__m64*) &y[12] = _mm_add_pi16( *(__m64*) &y[12], *(__m64*) &x[12] );
util/ctmf.c:188: *(__m64*) &y[0] = _mm_sub_pi16( *(__m64*) &y[0], *(__m64*) &x[0] );
util/ctmf.c:189: *(__m64*) &y[4] = _mm_sub_pi16( *(__m64*) &y[4], *(__m64*) &x[4] );
util/ctmf.c:190: *(__m64*) &y[8] = _mm_sub_pi16( *(__m64*) &y[8], *(__m64*) &x[8] );
util/ctmf.c:191: *(__m64*) &y[12] = _mm_sub_pi16( *(__m64*) &y[12], *(__m64*) &x[12] );
make编译可以看到工程开始编译了
hya@ubuntu:~/workspace/astrometry.net-0.93$ make
make -C gsl-an
make[1]: 进入目录“/home/hya/workspace/astrometry.net-0.93/gsl-an”
make[1]: 对“all”无需做任何事。
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/gsl-an”
make -C util config
make[1]: 进入目录“/home/hya/workspace/astrometry.net-0.93/util”
make[1]: 对“config”无需做任何事。
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/util”
make -C qfits-an
make[1]: 进入目录“/home/hya/workspace/astrometry.net-0.93/qfits-an”
make[1]: 对“all”无需做任何事。
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/qfits-an”
make -C util
make[1]: 进入目录“/home/hya/workspace/astrometry.net-0.93/util”
make[1]: 对“all”无需做任何事。
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/util”
make -C libkd
make[1]: 进入目录“/home/hya/workspace/astrometry.net-0.93/libkd”
make[1]: 对“all”无需做任何事。
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/libkd”
make -C catalogs
make[1]: 进入目录“/home/hya/workspace/astrometry.net-0.93/catalogs”
arm-linux-gnueabihf-gcc -g -Wall -ffinite-math-only -fno-signaling-nans -pthread -O3 -fomit-frame-pointer -DNDEBUG -fpic -fPIC -Winline -I../include -I../include/astrometry -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -DAN_GIT_REVISION='"0.93"' -DAN_GIT_DATE='"Mon_Dec_19_16:41:15_2022_-0500"' -DAN_GIT_URL='"https://github.com/dstndstn/astrometry.net"' -I../include -I../include/astrometry -I../gsl-an -I../include -I../include/astrometry -I../gsl-an -I. -I../util /usr/include -c -o 2masstofits.o 2masstofits.c
2masstofits.c:11:18: 致命错误: zlib.h:没有那个文件或目录
#include <zlib.h>
^
编译中断。
<内置>: recipe for target '2masstofits.o' failed
make[1]: *** [2masstofits.o] Error 1
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/catalogs”
Makefile:90: recipe for target 'catalogs' failed
make: *** [catalogs] Error 2
报错找不到zlib.h,查看发现Ubuntu系统和buildroot里都有zlib.h,通过指定库路径的方式还是报错找不到zlib.h
hya@ubuntu:~/workspace/astrometry.net-0.93$ cat util/makefile.zlib
# This file is part of the Astrometry.net suite.
# Licensed under a 3-clause BSD style license - see LICENSE
ZLIB_INC ?= //home/hya/workspace/RV1126SDK/buildroot/output/rockchip_rv1126_rv1109/host/include
ZLIB_LIB ?= /home/hya/workspace/RV1126SDK/buildroot/output/rockchip_rv1126_rv1109/build/host-libzlib-1.2.11/
直接把zlib.h和zconf.h拷贝到工程的include中
重新make编译报错
hya@ubuntu:~/workspace/astrometry.net-0.93$ make
make -C gsl-an
make[1]: 进入目录“/home/hya/workspace/astrometry.net-0.93/gsl-an”
make[1]: 对“all”无需做任何事。
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/gsl-an”
make -C util config
make[1]: 进入目录“/home/hya/workspace/astrometry.net-0.93/util”
make[1]: 对“config”无需做任何事。
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/util”
make -C qfits-an
make[1]: 进入目录“/home/hya/workspace/astrometry.net-0.93/qfits-an”
make[1]: 对“all”无需做任何事。
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/qfits-an”
make -C util
make[1]: 进入目录“/home/hya/workspace/astrometry.net-0.93/util”
make[1]: 对“all”无需做任何事。
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/util”
make -C libkd
make[1]: 进入目录“/home/hya/workspace/astrometry.net-0.93/libkd”
make[1]: 对“all”无需做任何事。
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/libkd”
make -C catalogs
make[1]: 进入目录“/home/hya/workspace/astrometry.net-0.93/catalogs”
arm-linux-gnueabihf-gcc -g -Wall -ffinite-math-only -fno-signaling-nans -pthread -O3 -fomit-frame-pointer -DNDEBUG -fpic -fPIC -Winline -I../include -I../include/astrometry -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -DAN_GIT_REVISION='"0.93"' -DAN_GIT_DATE='"Mon_Dec_19_16:41:15_2022_-0500"' -DAN_GIT_URL='"https://github.com/dstndstn/astrometry.net"' -I../include -I../include/astrometry -I../gsl-an -I../include -I../include/astrometry -I../gsl-an -I. -I../util -c -o 2masstofits.o 2masstofits.c
echo ZLIB_LIB is -lz
ZLIB_LIB is -lz
arm-linux-gnueabihf-gcc -o 2masstofits -g -Wall -ffinite-math-only -fno-signaling-nans -pthread -O3 -fomit-frame-pointer -DNDEBUG -fpic -fPIC -Winline 2masstofits.o libcatalogs.a ../util/libanfiles.a ../libkd/libkd.a ../util/libanutils.a ../qfits-an/libqfits.a ../util/libanbase.a ../gsl-an/libgsl-an.a -lm -lm -lm -lz
/home/hya/workspace/RV1126SDK/prebuilts/gcc/linux-x86/arm/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/6.3.1/../../../../arm-linux-gnueabihf/bin/ld: 找不到 -lz
collect2: 错误: ld 返回 1
Makefile:127: recipe for target '2masstofits' failed
make[1]: *** [2masstofits] Error 1
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/catalogs”
Makefile:90: recipe for target 'catalogs' failed
make: *** [catalogs] Error 2
查看~/workspace/astrometry.net-0.93/catalogs/Makefile下关于lz的内容,被定义为ZLIB_LIB
手动定义libz库
export ZLIB_LIB=/home/hya/workspace/RV1126SDK/buildroot/output/rockchip_rv1126_rv1109/build/libzlib-1.2.11/libz.so.1.2.11
重新编译
报错缺少文件,在buildroot中找到拷贝到工程include里
arm-linux-gnueabihf-gcc -g -Wall -ffinite-math-only -fno-signaling-nans -pthread -O3 -fomit-frame-pointer -DNDEBUG -fpic -fPIC -Winline -I../include -I../include/astrometry -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -DAN_GIT_REVISION='"0.93"' -DAN_GIT_DATE='"Mon_Dec_19_16:41:15_2022_-0500"' -DAN_GIT_URL='"https://github.com/dstndstn/astrometry.net"' -I../include -I../include/astrometry -I../gsl-an -I../include -I../include/astrometry -I../gsl-an -I. -I../util -c -o ucac5tofits.o ucac5tofits.c
ucac5tofits.c:18:19: 致命错误: bzlib.h:没有那个文件或目录
#include <bzlib.h>
^
编译中断。
<内置>: recipe for target 'ucac5tofits.o' failed
make[1]: *** [ucac5tofits.o] Error 1
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/catalogs”
Makefile:90: recipe for target 'catalogs' failed
make: *** [catalogs] Error 2
再次重新编译报错,缺少libz2的库
arm-linux-gnueabihf-gcc -o ucac5tofits -g -Wall -ffinite-math-only -fno-signaling-nans -pthread -O3 -fomit-frame-pointer -DNDEBUG -fpic -fPIC -Winline ucac5tofits.o libcatalogs.a ../util/libanfiles.a ../libkd/libkd.a ../util/libanutils.a ../qfits-an/libqfits.a ../util/libanbase.a ../gsl-an/libgsl-an.a -lm -lm -lm -lbz2
/home/hya/workspace/RV1126SDK/prebuilts/gcc/linux-x86/arm/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/6.3.1/../../../../arm-linux-gnueabihf/bin/ld: 找不到 -lbz2
collect2: 错误: ld 返回 1
Makefile:123: recipe for target 'ucac5tofits' failed
make[1]: *** [ucac5tofits] Error 1
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/catalogs”
Makefile:90: recipe for target 'catalogs' failed
make: *** [catalogs] Error 2
在buildroot中make menuconfig,打开bzlp2的编译选项
BR2_PACKAGE_BZIP2=y
系统里这个库的链接已经失效了,需要自己下载,然后移植到buidlroot/dl下
bzip2 download | SourceForge.net
修改catalogs/Makefile
ucac3tofits: ucac3tofits.o $(SLIB)
#$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) -lbz2
$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) $(BZ2_LIB)
ALL_OBJ += ucac3tofits.o
ucac4tofits: ucac4tofits.o $(SLIB)
#$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) -lbz2
$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) $(BZ2_LIB)
ALL_OBJ += ucac4tofits.o
ucac5tofits: ucac5tofits.o $(SLIB)
#$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) -lbz2
$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) $(BZ2_LIB)
手动定义库的路径
export BZ2_LIB=/home/hya/workspace/RV1126SDK/buildroot/output/rockchip_rv1126_rv1109/build/bzip2-1.0.6/libbz2.so.1.0.6
重新编译
报错缺少头文件,从buildroot环境中拷贝到交叉编译环境中。
编译报错没有链接libcfitsio.so.8.3.47
按照之前的方法,查看Makefile的库定义为CFITS_LIB,通过export设置其路径
export CFITS_LIB=/home/hya/workspace/RV1126SDK/buildroot/output/rockchip_rv1126_rv1109/target/usr/lib/libcfitsio.so.8.3.47
重新编译报错
arm-linux-gnueabihf-gcc -o image2xy -g -Wall -ffinite-math-only -fno-signaling-nans -pthread -O3 -fomit-frame-pointer -DNDEBUG -fpic -fPIC -Winline image2xy-main.o image2xy-files.o libastrometry.a ../catalogs/libcatalogs.a ../util/libanfiles.a ../libkd/libkd.a ../util/libanutils.a ../qfits-an/libqfits.a ../util/libanbase.a ../gsl-an/libgsl-an.a /home/hya/workspace/RV1126SDK/buildroot/output/rockchip_rv1126_rv1109/target/usr/lib/libcfitsio.so.8.3.47 -lm -lm
/home/hya/workspace/RV1126SDK/buildroot/output/rockchip_rv1126_rv1109/target/usr/lib/libcfitsio.so.8.3.47:对‘fcntl64@GLIBC_2.28’未定义的引用
collect2: 错误: ld 返回 1
Makefile:288: recipe for target 'image2xy' failed
make[1]: *** [image2xy] Error 1
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/solver”
fcntl64未定义引用的错误
通过交叉编译工具查看libcfitsio库是否有fcntl64的符号
arm-linux-gnueabihf-nm -D target/usr/lib/libcfitsio.so.8.3.47 | grep fcntl64
U fcntl64
可以看到是有这个符号定义的
所以考虑是交叉编译工具链版本问题
hya@ubuntu:~/workspace/RV1126SDK/buildroot/output/rockchip_rv1126_rv1109$ arm-linux-gnueabihf-ld --version
GNU ld (Linaro_Binutils-2017.05) 2.27.0.20161019
Copyright (C) 2016 Free Software Foundation, Inc.
这个程序是自由软件;您可以遵循GNU 通用公共授权版本 3 或
(您自行选择的) 稍后版本以再次散布它。
这个程序完全没有任何担保。
交叉编译工具的GLIBC版本为2.27,链接cfitsio库需要的GLIBC版本为2.28
尝试升级cfitsio库版本,升级后修改链接高版本的库,有更多报错,且仍然有glibc兼容性问题的报错
尝试升级交叉编译工具链,不过修改交叉编译工具链风险较大,因为整个buildroot系统也是依赖交叉编译工具链的,即使能编译astrometry.net,移植到buildroot里也会因为GLIBC版本问题而不能运行
测试发现交叉编译源码时就会有兼容性问题
/home/hya/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/10.3.1/../../../../arm-none-linux-gnueabihf/bin/ld: ../util/libanutils.a(dallpeaks.o): in function `max_gaussian':
/home/hya/workspace/astrometry.net-0.93/util/dallpeaks.c:79: undefined reference to `__exp_finite'
/home/hya/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/10.3.1/../../../../arm-none-linux-gnueabihf/bin/ld: ../util/libanutils.a(dsigma.o): in function `dsigma':
/home/hya/workspace/astrometry.net-0.93/util/dsigma.inc:69: undefined reference to `__sqrtf_finite'
/home/hya/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/10.3.1/../../../../arm-none-linux-gnueabihf/bin/ld: ../util/libanutils.a(dsigma.o): in function `dsigma_u8':
/home/hya/workspace/astrometry.net-0.93/util/dsigma.inc:69: undefined reference to `__sqrtf_finite'
/home/hya/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/10.3.1/../../../../arm-none-linux-gnueabihf/bin/ld: ../util/libanutils.a(dsmooth.o): in function `dsmooth2':
/home/hya/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/10.3.1/../../../../arm-none-linux-gnueabihf/bin/ld: /home/hya/workspace/astrometry.net-0.93/util/resample.inc:107: undefined reference to `__hypot_finite'
/home/hya/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/10.3.1/../../../../arm-none-linux-gnueabihf/bin/ld: ../util/libanbase.a(resample.o): in function `lanczos_resample_d':
/home/hya/workspace/astrometry.net-0.93/util/resample.inc:107: undefined reference to `__hypot_finite'
/home/hya/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/10.3.1/../../../../arm-none-linux-gnueabihf/bin/ld: /home/hya/workspace/astrometry.net-0.93/util/resample.inc:107: undefined reference to `__hypot_finite'
collect2: 错误: ld 返回 1
Makefile:288: recipe for target 'image2xy' failed
make[1]: *** [image2xy] Error 1
make[1]: 离开目录“/home/hya/workspace/astrometry.net-0.93/solver”
检查Ubuntu环境中GLIBC版本和libcfitsio版本情况,GLIBC版本为2.27,libcfitsio版本为3.43
hya@ubuntu:~/workspace/RV1126SDK$ ldd --version
ldd (Ubuntu GLIBC 2.27-3ubuntu1.6) 2.27
-------------------------------------------------------
正在读取状态信息... 完成
libcfitsio-dev 已经是最新版 (3.430-2)。
交叉编译环境的GLIBC版本也是2.27,但是libcfitsio版本为3.47,已经是官网上能找到的最老的版本了,要想办法找一个3.43版本的包测试
Index of /FTP/software/fitsio/c
随后发现官网cfitsio3430.zip就是指3.43版本,命名方式不同
下载到本地后,添加到buildroot框架中发现没有编译
自己手动编译测试,解压后进入cfitsio根目录
./configure --host=arm-linux-gnueabihf
make
sudo make install
编译完的库装到了本地lib下
hya@ubuntu:~/cfitsio/lib$ ls
libcfitsio.a pkgconfig
修改库路径
export CFITS_LIB=/home/hya/cfitsio/lib/libcfitsio.a
重新交叉编译
make clean
make
可以看到通过了
整个交叉编译工程在这里
hya@ubuntu:/usr/local/astrometry$ ls
bin data doc etc examples include lib share
用file命令查看bin下的可执行程序,是arm32位的,所以确实是交叉编译生成的
sudo scp -r astrometry/ root@192.168.1.1:/workspace
通过scp,把整个交叉编译的环境移植到板子上测试,运行正常
测试依赖python的可执行程序报错,
[root@owlvtech:/workspace/astrometry/bin]# ./text2fits -h
/usr/bin/env: 'python3': No such file or directory
需要给板子搭建python环境
利用buildroot,直接通过make menuconfig来搭建
搜索python3,选择后重新编译buildroot
测试发现报错没有numpy模块
还需要搜索安装numpy(注意不是host-numpy),安装因为python环境的构建问题,需要把output/rv1126下host-python*全部删掉,重新构建
安装python会自动构建cython和setuptools
cython的下载链接已经不存在了,要在这里下载后放到buildroot/dl下
numpy的包同样在下面的链接下载,放到buildroot/dl下
重新测试,python环境也没问题了
3、关于交叉编译的总结
1、简单工程
一个简单的项目,例如仅几个.c 或 .h文件的项目,完全可以使用命令行的方式来处理,直接使用交叉编译工具链编译出可执行程序,拷贝到板子上就可以运行
arm-linux-gnueabihf-gcc main.c mong.c mong.h -o example
2、复杂工程
复杂工程还需要考虑交叉编译链接器的问题
像astrometry.net这样的工程,依赖众多的库和头文件,交叉编译时,需要提前交叉编译好依赖库
(1)依赖库的编译
依赖库的交叉编译可以参考笔记开头的方式,在buildroot的框架里去编译,可以通过修改.mk文件来设置版本。但熟练以后更推荐手动下载后使用交叉编译工具链手动编译(可以灵活的选择版本),然后将编译出来的库移植到交叉编译环境。
关于依赖库版本的选择问题,可以提前在Ubuntu中测试好,在Ubuntu中运行没问题以后,把依赖库版本确定下来,交叉编译时就按照Ubuntu中约定的来,另外需要注意的就是交叉编译工具链和Ubuntu的GLIBC版本问题,不过rockchip之前可能已经考虑到这个问题,所以rv1126的SDK推荐使用ubuntu18来编译,查看发现Ubuntu的GLIBC版本与交叉编译工具链一致
(2)Makefile文件
astrometry.net工程要编译很多源码,其中大部分都定义在各子目录的Makefile中,
例如~/workspace/astrometry.net-0.93下的Makefile文件
通过阅读此Makefile,得知工程的编译工具链被定义为$(CC)
所以通过export 可以直接将CC设置为交叉编译工具链
export CC=arm-linux-gnueabihf-gcc
再例如~/workspace/astrometry.net-0.93/catalogs/Makefile
这里定义了许多源码的编译规则,包括要链接的库路径,但由于我们是交叉编译环境,所以不能使用ubuntu下的库,只能将原来的编译规则注释掉,手动定义一个$(BZ2_LIB),并通过export去选择这个库的路径,这里的库是提前交叉编译好的
export BZ2_LIB=/home/hya/workspace/RV1126SDK/buildroot/output/rockchip_rv1126_rv1109/build/bzip2-1.0.6/libbz2.so.1.0.6
需要注意的是,export设置的东西仅在此终端生效,因为是临时的环境变量
同理最后一行的ZLIB_LIB也是这样设置
ucac3tofits: ucac3tofits.o $(SLIB)
#$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) -lbz2
$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) $(BZ2_LIB)
ALL_OBJ += ucac3tofits.o
ucac4tofits: ucac4tofits.o $(SLIB)
#$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) -lbz2
$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) $(BZ2_LIB)
ALL_OBJ += ucac4tofits.o
ucac5tofits: ucac5tofits.o $(SLIB)
#$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) -lbz2
$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) $(BZ2_LIB)
ALL_OBJ += ucac5tofits.o
2masstofits: 2masstofits.o $(SLIB)
echo ZLIB_LIB is $(ZLIB_LIB)
$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) $(ZLIB_LIB)
总之在实际交叉编译过程中,会遇到各种的缺少头文件和无法链接到正确库的路径,参考上文中的解决方法即可
在buildroot中交叉编译一个大工程是很让人头疼的事,各种报错,需要一点一点解决,关于交叉编译的问题,欢迎交流