net-snmp-5.3.2를 크로스 컴파일 하는데 라이브러리소스를 링크안시켜 줬는데 에러가 없다.

bakdorazi의 이미지

<환경> 1. 페도라 11 2. net-snmp-5.3.2

<문제점 1>

1. 라이브러리 소스를 agent/mibgroup에 복사했습니다.

2. mib-module 파일은 fan.c log.c 입니다.

3. 위의 소스 파일은 라이브러리에서 정의된 함수를 호출합니다.

예)fan.c 에는 nex_fan.c 가 인클루드 되어 있습니다. 즉 nex_fan.c에 있는 함수를 불러옵니다.

3. 라이브러리 소스를 이용해서 libnexcmd.a라는 함수를 만들었는데 이렇게 만든 함수를 인스톨 스크립트에 추가해서 넣거나 링크하지 않았습니다.

4. LD_LIBRATY_PATH에 경로를 추가하지 않았으면 어떤 환경 변수에도 위의 라이브러리 함수를 추가하거나 링크하지 않았습니다.

5. net-snmp-5.3.2폴더에서 make를 하면 아무런 에러없이 컴파일되며 보드위에서 올려서 실행시에도 아무 에러가 나지 않습니다.

아래는 인스톨 스크립트 입니다.

./configure --host=i386-linux --build=ppc-linux --target=ppc-linux --prefix=/usr --exec-prefix=/usr --enable-shared --disable-debugging --enable-mini-agent --with-mibs="IP-MIB:IF-MIB:TCP-MIB:UDP-MIB:SNMPv2-MIB:RFC1213-MIB:NEXCOMM-FAN-MIB:NEXCOMM-LOG-MIB:NEXCOMM-MODULE-MIB" --with-mib-modules="agentx ucd-snmp/dlmod nextest/fan nextest/log nextest/module" --with-enterprise-notification-oid=.1.3.6.1.4.1.5927.99.12.1 --sysconfdir=/etc --localstatedir=/var --enable-internal-md5 --enable-snmpv1 --enable-snmpv2c --disable-embedded-perl --with-cc=ppc_82xx-gcc --with-linkcc=ppc_82xx-gcc --with-ar=ppc_82xx-ar --with-endianness=big --with-install-prefix=/home/test/install --without-rpm | tee snmp.config.l
 
 
make | tee snmp.config.log
 
perl -pi -e "s|^prefix=/usr|prefix=/home/psyche/sychoi/install/usr|" net-snmp-config
 
perl -pi -e "s|^exec_prefix=/usr|exec_prefix=/home/psyche/sychoi/install/usr|" net-snmp-config
 
make install | tee snmp.intall.log

<추신> 전에 이와 유사한 문제로 게시판에 글 올려서 많은 도움을 받았습니다. bush님께서 많이 도와주셨는데요...

그때 문제는 라이브러리를 링크해도 실행하면 응답이 오지않는다는 것입니다. 지금은 그때와는 정반대의 질문인데요.

그때 그 문제를 풀기 위해서 처음부터 mib2c를 이용하여 소스부터 생성하는 걸 다시 했습니다. 그러다가 발견한 건데요..

mib module 소스의 이름을 mib에 정의된 object identity 이름으로 하니까.. 응답이 오더라구요...

그러니까 NEXCOMM-FAN-MIB 일 경우 fan으로 소스이름을 바꾸니까 실행이 되는데... 이제 문제는 라이브러리 include와 상관없이 실행되다는 거지요..

이게 웬일인가... 하지만 사실입니다...

<문제점2>

1. 위의 인스톨 스크립트에 module.c를 추가하면 make시 라이브러리에서 호출하는 함수에 대한 에러는 안나는데요.
단 semaphore.h 를 include 안하면 발생하는 문제 sem_init, sem_post, sem_wait를 찾을 수 없다는 에러가 나네요....

2. 위의 문제점을 해결하려고 net-snmp 다 지우고 새로운 디렉토리에 새로 압축 풀어서 깔고 라이브러리 소스와 mib module 소스만 카피해서 새로 해봤지만 똑같은 문제들이 연속입니다.

