net-snmp로 subagent를 만드는데 semaphore.h를 include 안했을 때 에러가 나네요.
글쓴이: bakdorazi / 작성시간: 월, 2010/05/10 - 5:56오후
net-snmp-5.3.2를 깔고 agent/mibgroup/nextest 폴더에 소스 파일을 넣었습니다.
소스명 : module.c module.h
소스 파일을 간단히 소개하자면 아래와 같습니다.
/* * Note: this file originally auto-generated by mib2c using * : mib2c.iterate.conf 16004 2007-03-27 09:20:28Z dts12 $ */ #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h> #include <semaphore.h> #include "common.h" #include "nex_common.h" #include "module.h" #include "nex_module.h" #include "nex_module.c" static sem_t module_sem; /* * Typical data structure for a row entry */ struct moduleTable_entry { /* * Index values */ long modulenum; /* * Column values */ long devicetype; long old_devicetype; long devicemode; long old_devicemode; char description; char old_description; char type; char firmware; char uptime; char restart; char old_restart; /* * Illustrate using a simple linked list */ ................................................ netsnmp_variable_list *moduleTable_get_first_data_point(void **my_loop_context, void **my_data_context, netsnmp_variable_list * put_index_data, netsnmp_iterator_info *mydata) { *my_loop_context = moduleTable_head; return moduleTable_get_next_data_point(my_loop_context,my_data_context, put_index_data,mydata); } netsnmp_variable_list * moduleTable_get_next_data_point(void **my_loop_context, void **my_data_context, netsnmp_variable_list * put_index_data, netsnmp_iterator_info *mydata) { struct moduleTable_entry *entry = (struct moduleTable_entry *) *my_loop_context; netsnmp_variable_list *idx = put_index_data; struct moduleTable_entry *ptr; struct moduleTalbe_entry *prev; int find=0; sem_wait(&module_sem); for (ptr = moduleTable_head, prev = NULL; ptr != NULL; prev = ptr, ptr = ptr->next) { if (entry == ptr){ find = 1; printf("entry : %d ptr: %d find : %d \n", entry, ptr, find); } } if (entry && find) { snmp_set_var_value(idx, (u_char *)&entry->modulenum, sizeof(entry->modulenum)); printf("modulenum : %d idx : %d (u_char *)&entry->modulenum : %d sizeof(entry->modulenum) : %d \n", idx, entry->modulenum, (u_char *)&entry->modulenum, sizeof(entry->modulenum)); idx = idx->next_variable; *my_data_context = (void *) entry; *my_loop_context = (void *) entry->next; printf("put_index_data : %d \n", put_index_data); sem_post(&module_sem); return put_index_data; } else { sem_post(&module_sem); return NULL; } }
위의 소스를 가지고 아래와 같은 작업을 진행했었는데...
net-snmp에서 서브 에이젼트 만드는 명령은 아래와 같습니다.
net-snmp-config --compile-subagent "서브에이젼트명" "소스명"
위의 명령어를 가지고 아래와 같이 컴파일 했는데요...
semaphore.h를 include 안했을때 에러가 나왔습니다.
다른 소스들도 세마포어 함수를 쓴 것들은 다른 에러들은 안나오는데 아래와 같은 에러가 동일하게 나옵니다.
[root@localhost nextest]# net-snmp-config --compile-subagent module module.c generating the tmporary code file: netsnmptmp.29599.c void init_module(void); checking for init_module in module.c void init_module(void) running: ppc_82xx-gcc -g -O2 -Dlinux -I. -I/home/test/install/usr/include -o module netsnmptmp.29599.c module.c -L/home/test/install/usr/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmphelpers -lnetsnmp -ldl -lcrypto -lm module.c: In function 'moduleTable_get_next_data_point': module.c:285: warning: assignment from incompatible pointer type /tmp/cc5rU0Qx.o: In function `moduleTable_remove': /home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:238: undefined reference to `sem_wait' /home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:256: undefined reference to `sem_post' /home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:246: undefined reference to `sem_post' /tmp/cc5rU0Qx.o: In function `moduleTable_createEntry': /home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:195: undefined reference to `sem_wait' /home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:198: undefined reference to `sem_post' /tmp/cc5rU0Qx.o: In function `init_module': /home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:139: undefined reference to `sem_init' /tmp/cc5rU0Qx.o: In function `moduleTable_removeEntry': /home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:213: undefined reference to `sem_wait' /home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:229: undefined reference to `sem_post' /home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:219: undefined reference to `sem_post' /tmp/cc5rU0Qx.o: In function `moduleTable_get_next_data_point': /home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:284: undefined reference to `sem_wait' /home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:302: undefined reference to `sem_post' /home/test/net-snmp-5.3.2/agent/mibgroup/nextest/module.c:299: undefined reference to `sem_post' collect2: ld returned 1 exit status removing the tmporary code file: netsnmptmp.29599.c
웹에서 찾아보니 -lpthread를 쓰라고 되어 있던데...
서브 에이젼트 말고 전체 snmp 깔때 mib-modle 에 소스추가해서 하는 방식으로 할 때 LIBFLAGS에 추가시켜서 해봤는데
아무 소용이 없더라구요...
도대체 세마포어 관련 에러는 왜 나오는 것이며 이걸 클리어 할 방법은 없습니까?
아무리 질문 올려도 답이 없어서요..
제발 좀 도와주세요.
Forums:
아마 sem_wait가 semaphore.h에 매크로로 지정되어있어서 그런거 같습니다
한번 semaphore.h여기에 sem_wait가 어떻게 정의되어있나 보세여
즐린
즐린
semaphore.h를 봤습니다.
semaphore.h 파일을 살펴보았는데요..
아래 파일 입니다.
보시면 아시겠지만 extern int 형으로 선언되어 있습니다.
혹은 위와 같은 경우 제가 어떻게 하면 좋을까요?
/lib/libpthread.so 퍼일에 이 함수가 있네여.
[hys545@localhost lib]$ nm libpthread-2.11.1.so | grep sem_wait
00ba0f40 t __new_sem_wait
00ba0fe0 t __old_sem_wait
00ba0f40 T sem_wait@@GLIBC_2.1
00ba0fe0 T sem_wait@GLIBC_2.0
00ba0fcc t sem_wait_cleanup
00ba1177 t sem_wait_cleanup
이런경우 -lpthread로 하면 될거 같은데
이 옵션 주고도 안되면
한번
pthread 라이브러리에 함수가 있나 확인해보세여
즐린
즐린
댓글 달기