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
/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 questions.org 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.
You need to explicitly link the math library. Like so:
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.
... err because that's where the (code for) maths fns like sin(), pow(), exp() & so on lives ??
Thank You. Appreciate it.
|All times are GMT -5. The time now is 10:46 PM.|