/bin/sh ../libtool  --mode=link ppc_82xx-gcc -g -O2 -Dlinux  -o snmpd snmpd.lo    libnetsnmpmibs.la libnetsnmpagent.la helpers/libnetsnmphelpers.la  ../snmplib/libnetsnmp.la -ldl -lcrypto -lm   
ppc_82xx-gcc -g -O2 -Dlinux -o snmpd snmpd.o  ./.libs/libnetsnmpmibs.a ./.libs/libnetsnmpagent.a helpers/.libs/libnetsnmphelpers.a ../snmplib/.libs/libnetsnmp.a -ldl -lcrypto -lm 
./.libs/libnetsnmpmibs.a(module.o): In function `moduleTable_remove':
nextest/module.c:239: undefined reference to `sem_wait'
nextest/module.c:257: undefined reference to `sem_post'
nextest/module.c:247: undefined reference to `sem_post'
./.libs/libnetsnmpmibs.a(module.o): In function `moduleTable_createEntry':
nextest/module.c:196: undefined reference to `sem_wait'
nextest/module.c:199: undefined reference to `sem_post'
./.libs/libnetsnmpmibs.a(module.o): In function `init_module':
nextest/module.c:140: undefined reference to `sem_init'
./.libs/libnetsnmpmibs.a(module.o): In function `moduleTable_removeEntry':
nextest/module.c:214: undefined reference to `sem_wait'
nextest/module.c:230: undefined reference to `sem_post'
nextest/module.c:220: undefined reference to `sem_post'
./.libs/libnetsnmpmibs.a(module.o): In function `moduleTable_get_next_data_point':
nextest/module.c:285: undefined reference to `sem_wait'
nextest/module.c:303: undefined reference to `sem_post'
nextest/module.c:300: undefined reference to `sem_post'
collect2: ld returned 1 exit status
make[1]: *** [snmpd] 오류 1
make[1]: Leaving directory `/home/test/net-snmp-5.3.2/agent'
make: *** [subdirs] 오류 1

3. 위의 문제들을 풀어보려고 라이브러리를 링크하거나 make 파일에 CFLAGS를 써서 해더파일을 링크하거나 하는 일을 했었는데요.. 그래서 위의 에러가 여전히 나더라구요..
쉽게 말하자면 라이브러리를 링크하거나 안하거나 에러는 똑같이 난다는 것입니다.
위의 문제1과 비슷한 연장선에서 보면 둘 다 .. 라이브러리와는 상관없이 프로그램이 컴파일되고 실행되고 한다는 것입니다...ㅠㅠ

제가 혼자서 풀어보려고 머리를 짜내고 아이디어가 떠오르지 않네요..

그래서 나약하게도 여기다 다시 글을 올립니다.

읽어보시고 도움을 주실 수 있는 분들의 답변을 기다립니다..

도와주세요..제발...

bakdorazi의 이미지

설치 및 실행 시 아무 에러 없는 것은 라이브러리 소스 파일을 agent/mibgroup에 복사해놨기 때문이라고 저희 상사께 설명드렸습니다. 그랬더니 말도 안되는 소리라고 하시더군요. 사실 snmp는 agent/mibgroup 폴더를 default source 폴더로 참고하기 때문에 컴파일 시 불러내야 하는 함수들은 따로 헤더를 include 하지 않아도 되지 않나 생각했는데요. 저희 상사는 그럼 라이브러리 소스들이 컴파일 된 목적 파일 *.o 파일이 있냐고 물으시더군요. 물론 없다고 말씀드렸습니다. 더 노력하라고 말씀하시던데요...
일단은 라이브러리 링크 하든 안하든 아무 영향 없고... 소스 잘 컴파일되고 단지 문제는 sem_init, sem_post 같은 세마포언 관련 함수들을 인식하지 못하는 것이 문제인데요... 어떤 아이디어라도 계시면 조언을 좀 부탁드립니다. snmp에 관해 모르시더라도 이런 경우가 만약 있으신 분들이 계시거나 혹은 이런 일이 생긴다면 이런 식으로 해결가능하다고 생각하시는 거라도 ... 하다못해 구글에서 어떤 걸 검색하면 해법을 찾을 수 있을거라도 코멘트라 부탁드립니다. 현재로는 무얼 찾아야 겠다는 아이디어 조차도 떠오르지 않네요.. 제발 부탁드립니다.

