在交叉编译systemd的时候,遇到上面的报错。
步骤是这样的:
export CFLAGS="-I/home/charles/code/build_systemd/libcap2-2.24/libcap/include"
export LDFLAGS="-L/home/charles/code/build_systemd/libcap2-2.24/libcap"
./configure --host=arm-linux-gnueabi
错误如下:
checking for linux/vm_sockets.h... yes
checking for library containing clock_gettime... none required
checking for library containing cap_init... no
configure: error: *** POSIX caps library not found
可是,caps 库文件是存在的:
$ ls /home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.*
/home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.a
/home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.h
/home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.pc
/home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.pc.in
/home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.so
/home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.so.2
/home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.so.2.24
看一下 config.log,里面有这样的错误:
configure:16647: arm-linux-gnueabi-gcc -o conftest -I/home/charles/code/build_systemd/libcap2-2.24/libcap/include -L/home/charles/code/build_systemd/libcap2-2.24/libcap conftest.c -lcap >&5
/toolchain/armv7-gcc-6.3/bin/../lib/gcc/arm-linux-gnueabi/6.3.0/../../../../arm-linux-gnueabi/bin/ld: warning: libattr.so.1, needed by /home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.so, not found (try using -rpath or -rpath-link)
/home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.so: undefined reference to `removexattr@ATTR_1.0'
/home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.so: undefined reference to `fremovexattr@ATTR_1.0'
/home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.so: undefined reference to `getxattr@ATTR_1.0'
/home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.so: undefined reference to `setxattr@ATTR_1.0'
/home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.so: undefined reference to `fsetxattr@ATTR_1.0'
/home/charles/code/build_systemd/libcap2-2.24/libcap/libcap.so: undefined reference to `fgetxattr@ATTR_1.0'
collect2: error: ld returned 1 exit status
configure:16647: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "systemd"
| #define PACKAGE_TARNAME "systemd"
| #define PACKAGE_VERSION "233"
| #define PACKAGE_STRING "systemd 233"
| #define PACKAGE_BUGREPORT "https://github.com/systemd/systemd/issues"
| #define PACKAGE_URL "https://www.freedesktop.org/wiki/Software/systemd"
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define __EXTENSIONS__ 1
| #define _ALL_SOURCE 1
| #define SIZEOF_DEV_T 8
| #define SIZEOF_INO_T 8
| #define SIZEOF_RLIM_T 8
| #define GPERF_LEN_TYPE size_t
| #define HAVE_SYS_CAPABILITY_H 1
| #define HAVE_LINUX_BTRFS_H 1
| #define HAVE_LINUX_MEMFD_H 1
| #define HAVE_LINUX_VM_SOCKETS_H 1
| /* end confdefs.h. */
|
| /* Override any GCC internal prototype to avoid an error.
|Use char because int might match the return type of a GCC
|builtin and then its argument prototype would still apply. */
| #ifdef __cplusplus
| extern "C"
| #endif
| char cap_init ();
| int
| main ()
| {
| return cap_init ();
| ;
| return 0;
| }
configure:16664: result: no
configure:16671: error: *** POSIX caps library not found
原来,错误的原因是没有加上 -lattr.
修改如下:
export LDFLAGS="-L/home/charles/code/build_systemd/libcap2-2.24/libcap -L/home/charles/code/build_systemd/attr-2.4.47/libattr/.libs -lattr"
重新执行 configure,通过了。