交叉编译parted命令bug记录
Linux parted命令编译
parted源码在上个随笔中已记述相关代码下载方法(ftp:https://ftp.gnu.org/gnu/parted/) 可以下载到想要的版本,还需要使用到libuuid,e2fsprogs等库,当这些库按照编译命令编译后得到对应的lib和头文件。
libuuid相关代码下载和安装可参考https://blog.csdn.net/qq_41622776/article/details/107639794,按照博客使用的方法,parted3.2版本编译到现有平台会出现以下问题:
编译命令为CFLAGS=-I/home/linux_parted/e2fsprogs-master/arch/include/ LDFLAGS=-L/home/linux_parted/e2fsprogs-master/arch/lib CC=mips-linux-gnu-gcc ../configure --prefix=/home/linux_parted/parted-3.2/arch --host=mips-linux --host=mips-linux --disable-device-mapper --without-readline --without-readline --disable-shared --disable-nls --disable-dynamic-loading
../../libparted/arch/linux.c: In function 'dm_canonical_path':
../../libparted/arch/linux.c:2313:32: warning: implicit declaration of function 'dm_task_create'; did you mean 'timer_create'? [-Wimplicit-function-declaration]
struct dm_task *task = dm_task_create (DM_DEVICE_INFO);
^~~~~~~~~~~~~~
timer_create
../../libparted/arch/linux.c:2313:48: error: 'DM_DEVICE_INFO' undeclared (first use in this function); did you mean '_SC_DEVICE_IO'?
struct dm_task *task = dm_task_create (DM_DEVICE_INFO);
^~~~~~~~~~~~~~
_SC_DEVICE_IO
../../libparted/arch/linux.c:2313:48: note: each undeclared identifier is reported only once for each function it appears in
../../libparted/arch/linux.c:2316:14: warning: implicit declaration of function 'dm_task_set_major_minor' [-Wimplicit-function-declaration]
if (!dm_task_set_major_minor (task, arch_specific->major,
^~~~~~~~~~~~~~~~~~~~~~~
../../libparted/arch/linux.c:2319:14: warning: implicit declaration of function 'dm_task_run' [-Wimplicit-function-declaration]
if (!dm_task_run(task))
^~~~~~~~~~~
../../libparted/arch/linux.c:2321:55: warning: implicit declaration of function 'dm_task_get_name'; did you mean 'ped_unit_get_name'? [-Wimplicit-function-declaration]
char *dev_name = zasprintf ("/dev/mapper/%s", dm_task_get_name (task));
^~~~~~~~~~~~~~~~
ped_unit_get_name
../../libparted/arch/linux.c:2324:9: warning: implicit declaration of function 'dm_task_destroy'; did you mean 'ped_disk_destroy'? [-Wimplicit-function-declaration]
dm_task_destroy (task);
^~~~~~~~~~~~~~~
ped_disk_destroy
../../libparted/arch/linux.c: In function '_disk_sync_part_table':
../../libparted/arch/linux.c:2949:33: error: '_dm_add_partition' undeclared (first use in this function); did you mean 'add_partition'?
add_partition = _dm_add_partition;
^~~~~~~~~~~~~~~~~
add_partition
../../libparted/arch/linux.c:2950:36: error: '_dm_remove_partition' undeclared (first use in this function); did you mean 'remove_partition'?
remove_partition = _dm_remove_partition;
^~~~~~~~~~~~~~~~~~~~
remove_partition
../../libparted/arch/linux.c:2951:36: error: '_dm_resize_partition' undeclared (first use in this function); did you mean '_dm_remove_partition'?
resize_partition = _dm_resize_partition;
^~~~~~~~~~~~~~~~~~~~
_dm_remove_partition
../../libparted/arch/linux.c:2952:50: error: '_dm_get_partition_start_and_length' undeclared (first use in this function); did you mean 'get_partition_start_and_length'?
get_partition_start_and_length = _dm_get_partition_start_and_length;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
get_partition_start_and_length
Makefile:1359: recipe for target 'arch/linux.lo' failed
make[3]: *** [arch/linux.lo] Error 1
make[3]: Leaving directory '/home/linux_parted/parted-3.2/build/libparted'
Linux parted命令编译问题思考:
1 代码parted3.2中已经有libparted源码了,在编译目录parted3.2/build下执行make会出现libparted目录,此时Makefile执行编译
make[3]: Entering directory '/home/linux_parted/parted-3.2/build/libparted'
CC debug.lo
CC architecture.lo
CC device.lo
CC exception.lo
CC filesys.lo
CC libparted.lo
CC timer.lo
CC unit.lo
CC disk.lo
CC cs/geom.lo
CC cs/constraint.lo
CC cs/natmath.lo
CC arch/linux.lo
接着便是build/libparted/arch 目录下linux.c中编译过程中出现的未声明函数直接调用导致的错误!使用meld命令对比parted3.2/build/libparted/arch/linux.c和parted3.2/libparted/arch/linux.c发现
parted3.2/build/libparted/arch没有生成linux.c文件,那么反推到parted3.2/build/Makefile文件编译parted3.2/libparted/Makefile.am Makefile.in文件生成.lo文件,那么问题究竟出在哪呢?
终于找到这篇博客:
https://blog.csdn.net/u011924787/article/details/63251851?spm=1001.2101.3001.6650.16&depth_1-utm_relevant_index=19
Linux parted中打个patch后还是有major/minor问题,
../libparted/.libs/libparted.a(linux.o): In function `_device_probe_type':
linux.c:(.text+0x788): undefined reference to `major'
linux.c:(.text+0x7a8): undefined reference to `minor'
collect2: error: ld returned 1 exit status
Makefile:1228: recipe for target 'parted' failed
make[3]: *** [parted] Error 1
make[3]: Leaving directory '/home/linux_parted/parted-3.2/build/parted'
Makefile:1135: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/home/hcy/linux_parted/parted-3.2/build/parted'
Makefile:1265: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/linux_parted/parted-3.2/build'
Makefile:1188: recipe for target 'all' failed
make: *** [all] Error 2
参考https://blog.csdn.net/cinmyheart/article/details/21877487解决问题
顺利解决问题!!
谢谢以上提及的博客楼主们!!!