[dpdk-users] DPDK application as a library

Amedeo Sapio amedeo.sapio at kaust.edu.sa
Thu Sep 13 17:18:25 CEST 2018


The problem here was that DPDK libraries should be linked with the
'--whole-archive' option. All the credit goes to the guy that answered on stack
overflow
<https://stackoverflow.com/questions/52293444/how-to-compile-a-dpdk-application-as-a-library>
.
I did not find this information in the documentation. Maybe it should be
added on this page <https://doc.dpdk.org/guides/prog_guide/build_app.html>.

---
Amedeo


On Tue, Sep 11, 2018 at 5:56 PM Amedeo Sapio <amedeo.sapio at kaust.edu.sa>
wrote:

> Thanks Keith for your answer.
> If I understand it correctly, you are suggesting to wrap the code that
> needs DPDK in a library and then call the functions in this library from my
> code. That is exactly what I did.
> I called rte_eal_init() before any other dpdk function. The dpdk code was
> tested and worked when compiled as an APP, but the same code did not work
> when used as library.
>
> The example with l2fwd is representative of what I am trying to do.
> I took the exact same code of the l2fwd example, then:
> - renamed the "main" function as "start"
> - I added an header file with the signature of the "start" function
> - compiled as a libf2wd.a file.
> - created a new file with the new main function. This simply calls the
> "start" function passing the argc,argv params.
> - compiled this new file with "gcc  -l l2fwd -l dpdk -pthread  -l dl -l
> numa ..."
>
> When I run it I get:
> EAL: Error - exiting with code: 1
> Cause: No Ethernet ports - bye
>
> PS: I am sorry about the disclaimer, it is not under my control, it is
> inserted automatically by my university mail system.
>
> Amedeo
>
> On Tue, Sep 11, 2018 at 5:07 PM Wiles, Keith <keith.wiles at intel.com>
> wrote:
>
>>
>>
>> > On Sep 11, 2018, at 5:49 AM, Amedeo Sapio <amedeo.sapio at kaust.edu.sa>
>> wrote:
>> >
>> > Dear all,
>> > I am writing a program that uses dpdk. I wrote the program based on the
>> > dpdk examples, in particular using the Makefile provided in the
>> examples.
>> > If i compile the program as an APP (as describe here
>> > <https://doc.dpdk.org/guides-18.02/prog_guide/build_app.html>), all
>> goes
>> > well.
>>
>> Sounds like you and this person need to get together here :-)
>> https://mails.dpdk.org/archives/users/2018-September/003439.html
>>
>> > However, my code is part of a larger project, for which the use of a
>> > separate makefile causes a lot of troubles.
>> > So I compiled my code as a library, as described in the same page.
>> > Now, the program that calls the functions in the library (to initialize
>> the
>> > EAL) is getting this error:
>> >
>>
>> Did you call rte_eal_init() first as most of the routines depend on
>> calling this function before you call the other one.
>>
>> As I explained the other thread, is that DPDK is not libc and you can not
>> just pick the functions you want to use for the most part. Some functions
>> are fairly independent, but not really as work is needed to make sure it
>> has all of the other inits called.
>>
>> If you want to use DPDK today, the best method is to make sure you
>> initialize DPDK correctly and then you can use parts of it for your needs.
>>
>> As for the code that interacts with your application it is best to have a
>> directory with just the functions you need to build with DPDK and use these
>> functions as a bridge to/from your code. Using your header files and DPDK
>> header files in the same directory or file can cause a number of build
>> problems, which is why I use this type of method. Some routines in DPDK you
>> can call without any real problems, but sometimes it makes it easier to
>> write inline functions or functions that build most independent of DPDK and
>> your routines. Not sure explained it clearly, but I hope it helps.
>>
>> BTW, please remove any disclaimers in your email as they do not apply to
>> a public email list.
>>
>> > MBUF: error setting mempool handler
>> > Cannot init mbuf pool
>> >
>> > I also made an experiment with the l2fwd example. The example compiled
>> as
>> > an app works correctly. But if I compile it as a library and then I call
>> > the functions in this library from another program, I get:
>> >
>> > EAL: Error - exiting with code: 1
>> >  Cause: No Ethernet ports - bye
>> >
>> > I have one ethernet port using the igb_uio driver (seen from
>> > dpdk-devbind.py). When I compile my program, I link the following
>> > libraries: dpdk, pthread, dl, numa. DPDK is compiled from source as
>> > described here <https://doc.dpdk.org/guides/linux_gsg/build_dpdk.html>.
>> >
>> > Thanks for your help,
>> >
>> > ---
>> > Amedeo
>> >
>> > --
>> >
>> > This message and its contents, including attachments are intended
>> solely
>> > for the original recipient. If you are not the intended recipient or
>> have
>> > received this message in error, please notify me immediately and delete
>> > this message from your computer system. Any unauthorized use or
>> > distribution is prohibited. Please consider the environment before
>> printing
>> > this email.
>>
>> Regards,
>> Keith
>>
>>
>> --
>>
>> This message and its contents, including attachments are intended solely
>> for the original recipient. If you are not the intended recipient or have
>> received this message in error, please notify me immediately and delete
>> this message from your computer system. Any unauthorized use or
>> distribution is prohibited. Please consider the environment before
>> printing
>> this email.
>>
>

-- 

This message and its contents, including attachments are intended solely 
for the original recipient. If you are not the intended recipient or have 
received this message in error, please notify me immediately and delete 
this message from your computer system. Any unauthorized use or 
distribution is prohibited. Please consider the environment before printing 
this email.


More information about the users mailing list