mtcp-stack / mtcp

mTCP: A Highly Scalable User-level TCP Stack for Multicore Systems
Other
1.98k stars 436 forks source link

how to compile mtcp into libmtcp.so #197

Open jingliu9 opened 6 years ago

jingliu9 commented 6 years ago

Hi, I'm wondering how can I compile mtcp into shared library?

Thanks

ajamshed commented 6 years ago

@jingliu9:

You need to do 2 things.

This will create libdpdk.so file in x86_64-native-linuxapp-gcc/lib/ directory.

jingliu9 commented 6 years ago

Thanks @ajamshed !

I just took a try. Then it reports error:

../../mtcp//lib/libmtcp.a(io_module.o): In function SetInterfaceInfo': ${HOME}/mtcp/mtcp/src/io_module.c:314: undefined reference toeal_proc_type_detect' collect2: error: ld returned 1 exit status Makefile:84: recipe for target 'epserver' failed make[2]: [epserver] Error 1 make[2]: Waiting for unfinished jobs.... ../../mtcp//lib/libmtcp.a(io_module.o): In function SetInterfaceInfo': ${HOME}/mtcp/mtcp/src/io_module.c:314: undefined reference toeal_proc_type_detect' collect2: error: ld returned 1 exit status Makefile:92: recipe for target 'epwget' failed


I tried to remove apps/example from the Makefile, and then generate the shared library using

#! /bin/bash

MTCP_LIBS="-lgmp -lpthread -lrte_acl -lrte_bitratestats -lrte_cfgfile -lrte_cmdline -lrte_cryptodev -lrte_distributor -lrte_eal -lrte_efd -lrte_ethdev -lrte_eventdev -lrte_gro -lrte_hash -lrte_ip_frag -lrte_jobstats -lrte_kni -lrte_kvargs -lrte_latencystats -lrte_lpm -lrte_mbuf -lrte_mempool_ring -lrte_mempool -lrte_mempool_stack -lrte_meter -lrte_metrics -lrte_net -lrte_pdump -lrte_pipeline -lrte_pmd_af_packet -lrte_pmd_ark -lrte_pmd_avp -lrte_pmd_bnxt -lrte_pmd_bond -lrte_pmd_crypto_scheduler -lrte_pmd_cxgbe -lrte_pmd_e1000 -lrte_pmd_ena -lrte_pmd_enic -lrte_pmd_failsafe -lrte_pmd_fm10k -lrte_pmd_i40e -lrte_pmd_ixgbe -lrte_pmd_kni -lrte_pmd_lio -lrte_pmd_nfp -lrte_pmd_null_crypto -lrte_pmd_null -lrte_pmd_octeontx_ssovf -lrte_pmd_qede -lrte_pmd_ring -lrte_pmd_sfc_efx -lrte_pmd_skeleton_event -lrte_pmd_sw_event -lrte_pmd_tap -lrte_pmd_thunderx_nicvf -lrte_pmd_vhost -lrte_pmd_virtio -lrte_pmd_vmxnet3_uio -lrte_port -lrte_power -lrte_reorder -lrte_ring -lrte_sched -lrte_table -lrte_timer -lrte_vhost -ldpdk"
MTCP_DIR=${HOME}/mtcp/

CUR_DIR=`pwd`

gcc -shared -o libmtcp.so mtcp/src/*.o -L${MTCP_DIR}/dpdk-17.08/x86_64-native-linuxapp-gcc/lib ${MTCP_LIBS}  -lgmp -Wl,-rpath=${MTCP_DIR}/dpdk-17.08/x86_64-native-linuxapp-gcc/lib/
the ldd result shows as follows:
linux-vdso.so.1 =>  (0x00007ffcc3bf9000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f349d4f0000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f349d2d3000)
librte_eal.so.5.1 => ${HOME}/mtcp//dpdk-17.08/x86_64-native-linuxapp-gcc/lib/librte_eal.so.5.1 (0x00007f349d06a000)
librte_ethdev.so.6.1 =>${HOME}/mtcp//dpdk-17.08/x86_64-native-linuxapp-gcc/lib/librte_ethdev.so.6.1 (0x00007f349cdd8000)
librte_mbuf.so.3.1 => ${HOME}/mtcp//dpdk-17.08/x86_64-native-linuxapp-gcc/lib/librte_mbuf.so.3.1 (0x00007f349cbd3000)
librte_mempool.so.2.1 => ${HOME}/mtcp//dpdk-17.08/x86_64-native-linuxapp-gcc/lib/librte_mempool.so.2.1 (0x00007f349c9cd000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f349c603000)
/lib64/ld-linux-x86-64.so.2 (0x00007f349d99b000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f349c3ff000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f349c1f7000)
libnuma.so.1 => /usr/lib/x86_64-linux-gnu/libnuma.so.1 (0x00007f349bfec000)

But then when write a simple test program which include mtcp_api.h:

// test.cpp
#include <mtcp_api.h>
int main(){
    ...
    ret = mtcp_init(conf_file);
    ...
    return 0;
}

Then it report ${HOME}/mtcp//libmtcp.so: undefined reference to `eal_proc_type_detect' collect2: error: ld returned 1 exit status

Do you have any idea on why this error happen? Thanks!

jingliu9 commented 6 years ago

It turns out that, there is some bugs in dpdk-17.08. Then it works.

ajamshed commented 6 years ago

@jingliu9:

You got it. I am using an internal dpdk function eal_proc_type_detect that tests for the existence of primary process. It needs to be exported in rte_eal_version.map file.

Flasew commented 4 years ago

Hi @jingliu9 and @ajamshed , I'm trying to port iperf3 to use mtcp stack and encountered the same problem (I believe the current DPDK submodule version is 18.05). How did you solve the undefined reference toeal_proc_type_detect'` issue?

Thanks!

jingliu9 commented 4 years ago

Hi @jingliu9 and @ajamshed , I'm trying to port iperf3 to use mtcp stack and encountered the same problem (I believe the current DPDK submodule version is 18.05). How did you solve the undefined reference toeal_proc_type_detect'` issue?

Thanks!

Hey, I add the function I'd like to export into "rte_eal_version.map", which explicitly control the symbols to be exported.

Jing