You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Yocto编译Weston时nss-3.103出现main未定义错误,求调试方法

问题

在运行Ubuntu 24.04的Docker容器中,为自定义板卡构建Yocto StyHead镜像时,nss-3.103环节编译失败,链接阶段出现undefined reference to 'main'错误。未修改过任何nss相关的默认配方,求调试方法。

错误日志如下:

| make[4]: Entering directory '/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/nss-3.103/nss/cmd/bltest'
| rm -f Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/bltest
| gcc  -isystem/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/recipe-sysroot-native/usr/include -O2 -pipe -D_XOPEN_SOURCE  -o Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/bltest -O2 -fPIC  -m64 -pipe -ffunction-sections -fdata-sections -DHAVE_STRERROR -DLINUX -Dlinux -Wall -Wshadow -DNSS_NO_GCC48 -DXP_UNIX -DXP_UNIX -UDEBUG -DNDEBUG -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -DSDB_MEASURE_USE_TEMP_DIR -D_REENTRANT -UDEBUG -DNDEBUG -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -DSDB_MEASURE_USE_TEMP_DIR -D_REENTRANT -DNSS_DISABLE_SSE3 -DNSS_NO_INIT_SUPPORT -DUSE_UTIL_DIRECTLY -DNO_NSPR_10_SUPPORT -DSSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES -DNSS_USE_STATIC_LIBS -I../../nss/lib/softoken -I/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/recipe-sysroot-native/usr/include/nspr -I../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/include -I../../../dist/public/nss -I../../../dist/private/nss -I../../../dist/public/seccmd -I../../../dist/public/dbm -I../../../dist/public/softoken  Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/blapitest.o -L/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/recipe-sysroot-native/usr/lib                         -L/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/recipe-sysroot-native/lib                         -Wl,--enable-new-dtags                         -Wl,-rpath-link,/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/recipe-sysroot-native/usr/lib                         -Wl,-rpath-link,/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/recipe-sysroot-native/lib                         -Wl,-rpath,/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/recipe-sysroot-native/usr/lib                         -Wl,-rpath,/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/recipe-sysroot-native/lib                         -Wl,-O1 -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/sysroots-uninative/x86_64-linux/lib/ld-linux-x86-64.so.2 -pthread -m64 -z noexecstack -m64 -z noexecstack -m64 -z noexecstack -m64 -z noexecstack -m64 -z noexecstack -m64 -z noexecstack -m64 -z noexecstack -m64 -z noexecstack -m64 -z noexecstack -m64 -z noexecstack ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libsectool.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libsmime.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libssl.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libnss.a  ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkcs12.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkcs7.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libcerthi.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libcryptohi.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpk11wrap.a  ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libsoftokn.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libcertdb.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libnsspki.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libnssdev.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libnssb.a  ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libfreebl.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libdbm.a  ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkixtop.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkixutil.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkixsystem.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkixcrlsel.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkixmodule.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkixstore.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkixparams.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkixchecker.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkixpki.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkixtop.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkixresults.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpkixcertsel.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libnss.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libpk11wrap.a ../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib/libcerthi.a   -L../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib -lsqlite3 -L../../../dist/Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/lib -lnssutil3 -L/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/recipe-sysroot-native/usr/lib -lplc4 -lplds4 -lnspr4  -lpthread  -ldl -lc
| /mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/hosttools/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
| (.text+0x1b): undefined reference to `main'
| collect2: error: ld returned 1 exit status
| make[4]: Leaving directory '/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/nss-3.103/nss/cmd/bltest'
| make[3]: Leaving directory '/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/nss-3.103/nss/cmd'
| make[2]: Leaving directory '/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/nss-3.103/nss'
| make[4]: *** [../../coreconf/rules.mk:165: Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/bltest] Error 1
| make[3]: *** [../coreconf/rules.mk:44: bltest] Error 2
| make[2]: *** [coreconf/rules.mk:44: cmd] Error 2
| make[1]: *** [manifest.mn:21: all] Error 2
| make[1]: Leaving directory '/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/nss-3.103/nss'
| make: *** [coreconf/rules.mk:24: autobuild] Error 2
| make: Leaving directory '/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/nss-3.103/nss'
| WARNING: exit code 2 from a shell command.
NOTE: recipe nss-native-3.103-r0: task do_compile: Failed
ERROR: Task (virtual:native:/mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/poky/../meta-openembedded/meta-oe/recipes-support/nss/nss_3.103.bb:do_compile) failed with exit code '1'
调试步骤
  • 检查bltest目标的源码与编译产物

    1. 进入bltest编译目录:
      cd /mnt/host_fs/yocto/build-scripts/cmn-srp/yocto_board/build/tmp/work/x86_64-linux/nss-native/3.103/nss-3.103/nss/cmd/bltest
      
    2. 查找包含main函数的源码文件:
      grep -l "int main" *.c
      
      如果无输出,说明源码缺失或Makefile未正确引入主程序文件。
    3. 检查已编译的blapitest.o是否包含main符号:
      nm Linux3.4_x86_64_glibc_PTH_64_OPT.OBJ/blapitest.o | grep main
      
      若无结果,说明该目标文件不是程序入口,Makefile可能漏加了包含main的.o文件。
  • 验证Makefile链接规则

    1. 查看当前目录的Makefile或上级规则文件(如rules.mk),检查bltest目标的依赖项是否包含所有必要的.o文件,尤其是带main函数的文件。
    2. 对比官方nss-3.103的Makefile配置,确认是否因环境变量替换错误导致文件遗漏。
  • 排查编译环境差异

    1. 确认Docker容器内的gcc版本:
      gcc --version
      
      Ubuntu 24.04默认gcc 13,部分旧版本软件的Makefile可能对高版本gcc的兼容性处理不足。
    2. 检查Yocto native编译的CFLAGS/LDFLAGS是否被意外修改:
      bitbake -e nss-native | grep "^CFLAGS"
      bitbake -e nss-native | grep "^LDFLAGS"
      
      确认是否存在导致符号丢失的编译参数。
  • 临时跳过bltest编译(非必需工具场景)
    如果bltest是测试工具,不影响核心功能,可以修改nss配方跳过该目标:

    1. 编辑nss_3.103.bb,添加:
      EXTRA_OEMAKE += "BLTEST_DISABLE=1"
      
      具体参数需参考nss的Makefile支持,或直接在编译前删除bltest在目标列表中的引用。
  • 清理并重编译

    1. 清理nss-native的所有编译产物:
      bitbake -c cleanall nss-native
      
    2. 重新编译并查看详细日志:
      bitbake -v nss-native
      

内容的提问来源于stack exchange,提问作者preetam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 19:50:52