eal: fix C++ link of delay function pointer
authorKonstantin Ananyev <konstantin.ananyev@intel.com>
Mon, 3 Oct 2016 17:27:25 +0000 (18:27 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 5 Oct 2016 09:16:28 +0000 (11:16 +0200)
commitfd4015e98e3a436a96eb9939661dde9eb4f3e34c
tree6990fe84534d65efd42db225acc02421b9478c9e
parent4d6cf2ac93dc7a9543b3ec4bd480bfa572d0b695
eal: fix C++ link of delay function pointer

When compiling with C++, it treats
void (*rte_delay_us)(unsigned int us);
as definition of the global variable.
So further linking with librte_eal fails.

Fixes: b4d63fb62240 ("eal: customize delay function")

Steps to reproduce:

$ cat rttm1.cpp

using namespace std;

int main(int argc, char *argv[])
{
        int ret = rte_eal_init(argc, argv);
        rte_delay_us(1);
        cout << "return code ";
        cout << ret;
        return ret;
}

$ g++ -m64 -I/${RTE_SDK}/${RTE_TARGET}/include -c  -o rttm1.o rttm1.cpp
$ gcc -m64 -pthread -o rttm1 rttm1.o -ldl -Wl,-lstdc++ \
  -L/${RTE_SDK}/${RTE_TARGET}/lib -Wl,-lrte_eal
.../librte_eal.a(eal_common_timer.o):
(.bss+0x0): multiple definition of `rte_delay_us'
rttm1.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status

$ nm rttm1.o | grep rte_delay_us
0000000000000092 t _GLOBAL__sub_I_rte_delay_us
0000000000000000 B rte_delay_us

Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
lib/librte_eal/common/include/generic/rte_cycles.h