[완료]gcc -static -L/usr/local/lib -lnet -o test test.c 가 잘안됩니다.도와주세요.
#include <stdio.h> #include <libnet.h> int main(){ u_int32_t i; libnet_t *l; libnet_ptag_t t; u_int8_t *packet; u_int32_t packet_s; char errbuf[LIBNET_ERRBUF_SIZE]; u_char enet_src[6] = {0x00, 0x00, 0x00, 0x0a, 0x0b, 0x0c}; u_char enet_dst[6] = {0x00, 0x00, 0x00, 0x0d, 0x0e, 0x0f}; l = libnet_init( LIBNET_LINK_ADV, "wlan0", errbuf); i = libnet_get_ipaddr4(l); t = libnet_autobuild_arp( ARPOP_REPLY, enet_src, (u_int8_t *)&i, enet_dst, (u_int8_t *)&i, l); t = libnet_autobuild_ethernet( enet_dst, ETHERTYPE_ARP, l); libnet_write(l); libnet_destroy(l); printf("wlan0 send complete!\n"); return 0; }
이렇게 libnet을 이용해서 커스텀패킷을 보내는 test.c를 만들었습니다.
라이브러리는 /usr/local/lib에 libnet.a 와 libnet.so 두개가 있습니다.
gcc -L/usr/local/lib -lnet -o test test.c
를 해서 libnet.so와 링크하여 만든 실행파일을 실행하니,
예상대로 패킷이 잘 나갑니다.
그런데 제가 원하는건 정적링크, libnet.a와 합체시키는 겁니다. 그래서
gcc -static -L/usr/local/lib -lnet -o test test.c
를 햇더니
/tmp/ccS0sbPQ.o: In function `main':
test.c:(.text+0x8d): undefined reference to `libnet_init'
test.c:(.text+0xa1): undefined reference to `libnet_get_ipaddr4'
test.c:(.text+0xe5): undefined reference to `libnet_autobuild_arp'
test.c:(.text+0x10b): undefined reference to `libnet_autobuild_ethernet'
test.c:(.text+0x11f): undefined reference to `libnet_write'
test.c:(.text+0x12d): undefined reference to `libnet_destroy'
collect2: ld returned 1 exit status
이렇게 자꾸 실패합니다.
무엇이 문제입니까?
/usr/local/lib/libnet.a 파일에
/usr/local/lib/libnet.a 파일에 symbol이 제대로 등록되어있는지 먼저 확인해보세요.
nm /usr/local/lib/libnet.a |grep libnet_autobuild_arp 같은 식으로 해보면 압니다.
symbol이 정의가 안되있으면 잘못된 *.a 파일인 것이겠죠.
nm
"U" 라고 되어있는 것은 undefined입니다.
"U" 라고 되어있는 것은 undefined입니다. libnet.a static 빌드옵션을 잘 못 주거나 제대로 빌드되지 않았을 가능성이 높네요.
혹은 dynamic하게 링크된 실행파일이 어떤 라이브러리를 쓰고 있는지 다시 한번 확인해보세요. ldd 실행파일 혹은 objdump --all-headers 실행파일 하면 실행파일이 필요로 하는 라이브러리 리스트를 좌악 보여줍니다.
음... 다시 보니 심볼이 모두 정의되어있네요.
음... 다시 보니 심볼이 모두 정의되어있네요. ld에 문제가 있는 듯...
http://stackoverflow.com/ques
http://stackoverflow.com/questions/6578484/telling-gcc-directly-to-link-a-library-statically 이걸 참고해보시기를
-lnet을 test.c로 보내면 될것요. 아마
-lnet을 test.c로 보내면 될것요. 아마 링커가 심볼을 찾는 순서때문에 생기는 문제일거예요.
gcc -static -L/usr/local/lib -o test test.c -lnet
.
약간 버그성이기는 해도, 저 역시 심볼 없다는 오류가
약간 버그성이기는 해도, 저 역시 심볼 없다는 오류가 날 때에 말씀하신 것처럼 링크 라이브러리 순서를 바꿔서 해결하곤 했습니다
다들 감사합니다. 덕분에 해결했습니다. 이걸
다들 감사합니다.
덕분에 해결했습니다.
이걸 버그성이라고 봐야하나요?
댓글 달기