LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   problem regarding executing c program in ubuntu (https://www.linuxquestions.org/questions/linux-newbie-8/problem-regarding-executing-c-program-in-ubuntu-836359/)

gerry_bertier 10-05-2010 12:52 PM

problem regarding executing c program in ubuntu
 
Hi,

i am a newbie in linux.
i have a c program which runs on linux....so i installed ubuntu 10.04 version on my system.

i tried to compile this program 'mygen.c' (using gcc -o mygen.c) but i was given some errors -

mygen.c:(.text+0x4fe): undefined reference to `exp'
mygen.c:(.text+0x569): undefined reference to `sqrt'
mygen.c:(.text+0x57a): undefined reference to `log'
mygen.c:(.text+0x5b9): undefined reference to `tan'
mygen.c:(.text+0x5e9): undefined reference to `floor'
mygen.c:(.text+0x631): undefined reference to `exp'
collect2: ld returned 1 exit status

i thought that maybe 'math.h' is missing.
so, i checked the folder /usr/include and it do contains the file 'math.h'.
but this math.h do not have anything related to 'exp','sqrt' or some other math functions.

i downloaded a new header file 'math.h' from internet.
i tried to save it in the folder /usr/include but i could not.
i don't have the permission to paste the header file in /usr/include.
i am the administrator then why don't i have the required permission to paste that file ?
i tried with the commands to change the permission for this folder...but met no success.

i would be more than happy if u could sort out my problem.

thanx in advace.

GrapefruiTgirl 10-05-2010 01:01 PM

I believe the header file you're looking for is tgmath.h and that it *might* not be on your Ubuntu machine by default. You need to install at least one additional package of stuff, before you can compile. The following command should help:
Code:

sudo apt-get install build-essential
EDIT On second look, I may have spoken before reading thoroughly; disregard this and try the next post first.

Tinkster 10-05-2010 01:01 PM

hi, welcome to LQ!

That's a linker problem, not a compiler one. Just bind
the math library to your executable.

Code:

-lm
Cheers,
Tink

GrapefruiTgirl 10-05-2010 01:07 PM

Thanks Tink :) - So are the headers are all there by default on Ubuntu? I thought they were not included?

Tinkster 10-05-2010 01:59 PM

Quote:

Originally Posted by GrapefruiTgirl (Post 4118550)
Thanks Tink :) - So are the headers are all there by default on Ubuntu? I thought they were not included?

Don't know about Ubunut and its defaults - but if it were
a header problem he'd see compiler errors, not linker ones.
"Undefined reference" is clearly a linker error.



Cheers,
Tink

GrapefruiTgirl 10-05-2010 02:14 PM

Yes, OP's post is similar to an earlier post and I wasn't paying attention when I read it. I'm going back to sleep now. :o

gerry_bertier 10-15-2010 07:44 AM

thank you everyone....
my problem is solved....:)


All times are GMT -5. The time now is 02:03 AM.