ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The "tan()" fucntion in linux doesn't work on my machine. It gives some error along with some message like "ld status 1" (I am right now on the windows machine so can't tell you the exact error).
The problem persists for all the <math.h> functions like"pow(),sin(),cos() atan()" etc.
How can I use the <math.h> header file so that the tan() and other functions will work?.
Thanks for the answers, it fixed my problem with sin(x) also. But I am wondering if this is correct behaviour. After all, in the program there is an #include <math.h> directive, which I think should cause the correct libraries to be loaded. I suppose that the linker knows nothing about compiler directives. But I do wonder if that is really correct, or should it be fixed?
The include tells the compiler to use a certain include file. This file contains function prototypes, definitions etc. So the compiler e.g can check if you use the correct syntax for a function.
It does not include the actual functions that you want to use. These are placed in labraries and you (sometimes) have to include the specific library during the linking.
OK, I understand that, and how to get round it, and thanks to all who have answered both the original poster and myself. It saved me possibly many hours.
But, it still seems to me that there is a duplication of input required by declaring the library with an #include directive in the source code (which I would definitely expect to do), and also invoking it on the command line. I would have thought that the #include alone "should" be sufficient, which is what I was questioning. After all, what is an #include for?
Now there may well be a very good and fundamental reason for all of this, if so it would be very interesting to know. Otherwise, I would suggest that just maybe a very minor enhancement to the way things work, if it is possible, might please a lot of people, myself included.
The header files defines the prototype of the function(s) that you wish to access.
The libraries consist of the actual binary code that will be executed when the program runs.
These are different files, living in different file locations. There may even be different versions of the library on the same machine (for example versions optimised for speed of execution or for size of executable, or a really new bells and whistles version rather than the staid but stable version)
So which one to link in? That is where the switch comes in to tell the linker please link in this version of the library.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Not to mention plenty of different include files can refer to a single library, or a combination of libraries, and you only need to include the ones necessary.
On the other hand, you can have "libraryless" include files, defining useful things for your program, but that are not backed at all by a library.
In summary, there is absolutely no one to one relationship between include files and libraries.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.