stat() 가 보이지 않는 현상입니다.

qprk의 이미지

환경 : redhat 9

gcc 2.95.3 


 

------------- stat.c -----------------

#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>


struct stat subuf;

//main()                                                                                                 
qprk()
{

  if(stat("a.java", &subuf) == -1){
    printf("stat error!!!\n");
    exit(0);
  }

  printf("uid->%d\n",subuf.st_uid);
}


 

 

 

-------- test.c --------------

#include"stdio.h"

main()
{

  qprk();
}


----------------------------

 

$ gcc -c stat.c

$ gcc -shared -o libstat.so stat.o

$ gcc test.c libstat.so

$ ./a.out

uid->500



-------------------------------------------


$ nm libstat.so
00001950 A _DYNAMIC
00001a28 A _GLOBAL_OFFSET_TABLE_
00001a1c d __CTOR_END__
00001a18 d __CTOR_LIST__
00001a24 d __DTOR_END__
00001a20 d __DTOR_LIST__
0000194c d __EH_FRAME_BEGIN__
0000194c d __FRAME_END__
         U ___brk_addr@@GLIBC_2.0
00001a58 A __bss_start
         U __curbrk@@GLIBC_2.0
         w __deregister_frame_info@@GLIBC_2.0
000008a4 t __do_global_ctors_aux
00000734 t __do_global_dtors_aux
         U __environ@@GLIBC_2.0
         w __gmon_start__
         w __register_frame_info@@GLIBC_2.0
0000086c t __stat
         U __xstat@@GLIBC_2.0
00001a58 A _edata
00001ad8 A _end
00000908 T _fini
00000694 T _init
         U atexit
00000700 t call_gmon_start
00001948 d completed.4
         U exit@@GLIBC_2.0
0000079c t fini_dummy
0000194c d force_to_data
0000194c d force_to_data
000007b8 t frame_dummy
00000730 t gcc2_compiled.
000008a0 t gcc2_compiled.
00000810 t gcc2_compiled.
000007f4 t init_dummy
000008dc t init_dummy
00001a60 b object.11
00001944 d p.3
         U printf@@GLIBC_2.0
00000810 T qprk
0000086c t stat
00001a80 B subuf 

위의 코드는 정상적입니다. 바로 윘줄보면 stat 가 t 로 잘 붙어 있습니다.
하지만 위의 코드는 test를 위한 코드이구요

다른 프로그램에서 *.so를 만든다음 실행해보면 stat 심볼이 없다고 나옵니다.
(undefined symbol: stat)
아래와 같이..

nm aaa.so | grep stat
0001545d T readstatistics
         U stat

위의 두 코드 모두 동일한 머신에서 컴파일 한것입니다.

혹시 이런 경우는 어떻게 접근해야 하는지요?

pynoos의 이미지

"t"는 외부링크에는 사용할 수 없는 심볼입니다.

소스에서 static을 빼시면 "T"가 되고 외부 링크가 되지요.

qprk의 이미지

pynoos wrote:
"t"는 외부링크에는 사용할 수 없는 심볼입니다.

소스에서 static을 빼시면 "T"가 되고 외부 링크가 되지요.

제가 설명이 부족한것 같습니다.

stat 함수는 file의 상태를 알아오는 함수죠..
그리고 이 함수는 외부에서 사용할 필요도 없는 것이구요..

하지만 문제점은 두번째 프로그램에서 .so 파일을 만들고
해당 라이브러리를 다른 프로그램에서 링크하여 사용합니다.

더 이상한점은
솔라리스, hp aix 에서 컴파일 하면 잘 동작한다는 것입니다.
또한 리눅스에서도 redhat 9 말고 7이나 다른 버전에서는 잘 동작 하는것이지요..

또한 컴파일 에러도 없구요...

유독 redhat 9에서만 링크에러가 발생합니다.

리눅스에서 컴파일러 버전도 동일한 상태니 더더욱 이상하고 난감하내요..

멋진남자...

pynoos의 이미지

linux c library 에서 stat 함수 관련해서 약간의 주의할 점이 있습니다.

http://bbs.kldp.org/viewtopic.php?p=98376#98376

위에서는 C++ 과 같이 사용하다가 생겼던 점인데, 비슷한 맥락인것 같습니다.

/usr/include/sys/stat.h 파일을 열어서 디버깅 해보시고, 좀더 자세한 에러메시지를 올려주세요.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.