C Library reference error using sqrt() - will not compile.

Thread Tools Search this Thread
Top Forums Programming C Library reference error using sqrt() - will not compile.
# 1  
Old 11-07-2010
Power C Library reference error using sqrt() - will not compile.

This so basic that it should work.... Any ideas would be appreciared. Using a number directly in the sqrt allows it to compile.
primrose > cat a.c
#include <stdio.h>
#include <math.h>
int main(void)
double abcd=9;
primrose > gcc a.c
Undefined first referenced
symbol in file
sqrt /var/tmp//ccm7jh8O.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
primrose >

Last edited by Scott; 11-07-2010 at 07:42 PM.. Reason: Please use code tags
# 2  
Old 11-07-2010
gcc a.c -lm

link in the math library
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 11-07-2010
Thanks, its been seven years since I last used C. I will sudy the gcc command and hopefully not need to ask rooky questions again.
Your answer was spot on.

Last edited by plastichead; 11-07-2010 at 03:07 PM.. Reason: Missed a bit
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Specifying dynamic library path to linker at compile time

I would like to compile a binary that doesnot depend on LD_LIBRARY_PATH as this binary will be setuid to owner and used by other users and since setuid doesnot support LD_LIBRARY_PATH making it independent of LD_LIBRARY_PATH would be great. But I am not able to specify the path of the shared... (1 Reply)
Discussion started by: waavman
1 Replies

2. Shell Programming and Scripting

Perl de-reference code reference variable

Guys, May i know how can we de reference the code reference variable.? my $a = sub{$a=shift;$b=shift;print "SUM:",($a+$b),"\n";}; print $a->(4,5); How can we print the whole function ? Please suggest me regarding this. Thanks for your time :) Cheers, Ranga :) (0 Replies)
Discussion started by: rangarasan
0 Replies

3. UNIX for Dummies Questions & Answers

sqrt in bash

Hi, i have a the following script: #!/bin/bash a=3 b=9 let "c= b*a" let "d=sqrt $c " echo $d But when i execute the code, it gives me the an error saying: line 5: let: d=sqrt 27 : syntax error in expression (error token is "27 ") Can any body tell me what I'm doing wrong? (5 Replies)
Discussion started by: limadario
5 Replies

4. OS X (Apple)

Canot find library on compile - fixing PKG_CONFIG_PATH isn't working

I am using bash on OSX Leopard. When I attempt ./configure I get this error: checking for OPENSSL... configure: error: Package requirements (openssl) were not met: No package 'openssl' found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a... (2 Replies)
Discussion started by: reasonstoprefer
2 Replies

5. Solaris

DBI with MySQL client library compile on Solaris

how dow you complie perl module DBI with mysql from /usr/local/mysql/bin keeps going to mysql client for /usr/sfw/bin is it the LD_PATH ???...:confused: error is # perl login.cgi DBI connect('customers;mysql_socket=/tmp/mysql.sock:localhost','root',...) failed: Client does not... (1 Reply)
Discussion started by: photon
1 Replies

6. Programming

sqrt is not find???

I was writing a simple program in linux, which includes sqrt function of c. I included the math.h. But when I use gcc to compile it, it gave an error message: /home/murat/tmp/ccOv9upo.o(.text+0x4b): In function `main': : undefined reference to `sqrt' collect2: ld returned 1 exit status I... (2 Replies)
Discussion started by: murataht
2 Replies

7. Programming

How compile a library on solaris(like dll in windows)

Hi all, how do i compile a c program into a library on solaris Thanks in advance Zing (3 Replies)
Discussion started by: zing
3 Replies

8. Programming


Hi! when i'm trying to compile this lite example on my linux machine I'll get errors and i don't know why.. #include <stdio.h> #include <math.h> /* needed by sqrt() */ int main() { printf("%f", sqrt(10.0)); return (0); } this is the error: /tmp/cc33hNVHK.o: In function... (1 Reply)
Discussion started by: CreamHarry
1 Replies
Login or Register to Ask a Question

Featured Tech Videos