"undefined reference to" error is driving me crazy [message #807426] |
Sun, 26 February 2012 12:45 |
Alternate Ego Messages: 2 Registered: February 2012 |
Junior Member |
|
|
Hi, This is my first post on the forum so please show mercy. I did Googled this error but could'nt find a definite answer.
I've just installed Eclipse CDT on my Ubuntu machine and tried compiling a sample program - just to check the installation.
#include <stdlib.h>
#include <stdio.h>
#define MAXLEN 21 /* A SMALL NUMBER FOR TESTING */
int gettline(char s[]);
void escape(char s[], char t[]);
void unescape(char t[], char s[]);
int error;
enum boolean {NO, YES};
enum escapes {BELL = '\a', BACKSPACE = '\b', TAB = '\t',
NEWLINE = '\n', VTAB = '\v', RETURN = '\r'};
int main(void) {
{
int len;
char in_str[MAXLEN], out_str[2 * MAXLEN - 1], undo_str[MAXLEN];
error = NO;
/* LOAD THE IN STRING FROM THE INPUT LINE */
len = gettline(in_str);
if (len == 0)
printf("STRING IS MISSING\n");
else {
printf("\nTHE CONVERTED STRING:\n");
escape(out_str, in_str);
printf("%s",out_str);
printf("\nTHE UNCONVERTED STRING:\n");
unescape(undo_str, out_str);
printf("%s",undo_str);
}
printf("\nEND OF PROGRAM\n");
return 0;
}
/* GETLINE: LOAD A LINE OF INPUT */
int gettline(char s[])
{
int i, c;
for (i = 0; i < MAXLEN - 1 && (c = getchar()) != NEWLINE && c != EOF; ++i)
s[i] = c;
if (i >= MAXLEN - 1)
printf("\nSTRING IS TOO LONG - OVER %d CHARACTERS\n", i);
if (c == NEWLINE)
s[i++] = c;
s[i] = '\0';
return i;
}
/* ESCAPE: CONVERT CHARS LIKE NEWLINE AND TAB INTO VISIBLE ESCAPE */
/* SEQUENCES LIKE \n AND \t WHILE COPYING STRING t TO s. */
void escape(char s[], char t[])
{
int i, j;
for (i = j = 0; t[i] != '\0'; ++i)
switch(t[i]) {
case BELL:
s[j++] = '\\';
s[j++] = 'a';
break;
case BACKSPACE:
s[j++] = '\\';
s[j++] = 'b';
break;
case TAB:
s[j++] = '\\';
s[j++] = 't';
break;
case NEWLINE:
s[j++] = '\\';
s[j++] = 'n';
break;
case VTAB:
s[j++] = '\\';
s[j++] = 'v';
break;
case RETURN:
s[j++] = '\\';
s[j++] = 'r';
break;
default:
s[j++] = t[i];
break;
}
s[j] = '\0';
}
/* UNESCAPE: CONVERT EMBEDDED SEQS TO THEIR CORRESPONDING CHARS. */
void unescape(char t[], char s[])
{
int i, j;
for (i = j = 0; s[i] != '\0'; ++i)
if (s[i] == '\\')
switch(s[i + 1]) {
case 'a':
t[j++] = BELL;
++i;
break;
case 'b':
t[j++] = BACKSPACE;
++i;
break;
case 't':
t[j++] = TAB;
++i;
break;
case 'n':
t[j++] = NEWLINE;
++i;
break;
case 'v':
t[j++] = VTAB;
++i;
break;
case 'r':
t[j++] = RETURN;
++i;
break;
default:
t[j++] = s[i];
break;
}
else
t[j++] = s[i];
t[j] = '\0';
}
}
while compiling I am getting this error (probably from linker).
Quote:escapefunction.c:(.text+0x29): undefined reference to `gettline'
escapefunction.c:(.text+0x5b): undefined reference to `escape'
escapefunction.c:(.text+0x91): undefined reference to `unescape'
I read on some sites that correct way of compiling is this:
Quote:gcc -Wall escapefunction.c -o dynamically_linked -L. -lmean
I tried that but could'nt succedd. Moreover I want to do the compiling within the IDE itself. I don't face any such issues on XP installation of Eclipse. Kindly guide.
[Updated on: Sun, 26 February 2012 12:45] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04267 seconds