静态编译失败创建库

静态编译失败创建库

对于某些救援任务,我需要在二进制文件中编译 extundelete 和一些其他带有共享库的工具。

我已经搜索了选项configure以及makeAskUbuntu 条目等。我发现了使用-strict选项(单连字符)的建议。不幸的是,我无法让它工作。

我做了通常的操作apt source install extundelete,,,./configure当然make还通过在 ./configure 和 make 中添加“-static”来完成此操作。什么也不做,不起作用。

最后,我通过在 LDFLAGS 环境变量中输入“-static”得到了一些提示。现在至少我得到了一条具体的错误消息!

./configure LDFLAGS=-static

Configuring extundelete 0.2.4
configure: error: Can't find ext2fs library

我发现的所有建议都指向缺少 e2fslibs-dev 和/或 libext2fs-dev 包。安装这些包后,错误消息仍然相同。Can't find ext2fs library

以防万一,我检查了包的内容,实际上有 ext2fs 库,或者看起来是这样。

dpkg -L libext2fs-dev | grep ext2fs
/usr/include/ext2fs
/usr/include/ext2fs/bitops.h
/usr/include/ext2fs/ext2_err.h
/usr/include/ext2fs/ext2_ext_attr.h
/usr/include/ext2fs/ext2_fs.h
/usr/include/ext2fs/ext2_io.h
/usr/include/ext2fs/ext2_types.h
/usr/include/ext2fs/ext2fs.h
/usr/include/ext2fs/ext3_extents.h
/usr/include/ext2fs/qcow2.h
/usr/include/ext2fs/tdb.h
/usr/lib/x86_64-linux-gnu/libext2fs.a
/usr/lib/x86_64-linux-gnu/pkgconfig/ext2fs.pc
/usr/lib/x86_64-linux-gnu/libext2fs.so
/usr/share/doc/libext2fs-dev

此时我的黑客资源已经耗尽。任何帮助我都十分欢迎。提前致谢。

答案1

如果你查看该config.log文件,你可能会发现,虽然错误消息是Can't find ext2fs library,但实际错误与未定义的引用有关之内 libext2fs.a

configure:5298: checking for ext2fs_bmap in -lext2fs
configure:5323: gcc -o conftest   -static conftest.c -lext2fs   >&5
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libext2fs.a(alloc_stats.o): In function `ext2fs_inode_alloc_stats2':
(.text+0x106): undefined reference to `com_err'

我能够使用它来配置和构建它

./configure CFLAGS=-pthread LDFLAGS='-pthread -static' LIBS=-lcom_err
make

IE

$ file -b ./src/extundelete
ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=a03a7d251e42c8a9182b062841f81e5d1cccc7c7, with debug_info, not stripped

请注意,我没有尝试实际运行它

如果省略这些-pthread选项,则可能会出现有关未解析的信号量原型sem_wait等的其他错误。我不知道这是否是“正确”的解决方案

相关内容