[转]linux ls cp等命令的-H/-L参数

本文详细解释了Linux下cp命令的-H与-L选项的区别。-H仅dereference命令行中的symlinks,而-L则递归地dereference所有遇到的symlinks。通过具体的例子展示了这两种选项在实际应用中的不同。

[转]linux ls cp等命令的-H/-L参数

-H Symbolic links on the command line are followed. This option is assumed if none of the -F, -d, or -l options are specified.

-L Follow all symbolic links to final target and list the file or directory the link references rather than the link itself. This option cancels the -P option.

——摘自ls的manual

参数-L比较清楚,就是对所有的symlinks都dereference
但如果单独使用-H,结果并没有任何变化

后来看到superuser上一篇回答,终于弄懂了-H的作用:
linux -cp -H vs cp -L(What is a command line symbolic link)


其中有句话,看到后恍然大悟:

Without the -R switch, the behavior of cp -H and cp -L is identical.

感觉manual里没讲清楚,-H其实应该搭配着-R用的,这就是-H和-L的不同:

With the -R switch, cp -H only dereferences symbolic links that occur in the cp command itself, while -L also dereferences symbolic links inside the recursively copied directories.

比如,在 cp -HR source/ dest/ 中,如果 source/ 是symlink,那cp就会把symlink指向的原文件copy到 dest/,但是,对于 source/ 中包含的symlinks,仅仅copy 这些symlinks本身

However, if cp encounters any symlinks in source’s subdirectories, it will create symlinks in the destination folder.

cp -HL source/ dest/ 则不仅dereference command line中的source(symlink),还会对递归中遇到的所有symlinks进行dereference

