Solaris cc to a Linux gcc 컴파일 오류

helloong의 이미지

안녕하세요? 궁금한게 있어서 질문 드립니다.
기존 SPARC Solaris 환경에서 컴파일하여 사용하던
오래된 c소스를 x86 64bit linux 머신의 gcc 환경으로 변경 컴파일 하려고 합니다.

Linux 머신에서 아래와 같이 gcc를 사용하여 컴파일 하려고 하면 struct in_addr 부분에서
에러가 나는것 같은데 어떤 에러인지 아시는분 계실까요?

# gcc -g -m64 -D_REENTRANT -D_SOL10 -I./ -I/usr/include -I/usr/local/include -g -m64 -L/usr/lib -lrt -lnsl -lsocket -lpthread -o watchdog watchdog.c logger.c unisock.c conf.c common.c unicrypt.c aes.c seed.c base64.c

In file included from common.h:12,
from watchdog.c:13:
unisock.h:15: warning: ‘struct in_addr’ declared inside parameter list
unisock.h:18: warning: ‘struct in_addr’ declared inside parameter list
unisock.h:22: warning: ‘struct in_addr’ declared inside parameter list
In file included from watchdog.c:15:
unisock.h:15: warning: ‘struct in_addr’ declared inside parameter list
unisock.h:15: error: conflicting types for ‘PsSocketBind’
unisock.h:15: note: previous declaration of ‘PsSocketBind’ was here
unisock.h:18: warning: ‘struct in_addr’ declared inside parameter list
unisock.h:18: error: conflicting types for ‘PsSocketConnect’
unisock.h:18: note: previous declaration of ‘PsSocketConnect’ was here
unisock.h:22: warning: ‘struct in_addr’ declared inside parameter list
unisock.h:22: error: conflicting types for ‘PsSocketAccept’
unisock.h:22: note: previous declaration of ‘PsSocketAccept’ was here
watchdog.c: In function ‘main’:
watchdog.c:138: warning: cast to pointer from integer of different size
In file included from unicrypt.c:19:
seed.h:43:1: warning: "LITTLE_ENDIAN" redefined
In file included from /usr/include/bits/waitstatus.h:65,
from /usr/include/stdlib.h:43,
from seed.h:13,
from unicrypt.c:19:
/usr/include/endian.h:46:1: warning: this is the location of the previous definition
In file included from seed.c:12:
seed.h:43:1: warning: "LITTLE_ENDIAN" redefined
In file included from /usr/include/bits/waitstatus.h:65,
from /usr/include/stdlib.h:43,
from seed.h:13,
from seed.c:12:
/usr/include/endian.h:46:1: warning: this is the location of the previous definition

unisock.h 파일은 아래와 같이 정의 되어 있습니다.
또한 혹시 몰라 프로젝트 파일의 최소 내용[민감 정보 제외 또는 대체]을 압축하여 첨부합니다.
아시는 분이 계시면 도움 부탁드립니다. 감사합니다.

#define _BSD 44
 
int PsSocketCreate(int *sockfd);
int PsSocketClose(int *sockfd);
int PsSocketBind(int sockfd, unsigned short* Port, struct in_addr *Address);
int PsSocketBindByName(int sockfd, unsigned short *Port, char *LocalName);
int PsSocketBindByIP(int sockfd, unsigned short *Port, char *LocalIP);
int PsSocketConnect(int sockfd, struct in_addr *Address, unsigned short Port);
int PsSocketConnectByName(int sockfd, char *RemoteName, unsigned short Port);
int PsSocketConnectByIP(int sockfd, char *RemoteIP, unsigned short Port);
int PsSocketListen(int sockfd, int nBackLog);
int PsSocketAccept(int svrsock, int *clisock, unsigned short *Port, struct in_addr *Address);
int PsSocketAcceptByName(int svrsock, int *clisock, unsigned short *Port, char *RemoteName);
int PsSocketSend(int sockfd, char *Buf, int BufLen);
int PsSocketReceiveN(int sockfd, char *Buf, int *BufLen, int Time);
void PsSocketClear(int *sockfd, int nCurLen, char *szTotLen);

File attachments: 
첨부파일 크기
Package icon 프로젝트 제한적 소스 압축본41.6 KB
ymir의 이미지

watchdog.c 입장에서 struct in_addr 이 선언되어 있는 곳을 알 수 없기 때문에 발생한 에러입니다.
strct in_addr 이 netinet/in.h 에 있을 텐데, 특정 자료형이 사용된 경우에는 해당 헤더에서 include 해주는게 의존 관계를 명확히 파악할 수 있어서 좋습니다.
안 그러면 unisock.h 를 사용하는 모든 소스 마다, unisock.h 를 include 하기 전에 반드시 netinet/in.h 를 먼저 include 해 줘야 하는데, 하나라도 빠트리면 지금같은 문제가 발생하는거죠.

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

helloong의 이미지

먼저 답변 주셔서 감사합니다.
그런데 답변주신 내용은 어렴풋이 이해 하겠는데 궁금한게 있습니다.

그럼 솔라리스상에서 컴파일 할때는 말씀주신 헤더를 굳이 선언하지 않아도 동일 소스로
에러 없이 컴파일이 되었는데 이는 gcc와 sun sutdio cc 컴파일러 상의 차이점 일까요?

단순히 첨부된 소스 중 seed.h 부분의 엔디안[현재 리눅스로에서 컴파일 해보려고 LITTLE로 바꾸어 놓은 상태]만 변경하면 무리없이 make로 컴파일이 되어서 궁금해서 여쭤봅니다.

ymir의 이미지

컴파일러는 어차피 표준에 의존적이라 어느 표준/확장을 지원하는지를 제외하면 큰 차이는 없을 겁니다. 아마도 사용하는 libc 라이브러리의 헤더 구조에 따라 조금씩 차이가 있을 것 같네요. 물론 링크해야 하는 라이브러리도 다릅니다. (linux 에서는 socket 함수를 사용하기 위해 -lsocket -lnsl 을 명시할 필요 없습니다.)

자세한 것은 libc 매뉴얼이나, 주요 함수들의 man page 를 확인해 보시면 될 것 같습니다.
https://www.gnu.org/software/libc/manual/html_mono/libc.html

추가로.. gcc 에서 pthread 와 같은 경우는 -pthread 와 -lpthread 의 역할이 조금 다릅니다. 별다른 이유가 있는게 아니라면 -pthread 옵션을 쓰는게 나을 겁니다.

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

댓글 달기

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