Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » "undefined reference to" error is driving me crazy
icon9.gif  "undefined reference to" error is driving me crazy [message #807426] Sun, 26 February 2012 12:45 Go to next message
Alternate Ego is currently offline Alternate EgoFriend
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

Re: "undefined reference to" error is driving me crazy [message #807475 is a reply to message #807426] Sun, 26 February 2012 14:37 Go to previous messageGo to next message
Klaus km is currently offline Klaus kmFriend
Messages: 142
Registered: November 2011
Senior Member
Hello,

this is not an Eclipse/CDT problem. The C code is simply wrong.
Remove the curly bracket from the end of this line
int main(void) {
and from the last line of the file.


Regards,
Klaus


Re: "undefined reference to" error is driving me crazy [message #807507 is a reply to message #807475] Sun, 26 February 2012 15:50 Go to previous message
Alternate Ego is currently offline Alternate EgoFriend
Messages: 2
Registered: February 2012
Junior Member
Thanks & that is pretty embarrassing. Embarrassed
Previous Topic:Eclipse/Indigo with CDT under openSUSE 12.1
Next Topic:eclipse IDE can't understand posix-style paths
Goto Forum:
  


Current Time: Wed Apr 24 16:43:26 GMT 2024

Powered by FUDForum. Page generated in 0.03026 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top