2012-11-04 1 views
2

나는 원래 iPhone 용으로 만들어진 this C program called Pirni을 컴파일하려고하는데, 나는 이것을 Linux Ubuntu 12.04 LTS에서 실행하고 싶다. 매우 짧습니다 (3 개의 C 파일과 1 개의 헤더 파일). 하지만 다음과 같은 오류가 발생합니다. 나는 libpcap-dev을 설치했고 -lpcap을 포함했기 때문에 무엇이 잘못 될 수 있는지 알지 못합니다.올바른 플래그를 전달 했음에도 불구하고 발생하는 "정의되지 않은 참조"링커 오류를 수정하는 방법은 무엇입니까?

gcc -Wall -pthread -lpcap pirni.c threads.c sniffer.c -o pirni -lnet 
pirni.c: In function ‘set_forwarding’: 
pirni.c:31:2: warning: implicit declaration of function ‘sysctlbyname’ [-Wimplicit-function-declaration] 
/tmp/cc3sf284.o: In function `set_forwarding': 
pirni.c:(.text+0xfd): undefined reference to `sysctlbyname' 
/tmp/ccvGjyMo.o: In function `processPacket': 
sniffer.c:(.text+0x1b): undefined reference to `pcap_dump' 
/tmp/ccvGjyMo.o: In function `initSniffer': 
sniffer.c:(.text+0xfa): undefined reference to `pcap_open_live' 
sniffer.c:(.text+0x15a): undefined reference to `pcap_lookupnet' 
sniffer.c:(.text+0x1af): undefined reference to `pcap_compile' 
sniffer.c:(.text+0x1dd): undefined reference to `pcap_setfilter' 
sniffer.c:(.text+0x222): undefined reference to `pcap_dump_open' 
sniffer.c:(.text+0x27c): undefined reference to `pcap_loop' 
collect2: ld returned 1 exit status 
make: *** [main] Error 1 

답변

6
gcc -Wall -pthread -lpcap pirni.c threads.c sniffer.c -o pirni -lnet 
        ^^^^^^ 

움직임은 끝으로, 그래서 링커는 연결해야하는 기호를 알고 있다는 것을.

라이브러리가 명령 행에있는 라이브러리에서 링커는 지금까지 libpcap의 기호가 필요하지 않으므로 무시합니다.

6

이 말해 :

gcc -Wall -pthread pirni.c threads.c sniffer.c -o pirni -lnet -lpcap 
#              ^^^^^^^^^^^^ 

라이브러리 로컬 번역 단위 후 을 나열해야합니다. 귀하의 ld 매뉴얼은 이유에 대해 자세히 설명합니다 (누락 된 기호를 검색하고 삽입하는 방법과 관련이 있습니다).