AnsweredAssumed Answered

Cross compiling problem about Libiio

Question asked by springping on Jul 8, 2015
Latest reply on Apr 17, 2018 by come0088@qq.com

I created cross compile enviroment on linux host according to the instruction of Building on the Linux Host Target in the page What is libiio? [Analog Devices Wiki], Then I created a simple C file named "hello.c" to test if it would be compiled successfully,the source code as shown below:

#include <iio.h>

#include <stdio.h>

@@@@@@@

void main()

{

    struct iio_context *ctx = NULL;

    unsigned int num_devices = 0;

    int i=0;

 

    const char *lName = NULL;

    if(ctx)

    {

        lName = iio_context_get_name(ctx);

    }

    else;

   

    if(!lName || strcmp(lName, "local"))

    {

        ctx = iio_create_local_context();

    }

    else;

 

   

    if(ctx)

    {

        //get numbers of devices

        num_devices = iio_context_get_devices_count(ctx);

 

        for(i = 0; i < num_devices; i++)

        {

            //get device object

            struct iio_device *lDev = iio_context_get_device(ctx, i);

            //get device name and display

            if(lDev)

            {

                printf("DeviceName:%s\n", iio_device_get_name(lDev));

            }

        }

    }

    else;

}

 

I complied the file but not success.

woo@woo-ThinkPad-T410:~$ arm-xilinx-linux-gnueabi-gcc hello.c -o hello

hello.c:1:17: fatal error: iio.h: No such file or directory

 

Then I added the "iio.h" header to the folder "/CodeSourcery/lib/gcc/arm-xilinx-linux-gnueabi/include" and compiled again, but it doesn,t work.

 

woo@woo-ThinkPad-T410:~$ arm-xilinx-linux-gnueabi-gcc hello.c -o hello

/tmp/cciufmLf.o: In function `main':

hello.c:(.text+0x3c): undefined reference to `iio_context_get_name'

hello.c:(.text+0x6c): undefined reference to `iio_create_local_context'

hello.c:(.text+0x84): undefined reference to `iio_context_get_devices_count'

hello.c:(.text+0xa4): undefined reference to `iio_context_get_device'

hello.c:(.text+0xbc): undefined reference to `iio_device_get_name'

collect2: error: ld returned 1 exit status

 

so I don't know where the problem is. Maybe it is a simple question, but as a beginner of analog, I really need your help, thanks!

Outcomes