This happens when I am using dpdk library.
DPDK library is using __attribute__((constructor))
trick to register the module before main()
.
Such as the virtio driver module, it declares an init function to register itself.
RTE_INIT(rte_virtio_pmd_init)
RTE_INIT
uses constructor extension to make sure rte_virtio_pmd_init
is called before main()
#define RTE_INIT(func) \
static void __attribute__((constructor, used)) func(void)
But nobody calls rte_virtio_pmd_init()
or any other function in virtio module in my program, so linker will not link virtio module.
I tried different ways to resolve this issue, but all failed.
Here is what I tried:
use
--no-as-needed linker
flag, doesn't workx86_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
Specify all the libraries explicitly in the compile command, also failed
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
I know the linker tool is very smart. But now the problem is it is too smart to make work done.
Is there any good approach to disable this smart feature and make my program be linked with the library?