Main.c:(.text+0x55): undefined reference to


 
Thread Tools Search this Thread
Top Forums Programming Main.c:(.text+0x55): undefined reference to
# 1  
Old 10-01-2013
Main.c:(.text+0x55): undefined reference to

I'm getting this error. I'm guessing either there is an error in my code or I am missing a library. Can I please have some ideas on what the problem is?

Code:
main.c:(.text+0x55): undefined reference to

Code:
$ gcc *.c
/tmp/ccP8MDTO.o: In function `getInput':
main.c:(.text+0x55): undefined reference to `validateInput'
main.c:(.text+0xb2): undefined reference to `validateInput'
main.c:(.text+0x10f): undefined reference to `validateInput'
collect2: ld returned 1 exit status

Code:
bool getInput (int* pFahrenheit, int* pFeet, int* pPounds)
{
    bool isValid=false;
    //Prompt for Temperature
    int count=scanf("%d",pFahrenheit);
    if(count==1)
    {
        if (validateInput(*pFahrenheit,0,212))
        {
            isValid=true;
        }
    }
}

# 2  
Old 10-01-2013
Quote:
Originally Posted by cokedude
I'm getting this error. I'm guessing either there is an error in my code or I am missing a library. Can I please have some ideas on what the problem is?

Code:
main.c:(.text+0x55): undefined reference to

Code:
$ gcc *.c
/tmp/ccP8MDTO.o: In function `getInput':
main.c:(.text+0x55): undefined reference to `validateInput'
main.c:(.text+0xb2): undefined reference to `validateInput'
main.c:(.text+0x10f): undefined reference to `validateInput'
collect2: ld returned 1 exit status

Code:
bool getInput (int* pFahrenheit, int* pFeet, int* pPounds)
{
    bool isValid=false;
    //Prompt for Temperature
    int count=scanf("%d",pFahrenheit);
    if(count==1)
    {
        if (validateInput(*pFahrenheit,0,212))
        {
            isValid=true;
        }
    }
    return(isValid);
}

Most importantly, the diagnostics you're getting say that you have at least three calls to a function named validateInput() that is not defined in your source file and is not included in any of the libraries you're linking. One of those calls is in the function you included above. Where is the function validateInput() defined?

Once you fix that, note that you have declared that your getInput() function returns an object of type bool, but the code doesn't return any value. I assume that you want to add a line of code similar to the line in red I added above.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 10-06-2013
Quote:
Originally Posted by Don Cragun
Most importantly, the diagnostics you're getting say that you have at least three calls to a function named validateInput() that is not defined in your source file and is not included in any of the libraries you're linking. One of those calls is in the function you included above. Where is the function validateInput() defined?

Once you fix that, note that you have declared that your getInput() function returns an object of type bool, but the code doesn't return any value. I assume that you want to add a line of code similar to the line in red I added above.
Thank you. validateInput() is not defined anywhere.

Yes your right I need to return that.

Is the bool getInput declaration ok? It took me awhile to figure out a way to use it and the compiler not give me an error. I wasn't able to find very much c programming documentation on a bool function. I eventually did this since I saw it recommended several times when I googled it.

Code:
#define bool int
#define true 1
#define false 0

[SOLVED] Boolean variables in C
# 4  
Old 10-06-2013
Quote:
Originally Posted by cokedude
Thank you. validateInput() is not defined anywhere.

Yes your right I need to return that.

Is the bool getInput declaration ok? It took me awhile to figure out a way to use it and the compiler not give me an error. I wasn't able to find very much c programming documentation on a bool function. I eventually did this since I saw it recommended several times when I googled it.

Code:
#define bool int
#define true 1
#define false 0

[SOLVED] Boolean variables in C
If you have a C programming environment that conforms to the 1999 C standard, you should include the stdbool header:
Code:
#include <stdbool.h>

before using bool, true, and false in your program. If you include that header, bool is defined to be an appropriate type and true and false will be defined appropriately for your programming environment. If your compiler provides stdbool.h, you should not use #defines to define bool, false, and true; you should use #include <stdbool.h> instead.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

undefined reference help

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The problem is a function which i typed although it kept saying that it is a undefined reference still. other... (1 Reply)
Discussion started by: mgyeah
1 Replies

2. Homework & Coursework Questions

undefined reference help

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: i know when undefined reference shows up the program is saying it is not link to that function but the problem... (1 Reply)
Discussion started by: mgyeah
1 Replies

3. Programming

undefined reference to `pthread_create'

Hi guys. H was learning posix threads in C with anjuta IDE. it gives me undefined reference to `pthread_create' I know i should compile it like: gcc -lpthread main.c how should i import this configuration in anjuta so i can compile inside it? (2 Replies)
Discussion started by: majid.merkava
2 Replies

4. Programming

undefined reference to pthread_create

I try to compile a sample c code in fedora eclipse 3.2 as managed makefile using pthread library,it shows some error on pthread functions.Error is of undefined reference to pthread.Anybody guide me to solve this problem. Thanking you (1 Reply)
Discussion started by: sujith4u87
1 Replies

5. Programming

undefined reference to 'function'

Hi, i want to compile a code where fortran calls c . First I compiled C module ,it has pass by gcc. However, after generating .o file. I compiled C and fortran files together by intel fortran and it failed " undefined reference to 'vicerror'". vicerror is a function. I do not know why. (1 Reply)
Discussion started by: austinhsu
1 Replies

6. Programming

undefined reference to `__ctype_b'

when i compile my program, i meet the following error: ... undefined reference to `__ctype_b' ... anybody knows which shared library should be linked during make? thanks a lot! (6 Replies)
Discussion started by: princelinux
6 Replies

7. Programming

undefined reference to `pthread_create'

Hi I wanted to learn communication between threads and I used a simple example but I faced with this error while I have a sofware that uses this functions without any problem so would you please help me to know the reason thanks for your help and great favor. #include <pthread.h>... (2 Replies)
Discussion started by: netman
2 Replies

8. Programming

about undefined reference for 'sinf'

I m writting code in c using another library(parapin) and making Makefile .but there is a error like undefined reference to `sinf' undefined reference to `ceilf' although i have added math.h library in my code . I tried to run simple programme using math.h and it run.but in making Makefile it... (2 Replies)
Discussion started by: bharat suthar
2 Replies

9. Programming

Undefined reference to Error

Hello, plz help me out with this error, i am getting this error when i compile my code with gcc. /usr/lib/gcc-lib/i386-redhat-linux/3.3.2/../../../crt1.o(.text+0x18): In function `_start': : undefined reference to `main' /tmp/cciLxqdV.o(.text+0x3c): In function `HandleUserTransaction()':... (2 Replies)
Discussion started by: svh
2 Replies
Login or Register to Ask a Question