DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 1st October 2021
yezster yezster is offline
Port Guard
 
Join Date: Jan 2014
Posts: 12
Default Cannot compile simple c sniffet.

Hi there why can't I not compile this code sniffet in my OpenBSD system 6.9

source code of xy.c:

#include <stdio.h>
#include <math.h>

int main() {

float x,y,r,t;

printf("Enter X and Y coordinates: ");
scanf("%f%f",&x,&y);

r=sqrt(x*x+y*y);
t=atan2f(y,x);
t=t*180.0/M_PI;

printf("R: %f Theta: %f degrees\n",r,t);

return 0;

}

== end of source ==

cc -g xy.c
ld: error: undefined symbol: atan2f
>>> referenced by xy.c:12
>>> /tmp/xy-bc81a0.omain)
cc: error: linker command failed with exit code 1 (use -v to see invocation)



Thats the error that keeps popping up, I don't seem to have anything wrong with the source code, I already put the #include <math.h>. Please enlighten me about this error. Thank you very much.
Reply With Quote
  #2   (View Single Post)  
Old 2nd October 2021
jmccue jmccue is offline
Real Name: John McCue
Shell Scout
 
Join Date: Aug 2012
Location: here
Posts: 87
Default

add '-lm' to the end of the cc command line, that will bring in the math library.

Last edited by jmccue; 2nd October 2021 at 12:41 AM. Reason: spelling
Reply With Quote
  #3   (View Single Post)  
Old 2nd October 2021
yezster yezster is offline
Port Guard
 
Join Date: Jan 2014
Posts: 12
Default

Quote:
Originally Posted by jmccue View Post
add '-lm' to the end of the cc command line, that will bring in the math library.
Thanks... It finally compiled.
Reply With Quote
Reply

Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't compile gcc-4.3.3_20090101 troberts FreeBSD Ports and Packages 7 12th January 2009 10:30 PM
Can't compile autoconf262 Sunsawe FreeBSD Ports and Packages 2 26th August 2008 07:53 PM
firefox3 will not compile map7 FreeBSD Ports and Packages 8 14th July 2008 11:23 PM
How come gnome2 won't compile? Damien787 FreeBSD Ports and Packages 10 16th June 2008 05:20 PM
Why wont this compile? Johnny2Bad FreeBSD General 10 19th May 2008 11:30 PM


All times are GMT. The time now is 06:20 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick