[해결 됨--> 타이핑에러였슴.] gcc link 에러입니다.어떤것을

initiative의 이미지

개발 환경은 -->
linux 2.6 X (한컴 베타2)
gcc :3.3.2
코드는 c코드입니다.

아래 코드를 BoA 주세요.

/*
* reverse.c
* 아큐먼트를 거꾸로 바꿔준다.
*/

#include <sys/file.h>
#include <stdio.h>
#include <stdlib.h>

/* emulator */
enum { FALSE, TRUE}; /* 표준 참,거짓 */
enum { STDIN, STDOUT, STDERR }; /* 표준 입출력 채널 색인 */

// define
#define BUFFER_SIZE 4096
#define NAME_SIZE 10
#define MAX_LINES 100000 /* 화일의 최대 줄 수 */

/* 전역 변수들 */
char *fileName = NULL; /* file 이름에 대한 포인터 */
char tmpName[NAME_SIZE];
int charOption = FALSE; /* -c 옵션이 사용되면 참으로 설정 */
int standardInput = FALSE; /* stdin 을 읽으면 참으로 설정 */
int lineCount = 0; /* 입력 줄의 합 */
int lineStart[MAX_LINES]; /* 각 줄의 옵셋 저장 */
int fileOffset = 0; /* 입력의 현재 위치 */
int fd; /* 입력의 화일 기술자 */

/* declaration */
void processOptions(char* str);
void parseCommandLine(int argc, char* argv[]);
void usageError();
void pass1();
void trackLines(char* buffer, int charsRead);
int pass2();
void processLine(int i);
void reverseLine(char* buffer, int size);
void fatalError();

/***********************************************************************/
int main(int argc, char* argv[])
{
parseCommandLine(argc, argv);

pass1(); /* 첫번째 패스 수행 */
pass2(); /* 두번째 패스 수행 */

return 0; /* 완료 */

}

/*
* 명령줄 파라미터 분석
*/
void parseCommandLine(int argc, char* argv[])
{
int i;

for(i =1; i< argc; i++)
{
if(argv[i][0]=='-')
prosessOptions(argv[i]);
else if(fileName ==NULL)
fileName =argv[i];
else
usageError(); /* 에러 발생 */
}

standardInput = (fileName == NULL);
}

/*
* 옵션 분석
*/
void processOptions(char* str)
{
int j;

for(j= 1; str[j]!=NULL; j++) <-- 여기서 에라.
{
switch(str[j]) /* 명령줄 플래그값에 따른 전환 */
{
case 'c':
charOption = TRUE;
break;
default:
usageError();
break;
}
}
}

void usageError()
{
fprintf(stderr, "Usage: reverse -c [filename]\n");
exit(1); /* 실패 */

}

/*
* 첫번째 파일의 스캔 실행
*/
void pass1()
{
int tmpfd, charsRead, charsWritten;
char buffer[BUFFER_SIZE];

if(standardInput) /* 표준 입력에서 읽기 */
{
fd = STDIN;
sprintf(tmpName, ".rev.%d", getpid()); // 임의의 이름

/* 입력의 복사를 저장할 임시 화일 생성 */
tmpfd = open(tmpName, O_CREAT| O_RDWR, 0600);
if(tmpfd == -1) fatalError();
}
else
{
// 읽기 위해 명명된 파일 읽기
fd = open(fileName, O_RDONLY);
if(fd == -1) fatalError();
}

lineStart[0] = 0; // 첫 줄의 offset

while(TRUE)
{
charsRead = read(fd, buffer, BUFFER_SIZE);
if(charsRead == 0) break; /* 화일 끝 */
if(charsRead == -1) fatalError();
trackLines(buffer, charsRead); // 프로세스 줄

/*
* 표준 입력 읽기이면 임시 화일로 줄 복사
*/
if(standardInput)
{
charsWritten = write(tmpfd, buffer, charsRead);
if(charsWritten != charsRead) fatalError();
}

}
/* 존재하면 뒷줄의 옵셋 저장 */
lineStart[lineCount+1] = fileOffset;

/* 표준 입력에서 읽기면 pass2 를 위해 fd 준비 */
if(standardInput) fd = tmpfd;
}

/*
* 각 줄 시작의 옵셋을 버퍼에 저장
*/
void trackLines(char* buffer, int charsRead)
{
int i;
for(i=0; i< charsRead; i++)
{
++fileOffset; // 현재 파일 위치 생성
if(buffer[i] == '\n') lineStart[++lineCount] = fileOffset;

}
}

/*
* 입력 파일을 다시 스캔하여 역순서로 줄들을 표시
*/
int pass2()
{
int i;
for(i= lineCount -1 ; i>=0; i--)
{
processLine(i);
}
close(fd);
if(standardInput) unlink(tmpName); /* 임시 파일 제거 */
}

/* 한 줄 읽고 표시 */
void processLine(int i)
{
int charsRead;
char buffer[BUFFER_SIZE];

lseek(fd, lineStart[i], L_SET); /* 줄을 찾아 읽기 */
charsRead = read(fd, buffer, lineStart[i+1] - lineStart[i]);

/* -c 옵션 사용되면, 선택된 줄 안의 글자순서 바꾸기 */
if(charOption) reverseLine(buffer, charsRead);
write(1,buffer, charsRead);
}

/* 버퍼에 있는 모든 문자의 순서를 역으로 */
void reverseLine(char* buffer, int size)
{
int start =0, end = size -1;
char tmp;

if(buffer[end]=='\n') --end; /* 뒤의 새 줄은 남긴다.*/
while(start < end)
{
tmp = buffer[start];
buffer[start] = buffer[end];
buffer[end] = tmp;
++start; /* 시작 인덱스 증가 */
--end;
}
}

void fatalError()
{
perror("reverse: "); /* 에러 설명 */
exit(1);
}

예를 컴팔하면
[jin@XXXSERVER c_ex]$ gcc reverse.c -o reverse
reverse.c: In function `processOptions':
reverse.c:82: warning: comparison between pointer and integer
/tmp/ccj3dGzn.o(.text+0x72): In function `parseCommandLine':
: undefined reference to `prosessOptions'
collect2: ld returned 1 exit status

이렇게 에라가 나거든요?
뒤에 gcc reverse.c -o reverse -l(라이브러리 링크) 를 해주면 될 거 같은데..
어떤 것을 링크해주어야 하는지 도통 모르겠어요.

내가 필요한 라이브러리(/usr/lib/에 있는 애들 중)가 몬지 알수 있는 방법도 궁금합니다.

그럼~

맹고이의 이미지

void processOptions(char* str);

으로 선언하고

prosessOptions(argv[i]);

으로 사용하였습니다.

initiative의 이미지

허걱...

할 말이 없네요.
감사합니다!

전 엄한 데 문제가 있는 줄 알고 link 에라쪽 막 찾았는 데..

살아있는 게시판이군요 역시!

With Everlasting Passion about new Tech. and Information!

댓글 달기

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