Make 似乎忽略了我的 CFLAGS 和 LDFLAGS
Make seems to ignore my CFLAGS and LDFLAGS
我在交叉编译 fuse-exfat 时遇到问题。
GCC 找不到我的保险丝库。
我 运行 在 x64-64 机器上构建并为 ARM 编译。
正如您在这里看到的,包含文件和库都在那里:
root@2a13b22d5372:/opt/sysroot/usr/lib# ls -al | grep fuse
-rwxr-xr-x 1 root root 943 Jul 5 16:31 libfuse.la
lrwxrwxrwx 1 root root 16 Jul 5 16:31 libfuse.so -> libfuse.so.2.9.9
lrwxrwxrwx 1 root root 16 Jul 5 16:31 libfuse.so.2 -> libfuse.so.2.9.9
-rwxr-xr-x 1 root root 719756 Jul 5 16:31 libfuse.so.2.9.9
lrwxrwxrwx 1 root root 17 Jul 5 15:53 libfuse3.so -> libfuse3.so.3.6.1
lrwxrwxrwx 1 root root 17 Jul 5 15:48 libfuse3.so.3 -> libfuse3.so.3.6.1
-rwxr-xr-x 1 root root 698096 Jul 5 15:47 libfuse3.so.3.6.1
root@2a13b22d5372:/opt/sysroot/usr/include# ls -al | grep fuse
drwxr-xr-x 2 root root 4096 Jul 5 16:31 fuse
-rw-r--r-- 1 root root 246 Jul 5 16:31 fuse.h
drwxr-xr-x 2 root root 4096 Jul 5 16:03 fuse3
运行 配置没有给出任何错误。
root@2a13b22d5372:/opt/fuse-exfat-1.3.0# ./configure --prefix=/opt/sysroot --host=arm-linux-gnueabihf
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-linux-gnueabihf-strip... arm-linux-gnueabihf-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for arm-linux-gnueabihf-gcc... arm-linux-gnueabihf-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-linux-gnueabihf-gcc accepts -g... yes
checking for arm-linux-gnueabihf-gcc option to accept ISO C89... none needed
checking whether arm-linux-gnueabihf-gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of arm-linux-gnueabihf-gcc... gcc3
checking for arm-linux-gnueabihf-gcc option to accept ISO C99... none needed
checking for arm-linux-gnueabihf-ranlib... arm-linux-gnueabihf-ranlib
checking for arm-linux-gnueabihf-ar... arm-linux-gnueabihf-ar
checking the archiver (arm-linux-gnueabihf-ar) interface... ar
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... 64
checking for arm-linux-gnueabihf-pkg-config... no
checking for pkg-config... /usr/bin/pkg-config
configure: WARNING: using cross tools not prefixed with host triplet
checking pkg-config is at least version 0.9.0... yes
checking for UBLIO... no
checking for FUSE... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating libexfat/Makefile
config.status: creating fuse/Makefile
config.status: creating Makefile
config.status: creating libexfat/config.h
config.status: libexfat/config.h is unchanged
config.status: executing depfiles commands
Make 失败并出现 "cannot find lib" 错误。
root@2a13b22d5372:/opt/fuse-exfat-1.3.0# LDFLAGS="-L/opt/sysroot/usr/lib" CFLAGS="-I/opt/sysroot/usr/include" make
Making all in libexfat
make[1]: Entering directory '/opt/fuse-exfat-1.3.0/libexfat'
make all-am
make[2]: Entering directory '/opt/fuse-exfat-1.3.0/libexfat'
make[2]: Leaving directory '/opt/fuse-exfat-1.3.0/libexfat'
make[1]: Leaving directory '/opt/fuse-exfat-1.3.0/libexfat'
Making all in fuse
make[1]: Entering directory '/opt/fuse-exfat-1.3.0/fuse'
arm-linux-gnueabihf-gcc -D_FILE_OFFSET_BITS=64 -I/usr/include/fuse -g -O2 -o mount.exfat-fuse mount_exfat_fuse-main.o ../libexfat/libexfat.a -lfuse -pthread
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lfuse
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:399: mount.exfat-fuse] Error 1
make[1]: Leaving directory '/opt/fuse-exfat-1.3.0/fuse'
make: *** [Makefile:363: all-recursive] Error 1
我错过了什么?
根据此处的信息,我们无法确定。
但是,makefile 可能设置了 LDFLAGS
和 CFLAGS
变量。在 makefile 中分配的变量将优先于从环境中获得的变量,因此您的变量分配将被忽略。
我建议您尝试在 make 命令行上传递变量赋值,而不是通过环境:
$ make LDFLAGS="-L/opt/sysroot/usr/lib" CFLAGS="-I/opt/sysroot/usr/include"
(PS 以 root 身份构建东西和 运行 几乎总是一个坏主意——事实上几乎总是一个坏主意任何事情 作为 root,除非需要它)
我在交叉编译 fuse-exfat 时遇到问题。 GCC 找不到我的保险丝库。 我 运行 在 x64-64 机器上构建并为 ARM 编译。
正如您在这里看到的,包含文件和库都在那里:
root@2a13b22d5372:/opt/sysroot/usr/lib# ls -al | grep fuse
-rwxr-xr-x 1 root root 943 Jul 5 16:31 libfuse.la
lrwxrwxrwx 1 root root 16 Jul 5 16:31 libfuse.so -> libfuse.so.2.9.9
lrwxrwxrwx 1 root root 16 Jul 5 16:31 libfuse.so.2 -> libfuse.so.2.9.9
-rwxr-xr-x 1 root root 719756 Jul 5 16:31 libfuse.so.2.9.9
lrwxrwxrwx 1 root root 17 Jul 5 15:53 libfuse3.so -> libfuse3.so.3.6.1
lrwxrwxrwx 1 root root 17 Jul 5 15:48 libfuse3.so.3 -> libfuse3.so.3.6.1
-rwxr-xr-x 1 root root 698096 Jul 5 15:47 libfuse3.so.3.6.1
root@2a13b22d5372:/opt/sysroot/usr/include# ls -al | grep fuse
drwxr-xr-x 2 root root 4096 Jul 5 16:31 fuse
-rw-r--r-- 1 root root 246 Jul 5 16:31 fuse.h
drwxr-xr-x 2 root root 4096 Jul 5 16:03 fuse3
运行 配置没有给出任何错误。
root@2a13b22d5372:/opt/fuse-exfat-1.3.0# ./configure --prefix=/opt/sysroot --host=arm-linux-gnueabihf
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-linux-gnueabihf-strip... arm-linux-gnueabihf-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for arm-linux-gnueabihf-gcc... arm-linux-gnueabihf-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-linux-gnueabihf-gcc accepts -g... yes
checking for arm-linux-gnueabihf-gcc option to accept ISO C89... none needed
checking whether arm-linux-gnueabihf-gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of arm-linux-gnueabihf-gcc... gcc3
checking for arm-linux-gnueabihf-gcc option to accept ISO C99... none needed
checking for arm-linux-gnueabihf-ranlib... arm-linux-gnueabihf-ranlib
checking for arm-linux-gnueabihf-ar... arm-linux-gnueabihf-ar
checking the archiver (arm-linux-gnueabihf-ar) interface... ar
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... 64
checking for arm-linux-gnueabihf-pkg-config... no
checking for pkg-config... /usr/bin/pkg-config
configure: WARNING: using cross tools not prefixed with host triplet
checking pkg-config is at least version 0.9.0... yes
checking for UBLIO... no
checking for FUSE... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating libexfat/Makefile
config.status: creating fuse/Makefile
config.status: creating Makefile
config.status: creating libexfat/config.h
config.status: libexfat/config.h is unchanged
config.status: executing depfiles commands
Make 失败并出现 "cannot find lib" 错误。
root@2a13b22d5372:/opt/fuse-exfat-1.3.0# LDFLAGS="-L/opt/sysroot/usr/lib" CFLAGS="-I/opt/sysroot/usr/include" make
Making all in libexfat
make[1]: Entering directory '/opt/fuse-exfat-1.3.0/libexfat'
make all-am
make[2]: Entering directory '/opt/fuse-exfat-1.3.0/libexfat'
make[2]: Leaving directory '/opt/fuse-exfat-1.3.0/libexfat'
make[1]: Leaving directory '/opt/fuse-exfat-1.3.0/libexfat'
Making all in fuse
make[1]: Entering directory '/opt/fuse-exfat-1.3.0/fuse'
arm-linux-gnueabihf-gcc -D_FILE_OFFSET_BITS=64 -I/usr/include/fuse -g -O2 -o mount.exfat-fuse mount_exfat_fuse-main.o ../libexfat/libexfat.a -lfuse -pthread
/usr/lib/gcc-cross/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lfuse
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:399: mount.exfat-fuse] Error 1
make[1]: Leaving directory '/opt/fuse-exfat-1.3.0/fuse'
make: *** [Makefile:363: all-recursive] Error 1
我错过了什么?
根据此处的信息,我们无法确定。
但是,makefile 可能设置了 LDFLAGS
和 CFLAGS
变量。在 makefile 中分配的变量将优先于从环境中获得的变量,因此您的变量分配将被忽略。
我建议您尝试在 make 命令行上传递变量赋值,而不是通过环境:
$ make LDFLAGS="-L/opt/sysroot/usr/lib" CFLAGS="-I/opt/sysroot/usr/include"
(PS 以 root 身份构建东西和 运行 几乎总是一个坏主意——事实上几乎总是一个坏主意任何事情 作为 root,除非需要它)