2016-07-26 7 views
-1

EDIT : 물론 완전한 복제본은 질문을하고 특정 답변을 얻으려는 stackoverflow의 전체 지점이 아니며 나를 연결 한 '대답'은 입니다. A. C++의 경우 부분적으로 이해할 수 없으므로 B. 위키 기사처럼 읽습니다. 거대하고, 사소한 것도 아니고, 조금 도움이되는 것도 아닙니다.정의되지 않은 참조 오류

내가 다운로드 한 코드 라이브러리 (libftdi)의 examples 폴더에서 예제 코드를 복사했습니다. 프로젝트를 작성할 때, 실행시 정의되지 않은 참조가 많이 있습니다. 그러나 원래 위치에서 잘 돌아갑니다.

홈페이지 파일 :

#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; 
} 

오류 :

[email protected] ~/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 

만들기 파일 :

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

all: 
    make bitbang 

clean: 
    rm bitbang 
+1

내가 돈 ' 요 표시 없음 ur 코드 ** 실행 **. ** 링커 ** 오류가 발생하면 ** 빌드 **합니다. – Olaf

+0

원래 위치에서 컴파일되고 정상적으로 실행되었으므로 추가하지 않았으므로 많은 표시가 표시되지 않습니다. 원하시겠습니까? 이것은 개발자의 한 예입니다. – ollie299792458

답변

0

당신은 FTDI 라이브러리와 연결해야 (-Llibdirectory -llib)

+0

이 줄 편집 :'CFLAGS = -Wall -g -I/usr/include/libftdi1/-L/usr/include/libftdi1/-lftdi' 이것을 얻으십시오 :'CFLAGS = -Wall -g -I/usr/include/libftdi1/-L/usr/include/libftdi1/-lftdi' – ollie299792458

+0

라이브러리가 어디에 있는지 확인하려면'pkg-config'를 사용하십시오. 라이브러리는'include' 폴더에 없습니다. – pleluron

+0

어떻게 그럴 수 있습니까? – ollie299792458