473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C programming using linux terminal

Whenever i run this code(on linux terminal):

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3. int main()
  4. {
  5. double x,y;
  6. printf ("enter the angle between the two sides(in radians): \n");
  7. scanf ("%lf",&x);
  8. y= cos(x);
  9. printf ("the cosine of the angle is: %lf\n",y);
  10. return 0;
  11. }
  12.  
I always get this error:

Expand|Select|Wrap|Line Numbers
  1. /tmp/cckIyjg6.o: In function `main':
  2. CosineRule.c:(.text+0x33): undefined reference to `cos'
  3. collect2: ld returned 1 exit status
  4.  
whats the problem with my code? please help..
Feb 16 '13 #1
3 1959
weaknessforcats
9,208 Expert Mod 8TB
There are no errors in the code you posted.

The error is in CosineRule.c. Did you include <math.h> in that file?
Feb 16 '13 #2
Luuk
1,047 Expert 1GB
@weaknessforcats: it is there at line 2 ...

i googled and found this:
use: cc CosineRule.c -o CosineRule -lm
(http://www.cs.cf.ac.uk/Dave/C/node17.html)
Feb 16 '13 #3
donbock
2,426 Expert 2GB
When you include <math.h> it is a little bit like telling the compiler: "Yes, I know these functions (such as cos) are not in my source file; but trust me, you'll have them when you need them."
That error message is the compiler's way of saying: "You let me down -- I didn't have this function when I needed it."
The -lm command line argument to the compiler directs it to look in library m (file libm.a) for anything that it still needs. As it happens, libm is where the <math.h> functions are kept (m is for math) so now the compiler is happy because it has everything it needs.

You might ask: "Why isn't libm automatically included?" The simple answer is that the C Standard does not require that behavior. The real answer is that C allows you the leeway to write your own cos function -- and you can even go so far as to write a cos function that has nothing to do cosines. I'm not suggesting it would be wise to do this, but it is allowed.
Feb 16 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Steven Burn | last post by:
Thats the headline this morning. In the latest issue of The Register (my favourite online newsletter), there's a story (see URL below) about Microsoft using Linux temporarily, for their...
4
by: Midhun K Menon | last post by:
Is there anyone who could direct me to an absolute beginners course in Windows Programming using C++? Links would be more welcome than Book names, because much of the foreign books aren't locally...
3
by: mairhtin o'feannag | last post by:
Hello, Since DB2 Cluster Certification Guide is out of print and I cannot seem to get my hands on a copy, is there a publication that would give me a "cookbook" approach to setting up a cluster...
4
by: Ehsan | last post by:
I wrote this simple code for setting environmental variable in linux but it's seems deosn' work. /************************************************************************/ #include <stdio.h>...
2
by: _A_C-ker_ | last post by:
Hello geek(s), I'm in desperate need of graphics programming using C language. Does anyone have material or web-links that explain graphics programming in- detail? I would appreciate your help...
5
by: McGuard | last post by:
I am trying to send an SMS using hyper terminal in windows XP pro. I am connecting my Satellite Phone (Motorola Iridium 9505A) to my notebook via serial cable (RS232) . Below are the sample...
3
AmberJain
by: AmberJain | last post by:
HELLO, I have some queries. Please help. Let me tell you experts that I'm a linux newbie and an ABSOLUTE UNIX illiterate person. I know a bit of linux and can easily handle GUI of Red hat...
0
by: ragsnayak | last post by:
Hi, I'm looking for reference material for "client server programming using C on windows environment". I'm using eclipse CDT IDE and Migwin for the development. Can anyone help me out? ...
1
Atran
by: Atran | last post by:
Hi, I've been working with C# and AS2, but today I don't have Windows since I'm using Linux. Any recommended languages which are properly applicable in all operating systems? (I know some info,...
0
by: Martha Pagka | last post by:
Hello. Me and my colleagues are trying to program an AutoCAD application using VB.NET (actually, VB 2008). We followed the below procedure closely: AutoCAD programming using VB.Net, C#.Net,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.