cross compile 하는 중에 소스가 semaphore.h를 인식하지 못하는 것 같아요...
저는 net-snmp-5.3.2의 agentx를 fedora11에서 크로스 컴파일 하고 있었습니다.
아래는 agentx Makefile 입니다.
============================================================================================
#
# Warning: you may need more libraries than are included here on the
# build line. The agent frequently needs various libraries in order
# to compile pieces of it, but is OS dependent and we can't list all
# the combinations here. Instead, look at the libraries that were
# used when linking the snmpd master agent and copy those to this
# file.
#
PROJDIR = /home/proj/msap/apps/sychoi
INSTDIR = $(PROJDIR)/rootfs/usr/sbin
SNMPINC = /home/proj/msap/apps/sychoi/install/usr
CC=ppc_82xx-gcc
STRIP=ppc_82xx-strip
OBJS += agentx.o
OBJS += fan.o
OBJS += exam.o
TARGETS = agentx
CFLAGS += -O2 -Dlinux -I. -I$(SNMPINC)/include
BUILDLIBS = -L$(SNMPINC)/lib -lnetsnmp -lcrypto -lm
BUILDAGENTLIBS = -L$(SNMPINC)/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmphelpers -lnetsnmp -ldl -lcrypto -lm
# shared library flags (assumes gcc)
DLFLAGS=-fPIC -shared -lpthread
all: $(TARGETS)
agentx: $(OBJS)
$(CC) -o agentx $(OBJS) $(BUILDLIBS) $(BUILDAGENTLIBS)
$(STRIP) agentx
install:
cp -a agentx $(INSTDIR)
clean:
rm -f $(OBJS) $(TARGETS)===========================================================================================
그리하여 make 명령을 내리니..... 소스파일에서 에러가 나는군요...
===========================================================================================
[root@localhost nextest]# make agentx ppc_82xx-gcc -O2 -Dlinux -I. -I/home/proj/msap/apps/sychoi/install/usr/include -c -o agentx.o agentx.c ppc_82xx-gcc -O2 -Dlinux -I. -I/home/proj/msap/apps/sychoi/install/usr/include -c -o fan.o fan.c ppc_82xx-gcc -O2 -Dlinux -I. -I/home/proj/msap/apps/sychoi/install/usr/include -c -o exam.o exam.c ppc_82xx-gcc -o agentx agentx.o fan.o exam.o -L/home/proj/msap/apps/sychoi/install/usr/lib -lnetsnmp -lcrypto -lm -L/home/proj/msap/apps/sychoi/install/usr/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmphelpers -lnetsnmp -ldl -lcrypto -lm exam.o: In function `init_exam': exam.c:(.text+0x27c): undefined reference to `sem_init' exam.o: In function `examNEXTable_get_next_data_point': exam.c:(.text+0x370): undefined reference to `sem_wait' exam.c:(.text+0x3f8): undefined reference to `sem_post' exam.c:(.text+0x4cc): undefined reference to `sem_post'
===========================================================================================
문제는 exam.c 가 "semaphore.h" 를 인식하지 못하는 것 같은데요..
를
소스파일의 일부를 가져왔습니다.
==========================================================================
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "exam.h"
//#include "/opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h"
#include <semaphore.h>
sem_t exam_sem;
....................................................................................
........
netsnmp_variable_list *
examNEXTable_get_next_data_point(void **my_loop_context,
void **my_data_context,
netsnmp_variable_list * put_index_data,
netsnmp_iterator_info *mydata)
{
struct examNEXTable_entry *entry = (struct examNEXTable_entry *) *my_loop_context;
netsnmp_variable_list *idx = put_index_data;
printf("entry :%d put_index_data: %d\n", entry, put_index_data);
struct examNEXTable_entry *ptr, *prev;
int find =0;
sem_wait(&exam_sem);
printf("sema_wait end!!\n");
for(prev =NULL, ptr=examNEXTable_head; ptr!=NULL; prev=ptr, ptr=ptr->next){
if(entry==ptr)
find =1;
printf("find : %d ptr : %d entry: %d\n", find, ptr, entry);
}
if (entry && find) {
snmp_set_var_value(idx, (u_char *)entry->name, strlen(entry->name));
printf("entry->name : %s len : %d \n", (u_char *)entry->name, strlen(entry->name));
idx = idx->next_variable;
printf("idx : %d idx->nex_variable : %d \n", idx, idx->next_variable);
*my_data_context = (void *) entry;
printf("my_data_context : %d \n", *my_data_context);
*my_loop_context = (void *) entry->next;
printf("my_loop_context: %d \n", *my_loop_context);
sem_post(&exam_sem);
printf("put_index_data : %d\n", put_index_data);
return put_index_data;
} else {
sem_post(&exam_sem);
printf("else!!\n");
return NULL;
}
}==========================================================================
저는 "semaphore.h"가 ppc_82xx format 이 아니라서 그런 에러가 나나 생각했습니다.
그래서 ppc_82xx format의 "semaphore.h" 을 include 했는데...
아래와 같은 에러가 나더군요..
==========================================================================
[root@localhost nextest]# make agentx ppc_82xx-gcc -O2 -Dlinux -I. -I/home/proj/msap/apps/sychoi/install/usr/include -c -o agentx.o agentx.c ppc_82xx-gcc -O2 -Dlinux -I. -I/home/proj/msap/apps/sychoi/install/usr/include -c -o fan.o fan.c ppc_82xx-gcc -O2 -Dlinux -I. -I/home/proj/msap/apps/sychoi/install/usr/include -c -o exam.o exam.c In file included from exam.c:10: /opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:30:28: error: bits/semaphore.h: No such file or directory In file included from exam.c:10: /opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:37: error: parse error before '*' token /opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:40: error: parse error before '*' token /opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:43: error: parse error before '*' token /opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:43: warning: data definition has no type or storage class /opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:46: error: parse error before '*' token /opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:55: error: parse error before '*' token /opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:67: error: parse error before '*' token /opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:70: error: parse error before '*' token /opt/eldk-4.1/ppc_8xx/usr/include/semaphore.h:73: error: parse error before '*' token exam.c:14: error: parse error before 'exam_sem' exam.c:14: warning: data definition has no type or storage class make: *** [exam.o] 오류 1
==========================================================================
뭐가 문제가 되서 그런 걸까요...
다른 소스에도 가 포함된 것이 많은데...
단순히 cross compile 할 때만 이런 에러가 나는군요...
아시는 분은 답변 달아주시면 감사하겠습니다....
제가 초보라서 그러니... 좀 어이 없는 질문이라도 양해 부탁드립니다.


이런 일은 다른 분에게는 일어나지 않는 일인가요...
저만 그런가요... 일단 semaphore.h 가 involve 되지 않으면서 sem_init, sem_post등을 모른다고 나오는 것 같은데요...
semaphore.h 는 /usr/lib 에 있습니다.... 이 문제 때문에...자꾸만 일이 뒤쳐지는데요...조금이라도 아시는 분 계시면 답글 부탁드립니다.
맨 처음의 에러는
맨 처음의 에러는 링크 에러입니다.
glibc 라면 Makefile 수정해서 -lrt 로 librt 를 같이 링크해주시면 될 겁니다.
그 이후의 에러는 ... 머리싸매고 고민하실 필요없습니다.
문제를 고치려고 노력하신게 아니라, 원래 없던 새로운 문제들을 계속 만들어내고 계십니다.
복사한 거, 고친 거... 원래대로 전부 복구하시거나 새로 설치하세요.
/usr/include 에 sempahore.h 할애비가 있어도 크로스 컴파일과는 상관없습니다.
OTL
댓글 달기