solaris에서 shm_open compile 에러..

psjcap의 이미지

solaris에서 CC 컴파일러를 사용하고 있는데요..

shm_open 함수 사용시..
함수를 찾을 수 없다는 에러가 계속 나오더군요..

그래서 -D_POSIX_C_SOURCE=4 를 Makefile에 추가했더니..
shm_open 함수 부분은 컴파일이 되는데..
gettimeofday에서 사용하기 위한 timeval 구조체에서 아래처럼 모두 에러가 나네요..ㅡㅡ;

The type "timeval" is incomplete.

혹시 동일한 경험 있으신 분..
이거 어떻게 해야 하나여.?

IsExist의 이미지

링커 옵션을 제대로줬나요?

shm_open 경우 man 해보면 나오지만 -lrt 해야 합니다.

---------
간디가 말한 우리를 파괴시키는 7가지 요소

첫째, 노동 없는 부(富)/둘째, 양심 없는 쾌락
셋째, 인격 없는 지! 식/넷째, 윤리 없는 비지니스

이익추구를 위해서라면..

다섯째, 인성(人性)없는 과학
여섯째, 희생 없는 종교/일곱째, 신념 없는 정치

psjcap의 이미지

-lrt는 물론 달았구요..
링크 에러가 아니라.. 컴파일 에러입니다..

그래서 header 파일을 뒤져 보았더니..
다음과 같이 되어 있네요..ㅡㅡ;

#if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \
    defined(__EXTENSIONS__) || defined(_XPG4_2)
#ifndef _ASM

#if !defined(_TIME_T) || __cplusplus >= 199711L
#define _TIME_T
typedef long    time_t;     /* time of day in seconds */
#endif  /* _TIME_T */

#ifndef _SUSECONDS_T
#define _SUSECONDS_T
typedef long    suseconds_t;    /* signed # of microseconds */
#endif  /* _SUSECONDS_T */

struct timeval {
    time_t      tv_sec;     /* seconds */
    suseconds_t tv_usec;    /* and microseconds */
};
..............

즉 _POSIX_C_SOURCE가 define 되어있으면..
timeval을 못 쓴다는건데..ㅡㅡ;

timeval을 위에다 살짝 정의해 놓아봤지만..
위와 같은 이유로 다른 부분에서 에러가 또 나네요..

최종호의 이미지

% man 5 standards
를 수행해 보시면 각 스펙별 feature test macro 를 보실 수 있을 것입니다.

Quote:
Specification Compiler/Flags Feature Test Macros
ANSI/ISO C c89 none
SVID3 cc -Xt none
POSIX.1-1990 c89 _POSIX_SOURCE
POSIX.1-1990 and c89 _POSIX_SOURCE and
POSIX.2-1992 POSIX_C_SOURCE=2
C-Language
Bindings Option
POSIX.1b-1993 c89 _POSIX_C_SOURCE=199309L
POSIX.1c-1996 c89 _POSIX_C_SOURCE=199506L
CAE XPG3 cc -Xa _XOPEN_SOURCE
CAE XPG4 c89 _XOPEN_SOURCE and
_XOPEN_VERSION=4
SUS (CAE XPG4v2) c89 _XOPEN_SOURCE and
(includes XNS4) _XOPEN_SOURCE_EXTENDED=1
SUSv2(includes XNS5) c89 _XOPEN_SOURCE=500

struct timeval 은 sys/time.h 에 정의되어 있으며 XPG4v2 에서 소개되었습니다.

http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/time.h.html

_POSIX_C_SOURCE=4

라는 것은 따로 정의되어 있지 않고

_POSIX_C_SOURCE=2 와 _POSIX_C_SOURCE=199309L
사이에 걸리지 않을까 생각이 됩니다. 이 경우에는
POSIX.1b-1993
에 해당되겠네요.

이 버젼의 POSIX 에서는 timeval 이 지원이 되지 않습니다.

(아마 제 생각에는 Posix.1 2001인 _POSIX_C_SOURCE=200112L 에서야
되지 않을까 생각이 됩니다.)

앞서 말씀드린 대로 해당 시점에서는 Posix와 XPG가 서로 다른 스펙으로

존재했기 때문에 XPG4v2 이상을 쓴다는 것을 나타내기 위한 지시를 해 주셔야 하는데,

앞의 인용에 보시듯이
-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED=1
을 지정하시거나
-D_XOPEN_SOURCE=500
을 지정하시면 될 것입니다.

또는 -D_EXTENSIONS 를 사용하셔도 되고요.

이후 Single Unix Spec v.3 에서는 Posix와 통합되었으므로

-D_POSIX_C_SOURCE=200112L