bakdorazi의 이미지

구글에서 검색해 보니 저와 같은 증상에 대하여 아래와 같은 답변이 있었습니다.

============================================================================

you have to link in the library when compiling : try adding -lpthreads to the compile command

==============================================================================

컴파일할 때 라이브러리 링크를 해줘야 하는데 -lpthreads 옵션을 줘서 해라는 이야기입니다.

그리하여 snmp Makefile에 아래와 같이 추가하였습니다.

저의 개인 라이브러리 파일이 있는 곳은 /home/test/net-snmp-5.3.2/agent/mibgroup/nextest입니다.
그리고 /home/proj/msap/include는 라이브러리 소스와 헤더파일은 /home/test/net-snmp-5.3.2/agent/mibgroup/nextest에 모두 모아놨지만 여기에도 같은 파일이 있기에 혹시나 하는 심정에서 여기도 인클루드 하였습니다.

# Compiler arguments
#
CFLAGS          = -I /home/proj/masp/include                           
CFLAGS          += -g -O2 -Dlinux -I. -I /home/test/install/usr/include
EXTRACPPFLAGS   = -x c
#LDFLAGS                =  
LDFLAGS         = /home/test/net-snmp-5.3.2/agent/mibgroup/nextest/libnexcmd.a -lpthread
LIBTOOL         = $(SHELL) $(top_builddir)/libtool
EXEEXT          =

그리하여 make를 하였더니 역시나 아래와 같은 에러가 나왔는데

/bin/sh ../libtool  --mode=link ppc_82xx-gcc -g -O2 -Dlinux  -o snmpd snmpd.lo    libnetsnmpmibs.la libnetsnmpagent.la helpers/libnetsnmphelpers.la  ../snmplib/libnetsnmp.la -ldl -lcrypto -lm   
ppc_82xx-gcc -g -O2 -Dlinux -o snmpd snmpd.o  ./.libs/libnetsnmpmibs.a ./.libs/libnetsnmpagent.a helpers/.libs/libnetsnmphelpers.a ../snmplib/.libs/libnetsnmp.a -ldl -lcrypto -lm 
./.libs/libnetsnmpmibs.a(module.o): In function `moduleTable_remove':
nextest/module.c:239: undefined reference to `sem_wait'
nextest/module.c:257: undefined reference to `sem_post'
nextest/module.c:247: undefined reference to `sem_post'
./.libs/libnetsnmpmibs.a(module.o): In function `moduleTable_createEntry':
nextest/module.c:196: undefined reference to `sem_wait'
nextest/module.c:199: undefined reference to `sem_post'
./.libs/libnetsnmpmibs.a(module.o): In function `init_module':
nextest/module.c:140: undefined reference to `sem_init'
./.libs/libnetsnmpmibs.a(module.o): In function `moduleTable_removeEntry':
nextest/module.c:214: undefined reference to `sem_wait'
nextest/module.c:230: undefined reference to `sem_post'
nextest/module.c:220: undefined reference to `sem_post'
./.libs/libnetsnmpmibs.a(module.o): In function `moduleTable_get_next_data_point':
nextest/module.c:285: undefined reference to `sem_wait'
nextest/module.c:303: undefined reference to `sem_post'
nextest/module.c:300: undefined reference to `sem_post'
collect2: ld returned 1 exit status
make[1]: *** [snmpd] 오류 1
make[1]: Leaving directory `/home/test/net-snmp-5.3.2/agent'
make: *** [subdirs] 오류 1

혹시나 컴파일 옵션을 주는 중에 무슨 문제가 있나요..
왜 에러가 픽스가 안되는 지 모르겠어요..

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.