OpenWrt Forum Archive

Topic: cross compile libftdi

The content of this topic has been archived on 23 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

please help. (sorry for my english)

I try to compile helloworld code from this guide: http://gargoyle-router.com/old-openwrt-coding.html
it's compiled and i can run it on my tp-link mr3020 (attitude_adjustment)

Ok. now i want compile sample code from http://www.intra2net.com/en/developer/l … mentation/
i take code from this page and insert it into helloworld.c and run make. In this case code does not compile with next error:

" undefined reference to 'ftdi_usb_close' " (this is function from ftdI.h)

so my question is
Why compiler cannot find and include "ftdi.h" but can find and include "stdio.h" if they locate in one folder (/usr/include/)?

and

HOW i can get success? (step by step)

p.s. i also try use -MD key for generate *.d file with paths to header file and include this *.d file to makefile.


Thanks

(Last edited by tregub on 4 Nov 2012, 19:33)

You have the source code from libftdi?

tregub wrote:

so my question is
Why compiler cannot find and include "ftdi.h" but can find and include "stdio.h" if they locate in one folder (/usr/include/)?

AFAIK, /usr/include is your host system include directory. OpenWRT include directory is under $(STAGING_DIR)/usr/include.

mazilo wrote:

AFAIK, /usr/include is your host system include directory. OpenWRT include directory is under $(STAGING_DIR)/usr/include.

i try put file ftdi.h into $(STAGING_DIR)/usr/include but it does not solve my problem

i do next steps:

1. install debian on virtualbox
2. install libftdi
3. download and unpack http://downloads.openwrt.org/attitude_a … .2.tar.bz2

4. create folder "helloworld" in OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2/package

5. create folder "src" in OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2/package

6. create file helloworld.c in OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2/package/src

#include <stdio.h>
#include <ftdi.h>

int main(void)
{
    int ret;
    struct ftdi_context ftdic;
    if (ftdi_init(&ftdic) < 0)
    {
        fprintf(stderr, "ftdi_init failed\n");
        return EXIT_FAILURE;
    }

    if ((ret = ftdi_usb_open(&ftdic, 0x0403, 0x6001)) < 0)
    {
        fprintf(stderr, "unable to open ftdi device: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
        return EXIT_FAILURE;
    }

    // Read out FTDIChip-ID of R type chips
    if (ftdic.type == TYPE_R)
    {
        unsigned int chipid;
        printf("ftdi_read_chipid: %d\n", ftdi_read_chipid(&ftdic, &chipid));
        printf("FTDI chipid: %X\n", chipid);
    }

    if ((ret = ftdi_usb_close(&ftdic)) < 0)
    {
        fprintf(stderr, "unable to close ftdi device: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
        return EXIT_FAILURE;
    }

    ftdi_deinit(&ftdic);

    return EXIT_SUCCESS;
}

7. create Makefile in OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2/package/src

helloworld: helloworld.o
    $(CC) $(LDFLAGS) helloworld.o -o helloworld
helloworld.o: helloworld.c
    $(CC) $(CFLAGS) -c helloworld.c

clean:
    rm *.o helloworld

8. create Makefile in OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2/package

include $(TOPDIR)/rules.mk

PKG_NAME:=helloworld
PKG_RELEASE:=1

PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/helloworld
    SECTION:=utils
    CATEGORY:=Utilities
    TITLE:=Helloworld -- prints a snarky message
endef

define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
    $(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Package/helloworld/install
    $(INSTALL_DIR) $(1)/bin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
endef

$(eval $(call BuildPackage,helloworld))

8. go to OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2 directory (cd /home/tregub/Downloads/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2)

9. do "make V=s"

10.  undefined reference to 'ftdi_usb_close'
undefined reference to 'ftdi_deinit' etc
collect2: ld returned 1 exit status


Whats wrong?

R U aware of and/or have you tried to compile the feeds/packages/libs/libftdi package from OpenWRT SVN trunk?

The discussion might have continued from here.