Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 07-22-2011, 07:31 PM   #1
LQ Newbie
Registered: Jan 2010
Posts: 5

Rep: Reputation: 0
Unhappy Error "Undefined reference" while compiling a c program in linux

I am trying to compile a built up code for a model. While compiling, I got the error of "undefined Reference" as below.I tried to compile with

gcc rout_version.c

/tmp/cclgEVdE.o: In function `MakeConvolution':
rout_version.c.text+0x1455): undefined reference to `sin'
rout_version.c.text+0x14a9): undefined reference to `sin'
/tmp/cclgEVdE.o: In function `MakeUH':
rout_version.c.text+0x2573): undefined reference to `sqrt'
rout_version.c.text+0x25d8): undefined reference to `pow'
rout_version.c.text+0x2613): undefined reference to `exp'
collect2: ld returned 1 exit status

I looked at the similar post in linux and tried to see if I can link like that. Since the error function "MakeConvolution" is a different file than the rout_version.c file, I was not able to fix it. I have attached related files with this post that might be helpful to fix this error in "rout_version.c". The file extensions are "F file for make convolution" ".c for rout_version.c". I don't know if it makes a difference but I had to change the extension since I can upload only txt file extension. The same code worked in "cygwin" (linux interface in windows) while it do not run in Linux. I can get object file (.O) in cygwin but get error in Linux. I need to run the program in actual Linux.

If anyone can help me out, it will be a great relief for me.

Attached Files
File Type: txt make_convolution.txt (4.5 KB, 22 views)
File Type: txt Makefile.txt (1.3 KB, 29 views)
File Type: txt rout_version.c.txt (32.9 KB, 19 views)
Old 07-23-2011, 12:12 AM   #2
Registered: Sep 2006
Location: Canada
Distribution: openSUSE 11.3, Xubuntu 10.10, Ubuntu 11.04
Posts: 53

Rep: Reputation: 23
You need to explicitly link the math library. Like so:
$ gcc rout_version.c -lm
$ ls
a.out  rout_version.c
1 members found this post helpful.
Old 07-25-2011, 11:59 AM   #3
LQ Newbie
Registered: Jan 2010
Posts: 5

Original Poster
Rep: Reputation: 0

Thank You Shambler, it worked. I appreciate it. It would have taken me weeks to find what's going on. You guys are really helpful.

BTW why we need to link it to math library? What it does? Just curious since I am new and it's a built up code.

Old 07-25-2011, 09:06 PM   #4
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
... err because that's where the (code for) maths fns like sin(), pow(), exp() & so on lives ??
Old 07-26-2011, 12:16 AM   #5
LQ Newbie
Registered: Jan 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thank You. Appreciate it.


compile error, undefined

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error when "make" the source of CosmoMC: undefined reference to `dpotrf_' limh Linux - Software 1 09-30-2009 03:27 PM
Several "undefined reference to" error when compiling a C programm acer_peri Programming 8 12-11-2008 06:45 AM
"undefined reference"linker error for static field w/ C++ astorm Programming 5 08-27-2008 04:00 AM
compiling linux failed with "undefined reference to s3c2410_pm_drvinit" cucmi Linux - Hardware 2 08-18-2008 11:21 PM
Error: Make on kismet-2005-08-R1 "undefined reference" zeevolking Linux - Software 1 12-23-2005 09:40 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:24 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration