-1

EDIT: A complete duplicate of course, isn't the whole point of stackoverflow to ask questions, and get specific answers, the 'answer' you linked me to is: A. For C++, so partly unintelligible B. Reads like a wiki article, it is massive, and not specific in the slightest, or in the least bit helpful.

I have copied an example bit of code from the examples folder in the code library (libftdi) I downloaded, to where I want to write my project, when I run it, it has a lot of undefined references, however it runs fine in its original location.

Main file:

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

int main(void)
{
    int ret, i;
    struct ftdi_context *ftdi;
    struct ftdi_device_list *devlist, *curdev;
    char manufacturer[128], description[128];
    int retval = EXIT_SUCCESS;

    if ((ftdi = ftdi_new()) == 0)
    {
        fprintf(stderr, "ftdi_new failed\n");
        return EXIT_FAILURE;
    }

    if ((ret = ftdi_usb_find_all(ftdi, &devlist, 0, 0)) < 0)
    {
        fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n", ret, ftdi_get_error_string(ftdi));
        retval =  EXIT_FAILURE;
        goto do_deinit;
    }

    printf("Number of FTDI devices found: %d\n", ret);

    i = 0;
    for (curdev = devlist; curdev != NULL; i++)
    {
        printf("Checking device: %d\n", i);
        if ((ret = ftdi_usb_get_strings(ftdi, curdev->dev, manufacturer, 128, description, 128, NULL, 0)) < 0)
        {
            fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n", ret, ftdi_get_error_string(ftdi));
            retval = EXIT_FAILURE;
            goto done;
        }
        printf("Manufacturer: %s, Description: %s\n\n", manufacturer, description);
        curdev = curdev->next;
    }
done:
    ftdi_list_free(&devlist);
do_deinit:
    ftdi_free(ftdi);

    return retval;
}

Error:

ollieb@ursus ~/Documents/BitBang $ make
make bitbang 
make[1]: Entering directory '/home/ollieb/Documents/BitBang'
cc -Wall -g -I/usr/include/libftdi1/    bitbang.c   -o bitbang
/tmp/cc20kltT.o: In function `main':
/home/ollieb/Documents/BitBang/bitbang.c:13: undefined reference to `ftdi_new'
/home/ollieb/Documents/BitBang/bitbang.c:19: undefined reference to `ftdi_usb_find_all'
/home/ollieb/Documents/BitBang/bitbang.c:21: undefined reference to `ftdi_get_error_string'
/home/ollieb/Documents/BitBang/bitbang.c:32: undefined reference to `ftdi_usb_get_strings'
/home/ollieb/Documents/BitBang/bitbang.c:34: undefined reference to `ftdi_get_error_string'
/home/ollieb/Documents/BitBang/bitbang.c:42: undefined reference to `ftdi_list_free'
/home/ollieb/Documents/BitBang/bitbang.c:44: undefined reference to `ftdi_free'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'bitbang' failed
make[1]: *** [bitbang] Error 1
make[1]: Leaving directory '/home/ollieb/Documents/BitBang'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2

Make file:

CFLAGS=-Wall -g -I/usr/include/libftdi1/

all:
    make bitbang 

clean:
    rm bitbang
ollie299792458
  • 222
  • 3
  • 16

1 Answers1

0

You have to link against the ftdi library (-Llibdirectory -llib)

pleluron
  • 733
  • 4
  • 12