ld不会链接静态库,因为它认为不需要库,但我需要这个库

时间:2018-03-05 09:39:04

标签: c linker dpdk

当我使用dpdk库时会发生这种情况。

DPDK库正在使用__attribute__((constructor))技巧在main()之前注册模块。

例如virtio驱动程序模块,它声明了一个init函数来注册自己。

RTE_INIT(rte_virtio_pmd_init) 

RTE_INIT使用构造函数扩展名以确保在rte_virtio_pmd_init之前调用main()

#define RTE_INIT(func) \
static void __attribute__((constructor, used)) func(void)

但是我的程序中没有人在virtio模块中调用rte_virtio_pmd_init()或任何其他函数,因此链接器不会链接virtio模块。

我尝试了不同的方法来解决这个问题,但都失败了。

以下是我的尝试:

  1. 使用--no-as-needed linker标志,不起作用

    x86_64-poky-linux-gcc -m64 -march=core2 -mtune=core2 -msse3 -mfpmath=sse --sysroot=/home/hliu/atomos/build-temp/build/tmp/work/core2-64-poky-linux/unittest/0.0-r0/recipe-sysroot -Wl,--hash-style=gnu -Wl,--no-as-needed -o l2_ut_dpdk l2_ut_dpdk.c -Wall -Werror -g -ldpdk -ldl -lpthread

  2. 在编译命令中显式指定所有库,也失败

    x86_64-poky-linux-gcc -m64 -march=core2 -mtune=core2 -msse3 -mfpmath=sse --sysroot=/home/hliu/atomos/build-temp/build/tmp/work/core2-64-poky-linux/unittest/0.0-r0/recipe-sysroot -Wl,--hash-style=gnu -Wl,--no-as-needed -o l2_ut_dpdk l2_ut_dpdk.c -Wall -Werror -g -lrte_mempool_stack -lrte_pmd_i40e -lrte_pmd_ark -lrte_ethdev -lrte_pmd_null -lrte_pmd_null_crypto -lrte_lpm -lrte_pmd_ena -lrte_kvargs -lrte_cmdline -lrte_pmd_tap -lrte_pmd_sw_event -lrte_latencystats -lrte_bitratestats -lrte_efd -lrte_sched -lrte_pmd_kni -lrte_pmd_qede -lrte_hash -lrte_pmd_enic -lrte_pdump -lrte_pmd_lio -lrte_acl -lrte_pmd_af_packet -lrte_eventdev -lrte_port -lrte_ip_frag -lrte_pmd_bond -lrte_pmd_sfc_efx -lrte_pmd_e1000 -lrte_mbuf -lrte_pmd_virtio -lrte_metrics -lrte_cryptodev -lrte_reorder -lrte_pmd_ring -lrte_eal -lrte_distributor -lrte_vhost -lrte_pmd_bnxt -lrte_timer -lrte_pmd_avp -lrte_pmd_crypto_scheduler -lrte_pmd_thunderx_nicvf -lrte_pmd_skeleton_event -lrte_pmd_nfp -lrte_jobstats -lrte_net -lrte_mempool -lrte_pmd_ixgbe -lrte_mempool_ring -lrte_pipeline -lrte_pmd_octeontx_ssovf -lrte_pmd_vhost -lrte_meter -lrte_pmd_cxgbe -lrte_kni -lrte_pmd_vmxnet3_uio -lrte_ring -lrte_pmd_fm10k -lrte_table -lrte_cfgfile -lpthread -ldl

  3. 我知道链接器工具非常智能。但现在问题是完成工作太聪明了。

    是否有任何好方法可以禁用此智能功能并使我的程序与库链接?

0 个答案:

没有答案