을 지정하시면 문제없이 컴파일이 될 것으로 생각됩니다.

psjcap의 이미지

답변 주셔서 감사합니다..^^
저런 내용이 있는 줄은 몰랐군요..

하지만.. 역시 컴파일은 않 되고 있습니다..ㅡㅡ;
헤더 파일에 메크로를 자세히 들여다 보니..

#if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \ 
    defined(__EXTENSIONS__) || defined(_XPG4_2) 

이 부분에서..
_POSIX_C_SOURCE 와 _XOPEN_SOURCE 는 define이 되면 않 되고..
__EXTENSIONS__ 나 _XPG4_2 중에 하나가 define 되어 있어야지 되겠네요..

기존 소스에 select나 gettimeofday를 많이 사용하였기 때문에..
timeval은 꼭 필요해서..
shm_open을 shmget으로 변경하였습니다..ㅜㅜ;

하지만 많은 도움이 되었습니다..
감사합니다..^^"

최종호의 이미지

psjcap wrote:
답변 주셔서 감사합니다..^^
저런 내용이 있는 줄은 몰랐군요..

하지만.. 역시 컴파일은 않 되고 있습니다..ㅡㅡ;
헤더 파일에 메크로를 자세히 들여다 보니..

#if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \ 
    defined(__EXTENSIONS__) || defined(_XPG4_2) 

이 부분에서..
_POSIX_C_SOURCE 와 _XOPEN_SOURCE 는 define이 되면 않 되고..
__EXTENSIONS__ 나 _XPG4_2 중에 하나가 define 되어 있어야지 되겠네요..

조건부 컴파일문을 해석하면
1. _POSIX_C_SOURCE 와 _XOPEN_SOURCE 가 모두 정의안되어 있거나
2. __EXTENSIONS__ 가 정의되어 있거나
3. _XPG4_2가 정의되어 있는 경우

이기 때문에 2번이나 3번을 만족한다면
_POSIX_C_SOURCE와 _XOPEN_SOURCE 를 정의해도 전혀 문제가 안됩니다.

__EXTENSIONS__ 나 _XPG4_2 는 직접 정의하셔도 되겠지만,
다른 정의에 의해서 유도되기도 합니다.

Solaris 7의 /usr/include/sys/feature_tests.h 를 보시면

/*
 * UNIX 95 implementation
 *
 * As specified in the following X/Open specifications:
 *
 *   System Interfaces and Headers, Issue 4, Version 2
 *   Commands and Utilities, Issue 4, Version 2
 *   Networking Services, Issue 4
 *   X/Open Curses, Issue 4
 *
 * application writers wishing to use any functions specified
 * as X/Open UNIX Extension must define _XOPEN_SOURCE and
 * _XOPEN_SOURCE_EXTENDED=1.  The Sun internal macro _XPG4_2
 * should not be used in its place as unexpected results may
 * occur.
 */
#if (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1)
#define _XPG4_2
#endif

/*
 * UNIX 98 implementation
 *
 * As specified in the following X/Open specfications:
 *
 *   System Interfaces and Headers, Issue 5
 *   Commands and Utilities, Issue 5
 *   Networking Services, Issue 5
 *   X/Open Curses, Issue 4, Version 2
 *
 * application writers wishing to utilize UNIX 98 functionality
 * must define _XOPEN_SOURCE=500.  This turns on UNIX 95 functionality
 * which is a subset of UNIX 98, and also turns on POSIX Realtime and
 * POSIX Threads functionality.
 */
#if (_XOPEN_SOURCE - 0 == 500)
#define _XPG5
#define _XPG4_2
#undef  _POSIX_C_SOURCE
#define _POSIX_C_SOURCE                 199506L
#define _POSIX_PTHREAD_SEMANTICS        1
#endif

와 같이 되어있어서 _XOPEN_SOURCE 가 500 이거나
_XOPEN_SOURCE_EXTENDED=1인 경우에는 _XPG4_2 가
정의되도록 되어있습니다.

Solaris 7과 8에서 아래 코드와 컴파일 옵션은 아무런 오류없이 컴파일되었습니다.

#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>

int
main(int argc, char **argv)
{
        struct timeval  tv;

        shm_open(NULL, 0, 0);
}

#!/bin/sh -v

cc -D_POSIX_C_SOURCE=199506L -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED timeval_compile_error.c -lrt
cc -D__EXTENSIONS__ timeval_compile_error.c -lrt
cc -D_POSIX_C_SOURCE=199506L -D_XOPEN_SOURCE=500 timeval_compile_error.c -lrt
cc -D_POSIX_C_SOURCE=199506L -D_XOPEN_SOURCE=500 timeval_compile_error.c -lrt

댓글 달기

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