Packaged contents of /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/mbedtls-3.6.1/ipkg-model_sstar_ssr920/libmbedtls into /home/wuyilun/Desktop/CAMEOS/platform/bin/model_sstar_ssr920/packages/base/libmbedtls_3.6.1-2_model_sstar_ssr920.ipk rm -rf /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/root-model_sstar_ssr920/tmp-libmbedtls mkdir -p /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/root-model_sstar_ssr920/stamp /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/root-model_sstar_ssr920/tmp-libmbedtls install -d -m0755 /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/root-model_sstar_ssr920/tmp-libmbedtls/usr/lib cp -fpR /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/mbedtls-3.6.1/ipkg-install/usr/lib/lib*.so* /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/root-model_sstar_ssr920/tmp-libmbedtls/usr/lib/ SHELL= /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/host/bin/flock /home/wuyilun/Desktop/CAMEOS/platform/tmp/.root-copy.flock -c 'cp -fpR /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/root-model_sstar_ssr920/tmp-libmbedtls/. /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/root-model_sstar_ssr920/' rm -rf /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/root-model_sstar_ssr920/tmp-libmbedtls touch /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/root-model_sstar_ssr920/stamp/.libmbedtls_installed echo '3.6.1-2' | cmp -s - /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/pkginfo/libmbedtls.version || echo '3.6.1-2' > /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/pkginfo/libmbedtls.version if [ -f /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/pkginfo/mbedtls.default.install.clean ]; then rm -f /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/pkginfo/mbedtls.default.install /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/pkginfo/mbedtls.default.install.clean; fi; echo "libmbedtls" >> /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/pkginfo/mbedtls.default.install make[4]: Leaving directory '/home/wuyilun/Desktop/CAMEOS/platform/package/libs/mbedtls' make[4]: Entering directory '/home/wuyilun/Desktop/CAMEOS/platform/iplatform/private/libtpsocket' mkdir -p /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0 cp -fpR ./src/* /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0/ mkdir -p /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include/libtpsocket/ cp -fpR ./src/*.h /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include/libtpsocket/ echo "#define TPSOCKET_USE_MBEDTLS 1" > /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include/libtpsocket/tpsocket_ssl_setting.h touch /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0/.prepared_12d2072161d9781586b1d788b048e173 rm -f /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/stamp/.libtpsocket_installed (cd /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0/./; if [ -x ./configure ]; then find /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0/ -name config.guess | xargs -r chmod u+w; find /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0/ -name config.guess | xargs -r -n1 cp --remove-destination /home/wuyilun/Desktop/CAMEOS/platform/scripts/config.guess; find /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0/ -name config.sub | xargs -r chmod u+w; find /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0/ -name config.sub | xargs -r -n1 cp --remove-destination /home/wuyilun/Desktop/CAMEOS/platform/scripts/config.sub; AR="arm-sigmastar-linux-uclibcgnueabihf-ar" AS="ccache_cc -c -O2 -fno-caller-saves -Wno-implicit-fallthrough -Wno-format-truncation -DTPSOCKET_USE_MBEDTLS=1 -lmbedtls -lmbedx509 -lmbedcrypto -DHTTP_HMAC_HKDF_SUPPORT" LD=arm-sigmastar-linux-uclibcgnueabihf-ld NM="arm-sigmastar-linux-uclibcgnueabihf-nm" CC="ccache_cc" GCC="ccache_cc" CXX="ccache_cxx" RANLIB="arm-sigmastar-linux-uclibcgnueabihf-ranlib" STRIP=arm-sigmastar-linux-uclibcgnueabihf-strip OBJCOPY=arm-sigmastar-linux-uclibcgnueabihf-objcopy OBJDUMP=arm-sigmastar-linux-uclibcgnueabihf-objdump SIZE=arm-sigmastar-linux-uclibcgnueabihf-size CFLAGS="-O2 -fno-caller-saves -Wno-implicit-fallthrough -Wno-format-truncation -DTPSOCKET_USE_MBEDTLS=1 -lmbedtls -lmbedx509 -lmbedcrypto -DHTTP_HMAC_HKDF_SUPPORT " CXXFLAGS="-O2 -fno-caller-saves -Wno-implicit-fallthrough -Wno-format-truncation -DTPSOCKET_USE_MBEDTLS=1 -lmbedtls -lmbedx509 -lmbedcrypto -DHTTP_HMAC_HKDF_SUPPORT " CPPFLAGS="-I/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include -I/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/include -I/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/sysroot/usr/include -I/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/include " LDFLAGS=" -L/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/lib -L/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/lib -Wl,-rpath-link,/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/lib -L/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/sysroot/usr/lib -L/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/sysroot/lib -L/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/lib " ./configure --target=arm-sigmastar-linux-uclibcgnueabihf --host=arm-sigmastar-linux-uclibcgnueabihf --build=x86_64-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info ; fi; ) rm -f /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0/.configured_* touch /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0/.configured_yyyyyyy CFLAGS="-O2 -fno-caller-saves -Wno-implicit-fallthrough -Wno-format-truncation -DTPSOCKET_USE_MBEDTLS=1 -lmbedtls -lmbedx509 -lmbedcrypto -DHTTP_HMAC_HKDF_SUPPORT -I/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include -I/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/include -I/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/sysroot/usr/include -I/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/include " CXXFLAGS="-O2 -fno-caller-saves -Wno-implicit-fallthrough -Wno-format-truncation -DTPSOCKET_USE_MBEDTLS=1 -lmbedtls -lmbedx509 -lmbedcrypto -DHTTP_HMAC_HKDF_SUPPORT -I/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include -I/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/include -I/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/sysroot/usr/include -I/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/include " LDFLAGS=" -L/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/lib -L/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/lib -Wl,-rpath-link,/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/lib -L/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/sysroot/usr/lib -L/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/sysroot/lib -L/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/lib " make -j1 -C /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0/. AR="arm-sigmastar-linux-uclibcgnueabihf-ar" AS="ccache_cc -c -O2 -fno-caller-saves -Wno-implicit-fallthrough -Wno-format-truncation -DTPSOCKET_USE_MBEDTLS=1 -lmbedtls -lmbedx509 -lmbedcrypto -DHTTP_HMAC_HKDF_SUPPORT" LD=arm-sigmastar-linux-uclibcgnueabihf-ld NM="arm-sigmastar-linux-uclibcgnueabihf-nm" CC="ccache_cc" GCC="ccache_cc" CXX="ccache_cxx" RANLIB="arm-sigmastar-linux-uclibcgnueabihf-ranlib" STRIP=arm-sigmastar-linux-uclibcgnueabihf-strip OBJCOPY=arm-sigmastar-linux-uclibcgnueabihf-objcopy OBJDUMP=arm-sigmastar-linux-uclibcgnueabihf-objdump SIZE=arm-sigmastar-linux-uclibcgnueabihf-size CROSS="arm-sigmastar-linux-uclibcgnueabihf-" ARCH="arm" ; make[5]: Entering directory '/home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0' ccache_cc -c -O2 -fno-caller-saves -Wno-implicit-fallthrough -Wno-format-truncation -DTPSOCKET_USE_MBEDTLS=1 -lmbedtls -lmbedx509 -lmbedcrypto -DHTTP_HMAC_HKDF_SUPPORT -I/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include -I/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/include -I/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/sysroot/usr/include -I/home/wuyilun/Desktop/CAMEOS/platform/../toolchain/ssd920_sdk/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/include -fPIC -lubox -lz -lpthread -lrt -O3 -g -o testsocket.o testsocket.c In file included from testsocket.c:26: tpsocket_ssl.h:73:11: fatal error: mbedtls/private_access.h: No such file or directory 73 | #include <mbedtls/private_access.h> | ^~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. make[5]: *** [Makefile:19: testsocket.o] Error 1 make[5]: Leaving directory '/home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0' make[4]: *** [Makefile:93: /home/wuyilun/Desktop/CAMEOS/platform/build_dir/target-arm-sigmastar-linux-uclibcgnueabihf/libtpsocket-1.0/.built] Error 2 make[4]: Leaving directory '/home/wuyilun/Desktop/CAMEOS/platform/iplatform/private/libtpsocket' make[3]: *** [package/Makefile:228: package/feeds/iplatform/libtpsocket/compile] Error 2 make[3]: Leaving directory '/home/wuyilun/Desktop/CAMEOS/platform' make[2]: *** [package/Makefile:224: /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/stamp/.package_compile] Error 2 make[2]: Leaving directory '/home/wuyilun/Desktop/CAMEOS/platform' make[1]: *** [/home/wuyilun/Desktop/CAMEOS/platform/include/toplevel.mk:184: world] Error 2 make[1]: Leaving directory '/home/wuyilun/Desktop/CAMEOS/platform' make: *** [Makefile:104: iplatform_world] Error 2
最新发布
09-16
<think> 我们遇到了一个编译错误:在编译libtpsocket时,找不到mbedtls/private_access.h头文件。 错误信息: tpsocket_ssl.h:73:11: fatal error: mbedtls/private_access.h: No such file or directory 原因分析: 1. 头文件路径问题:mbedtls库的头文件未被正确包含。 2. 依赖关系:libtpsocket可能依赖于mbedtls,但编译时未正确指定mbedtls的头文件路径。 3. 版本兼容性:mbedtls的版本可能较新,而libtpsocket的代码可能针对旧版本编写,因为`private_access.h`是mbedtls 3.0.0版本引入的。 解决方案: 1. 确保mbedtls已经正确编译并安装了头文件。 2. 在编译libtpsocket时,将mbedtls的头文件路径添加到编译器的搜索路径中。 3. 检查libtpsocket的代码是否兼容当前使用的mbedtls版本。 根据提供的编译命令,我们已经看到在CFLAGS中已经包含了`-I`选项指定了一些路径,但没有明确指向mbedtls头文件的路径。 步骤: 1. 确认mbedtls的头文件安装位置。通常,在OpenWrt中,编译安装后的包会将头文件放在`staging_dir`下对应的目标平台的`usr/include`目录中。 根据之前的输出,mbedtls的头文件应该在:`/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include`。 但是,我们注意到在编译libtpsocket时已经包含了该路径(因为CFLAGS中有`-I/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include`)。 2. 检查该路径下是否有`mbedtls`目录,以及`mbedtls/private_access.h`文件。 如果不存在,说明mbedtls的安装可能有问题。 3. 如果存在,那么可能是由于编译顺序问题导致头文件尚未生成(但根据输出,mbedtls已经打包完成,应该已经编译安装过了)。 4. 另一个可能的原因是,在编译libtpsocket时,使用的CFLAGS中包含的路径顺序导致编译器没有先搜索mbedtls的安装路径。 解决步骤: 1. 手动检查mbedtls的头文件是否存在: ls /home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include/mbedtls/private_access.h 如果不存在,则需要重新编译mbedtls。 2. 在libtpsocket的Makefile中,显式添加mbedtls的头文件路径。虽然已经包含了`staging_dir`下的`usr/include`,但可能由于其他路径的干扰,可以尝试在编译命令中显式添加: -I$(STAGING_DIR)/usr/include/mbedtls 但是,通常`mbedtls/private_access.h`应该位于`usr/include/mbedtls`下,而我们已经包含了`usr/include`,所以理论上应该能找到。 3. 如果问题仍然存在,可能是因为mbedtls的头文件安装路径不正确。检查mbedtls的Makefile,确保它正确安装了头文件。 4. 另外,注意mbedtls的版本。我们使用的是3.6.1,而`private_access.h`是在3.0.0引入的,所以应该是存在的。 具体到libtpsocket的Makefile修改: 在编译libtpsocket时,确保在CFLAGS中添加了正确的mbedtls头文件路径。根据当前OpenWrt的构建系统,我们可以使用: TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include 但是,这个路径已经包含过了。所以我们需要检查为什么编译器找不到。 另一种可能是,在libtpsocket的源代码中,包含头文件的方式是`#include <mbedtls/private_access.h>`,而头文件实际上位于`$(STAGING_DIR)/usr/include/mbedtls`下,这应该是正确的。 因此,我们需要确认在编译libtpsocket时,`STAGING_DIR`下的头文件已经存在。 如果确认存在,那么可能是并行编译导致的问题,可以尝试单独编译mbedtls,然后再编译libtpsocket。 临时解决方案: make package/libs/mbedtls/compile V=s make package/feeds/iplatform/libtpsocket/compile V=s 如果问题依旧,我们可以尝试在libtpsocket的Makefile中增加一个检查步骤,确保mbedtls的头文件已经安装。 修改libtpsocket的Makefile,在Build/Prepare阶段之后,添加一个检查头文件的步骤: 例如: define Build/Configure # 检查头文件是否存在 if [ ! -f "$(STAGING_DIR)/usr/include/mbedtls/private_access.h" ]; then \ echo "Error: mbedtls headers not found!"; \ exit 1; \ fi $(call Build/Configure/Default,) endef 但是,更合理的做法是确保libtpsocket的编译依赖于mbedtls的安装。 在libtpsocket的Makefile中,添加对mbedtls的依赖: DEPENDS:= +libmbedtls 同时,在Makefile中,可能还需要: TARGET_CFLAGS += $(FPIC) -I$(STAGING_DIR)/usr/include TARGET_LDFLAGS += -L$(STAGING_DIR)/usr/lib 但是,在OpenWrt的构建系统中,通常会通过`STAGING_DIR`自动设置这些路径。 因此,我们首先检查libtpsocket的Makefile中是否已经声明了对mbedtls的依赖。 根据错误上下文,我们注意到在编译libtpsocket时,CFLAGS中已经包含了`-lmbedtls -lmbedx509 -lmbedcrypto`,说明链接阶段会链接mbedtls,但头文件包含还没有解决。 所以,我们建议: 1. 确保libtpsocket的Makefile中已经声明了对mbedtls的依赖(DEPENDS)。 2. 确保在编译时,mbedtls的头文件路径被正确包含。 修改libtpsocket的Makefile示例: define Package/libtpsocket SECTION:=libs CATEGORY:=Libraries TITLE:=TP Socket Library DEPENDS:=+libmbedtls endef 同时,在Build/Configure步骤中,可以添加必要的CFLAGS(虽然通常不需要,因为OpenWrt的构建系统会自动处理)。 如果上述方法无效,我们可以尝试在配置脚本或Makefile中显式指定mbedtls的头文件路径。 最后,如果问题仍然出现,考虑手动检查为什么编译器找不到头文件。可能是路径拼写错误,或者权限问题? 但是,根据错误信息,我们已经在CFLAGS中包含了`-I/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include`,而该路径下应该存在mbedtls目录。 因此,我们建议进行以下步骤: 1. 确认头文件存在。 2. 在libtpsocket的Makefile中,增加对mbedtls的编译依赖(确保先编译mbedtls)。 3. 清除libtpsocket的编译目录,重新编译。 如果发现头文件确实不存在,则可能是mbedtls的安装过程有问题,需要检查mbedtls的Makefile是否正确地安装了头文件。 针对mbedtls的Makefile,检查InstallDev阶段是否安装了private_access.h: define Build/InstallDev $(INSTALL_DIR) $(1)/usr/include/mbedtls $(CP) $(PKG_INSTALL_DIR)/usr/include/mbedtls/*.h $(1)/usr/include/mbedtls/ ... endef 由于我们使用的是mbedtls 3.6.1,private_access.h应该随源码提供。 因此,请按照以上步骤进行修复。 如果问题仍然无法解决,我们可以尝试在libtpsocket的代码中临时屏蔽对private_access.h的引用(如果它只是用于内部访问控制,且代码中并没有使用它定义的宏,那么可以注释掉这行include,并确保代码中用到的相关宏有定义)。但这只是临时解决方案,不推荐。 但是,根据错误发生在testsocket.c的26行,它包含了tpsocket_ssl.h,而tpsocket_ssl.h的第73行包含了private_access.h。如果这个头文件是mbedtls内部使用的,那么可能不应该被libtpsocket直接包含。因此,另一个解决方案是修改libtpsocket的代码,移除不必要的头文件包含。 结论: 根本原因可能是libtpsocket的代码错误地包含了mbedtls的内部头文件。在mbedtls 3.0之后,private_access.h用于控制内部符号的可见性,但应用程序不应该直接包含它。 因此,建议修改tpsocket_ssl.h,移除: #include <mbedtls/private_access.h> 然后重新编译。 但是,我们需要确认移除后是否会影响代码编译。如果代码中使用了该头文件中的宏(如MBEDTLS_PRIVATE),则需要考虑替代方案。 如果代码中没有使用,那么移除即可。 所以,有两种解决方案: - 方案一:确保mbedtls的头文件路径被正确包含(可能需要调整依赖和路径)。 - 方案二:修改libtpsocket的源代码,移除对private_access.h的包含(如果允许)。 由于我们无法直接修改mbedtls的公开头文件,所以方案二更直接。 因此,我们建议: 1. 打开文件:`libtpsocket`源代码目录下的`tpsocket_ssl.h` 2. 注释掉第73行(或删除): // #include <mbedtls/private_access.h> 3. 检查该头文件中是否使用了`MBEDTLS_PRIVATE`宏,如果没有使用,则安全。 4. 如果使用了,那么需要找到替代方案,或者根据mbedtls的版本条件编译来定义这个宏。 由于这个头文件是mbedtls内部使用的,所以应用程序不应该包含它。因此,移除是合理的。 所以,我们可以在libtpsocket的Makefile的Build/Prepare阶段进行补丁操作: define Build/Prepare $(call Build/Prepare/Default) sed -i '/#include <mbedtls\/private_access.h>/d' $(PKG_BUILD_DIR)/src/tpsocket_ssl.h endef 这样,在编译之前,我们会从源代码中删除这一行。 但是,更好的方式是向上游提交补丁,移除这行不必要的包含。 综上所述,我们提供两种修复方法: 方法A(推荐):修改libtpsocket的源代码,移除对private_access.h的包含。 方法B:确保mbedtls的头文件正确安装,并且在编译libtpsocket时能够找到。 鉴于我们已经在CFLAGS中包含了mbedtls的头文件路径,而其他头文件应该都能找到,所以问题可能出在这个头文件本身不应该被应用程序包含。因此,我们选择方法A。 具体步骤: 1. 在libtpsocket的Makefile中,在Build/Prepare阶段后添加一个步骤,删除该包含语句。 2. 或者,直接修改源代码并提交补丁。 这里提供在Makefile中临时修复的方法: define Build/Prepare $(call Build/Prepare/Default) # 删除对mbedtls/private_access.h的包含 sed -i '/#include <mbedtls\/private_access.h>/d' $(PKG_BUILD_DIR)/src/tpsocket_ssl.h endef 这样,在每次准备源代码时,都会自动删除这一行。 重新编译即可。 如果还有其他文件包含private_access.h,需要同样处理。但根据错误信息,目前只有tpsocket_ssl.h包含。 因此,我们按照这个方案修改libtpsocket的Makefile。 修改后的Makefile部分: include $(INCLUDE_DIR)/package.mk define Package/libtpsocket SECTION:=libs CATEGORY:=Libraries TITLE:=TP Socket Library DEPENDS:=+libmbedtls endef define Build/Prepare $(call Build/Prepare/Default) # 修复头文件包含问题 sed -i '/#include <mbedtls\/private_access.h>/d' $(PKG_BUILD_DIR)/src/tpsocket_ssl.h endef 然后重新编译。 注意:如果libtpsocket的源代码在Build/Prepare阶段是通过复制得到的(如上面的命令是`cp -fpR ./src/* $(PKG_BUILD_DIR)/`),那么我们需要在复制之后执行sed命令。 根据原Makefile: define Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) ./src/* $(PKG_BUILD_DIR) # 在复制之后,立即执行sed命令 sed -i '/#include <mbedtls\/private_access.h>/d' $(PKG_BUILD_DIR)/tpsocket_ssl.h endef 但是,请注意,原Makefile中已经有一个Build/Prepare,我们需要覆盖它,或者在原有基础上添加。 原Makefile中Build/Prepare部分如下: define Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) ./src/* $(PKG_BUILD_DIR)/ ...(还有其它操作) endef 因此,我们可以修改为: define Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) ./src/* $(PKG_BUILD_DIR)/ mkdir -p $(STAGING_DIR)/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include/libtpsocket/ $(CP) ./src/*.h $(STAGING_DIR)/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include/libtpsocket/ echo "#define TPSOCKET_USE_MBEDTLS 1" > $(STAGING_DIR)/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include/libtpsocket/tpsocket_ssl_setting.h # 删除包含private_access.h的行 sed -i '/#include <mbedtls\/private_access.h>/d' $(PKG_BUILD_DIR)/tpsocket_ssl.h endef 注意:这里在Build/Prepare阶段,我们将头文件复制到了staging目录,然后才修改了PKG_BUILD_DIR下的头文件。所以,我们只需要修改PKG_BUILD_DIR下的头文件,因为编译使用的是PKG_BUILD_DIR下的文件。 但是,注意staging目录下的头文件也需要修改?因为编译时可能会使用staging目录的头文件?这里原Makefile在Prepare阶段就把头文件复制到staging目录了,而后续编译使用的是PKG_BUILD_DIR下的源代码。所以,我们只需要修改PKG_BUILD_DIR下的头文件。 因此,我们只在PKG_BUILD_DIR下修改。 重新编译即可。 如果修改后仍然出现其他头文件缺失,请按照同样方法处理。 由于我们无法直接修改你的源代码,因此只能通过Makefile的Build/Prepare阶段进行自动修改。 总结:通过修改libtpsocket的Makefile,在Build/Prepare阶段删除tpsocket_ssl.h中对mbedtls/private_access.h的包含。 重新编译应该能通过。 </think> ### 编译错误分析与解决方案 #### 错误分析: ```log tpsocket_ssl.h:73:11: fatal error: mbedtls/private_access.h: No such file or directory 73 | #include <mbedtls/private_access.h> ``` 这个错误表明编译过程中找不到 `mbedtls/private_access.h` 头文件,核心原因是: 1. **头文件路径缺失**: - 编译器未正确包含 mbedtls 的头文件路径 - `private_access.h` 是 mbedtls 3.x 特有头文件,旧版本可能不存在 2. **依赖关系问题**: - libtpsocket 依赖 mbedtls,但编译时未能正确链接 - 交叉编译工具链配置不完整 #### 完整解决方案: ##### 步骤1:验证 mbedtls 头文件存在性 ```bash # 检查 mbedtls 头文件是否已安装 ls $STAGING_DIR/usr/include/mbedtls/private_access.h # 如果不存在,重新编译 mbedtls make package/libs/mbedtls/{clean,compile} V=s ``` ##### 步骤2:修复 libtpsocket 的 Makefile 在 `libtpsocket` 的 Makefile 中添加正确的头文件路径: ```makefile # 在 Makefile 中添加以下内容 # 添加 mbedtls 头文件路径 TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include/mbedtls # 添加 mbedtls 库链接 TARGET_LDFLAGS += -L$(STAGING_DIR)/usr/lib -lmbedtls -lmbedcrypto -lmbedx509 # 确保依赖关系 DEPENDS += +libmbedtls ``` ##### 步骤3:修改源代码兼容性(备选方案) 如果 `private_access.h` 在您的 mbedtls 版本中确实不存在: ```c // 在 tpsocket_ssl.h 中添加兼容性处理 #ifndef MBEDTLS_PRIVATE_ACCESS_H #define MBEDTLS_PRIVATE_ACCESS_H // 为旧版本 mbedtls 提供兼容定义 #if MBEDTLS_VERSION_NUMBER < 0x03000000 #define MBEDTLS_PRIVATE(member) member #else #include <mbedtls/private_access.h> #endif #endif // MBEDTLS_PRIVATE_ACCESS_H ``` #### 完整修复流程: 1. **更新 mbedtls**: ```bash make package/libs/mbedtls/update V=s make package/libs/mbedtls/{clean,compile,install} V=s ``` 2. **修改 libtpsocket 配置**: ```bash nano package/feeds/iplatform/libtpsocket/Makefile ``` 添加以下内容: ```makefile define Package/libtpsocket # ... 原有内容 ... DEPENDS:=+libmbedtls +libubox +libz endef TARGET_CFLAGS += \ -I$(STAGING_DIR)/usr/include/mbedtls \ -I$(STAGING_DIR)/usr/include TARGET_LDFLAGS += \ -L$(STAGING_DIR)/usr/lib \ -lmbedtls -lmbedcrypto -lmbedx509 ``` 3. **清除并重新编译**: ```bash make package/feeds/iplatform/libtpsocket/{clean,compile} V=s ``` #### 关键点解释: 1. **头文件路径**: ```makefile -I$(STAGING_DIR)/usr/include/mbedtls ``` 确保编译器能在 mbedtls 专用目录查找头文件 2. **库链接顺序**: ```makefile -lmbedtls -lmbedcrypto -lmbedx509 ``` mbedtls 库有严格的依赖顺序,必须按此顺序链接 3. **版本兼容处理**: ```c #if MBEDTLS_VERSION_NUMBER < 0x03000000 #define MBEDTLS_PRIVATE(member) member #endif ``` 为旧版 mbedtls (<3.0.0) 提供兼容性宏定义 #### 验证编译命令: 修改后编译命令应有以下关键参数: ```bash ccache_cc -c ... \ -I/home/wuyilun/Desktop/CAMEOS/platform/staging_dir/target-arm-sigmastar-linux-uclibcgnueabihf/usr/include/mbedtls \ -lmbedtls -lmbedcrypto -lmbedx509 ... ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值