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.
hello friends
I've started programming in c recently . following are the details about scene:
* vim is editor and program is compiled in gcc
* whenever a program involving math function appears it gives error i.e
though math.h is included in header file compiler complains about it
it gives error of unrecognized function that math function like sqrt, etc
* question is how to connect math.h to a program.
hello friends
I've started programming in c recently . following are the details about scene:
* vim is editor and program is compiled in gcc
* whenever a program involving math function appears it gives error i.e
though math.h is included in header file compiler complains about it
it gives error of unrecognized function that math function like sqrt, etc
* question is how to connect math.h to a program.
Enter
C math library
into favorite WEB search engine and read the matches.
When you compile your program with gcc you will also (typically) invoke the linker as well. For an overview: the compiler converts your source code to object code (it takes something that you can read into something that the computer can read) the compiler does this for each source code file generating one object fiel for each source code file that you have in your program; the linker joins all of this object code together (along with any libraries you are using) to form an executable.
The Maths library alos need to be linked in but it doesn't get linked in by default. So you will need to tell it to link in the maths library, that is where the switch -lm comes into play.
If you have one source code file called myCalc.c, which uses the maths library, and you want your program to be called calc, use the following command:
into favorite WEB search engine and read the matches.
Which I did. Ten matches came up:
Two for C++
One for Python
Two for vendor version of Maths libraries
Of the remaining five matches only one mentioned linking but for someone who doesn't understand the linking process its significance would be very easy to miss.
Incidentally, the clearest advice came from a C++ specific page.
Quote:
Compiling with gcc
In order to use some of the above functions, certain versions of the gcc compiler require the math library to be explicitly linked in using the -lm command-line option.
In summary you advice would have been of very little help to someone who was just stating to learn to program and hadn't yet understood the nuances of gcc.
So please, don't just tell people to use a search engine as if it is a panacea, context is important and often that is what people lack when they come to LinuxQuestions.
...
because they don't know as much as you. That's why they're here.
Nowadays people know how to use WEB search engines from the(ir) teen age.
The legitimate questions to ask are the ones which can't be easily answered through keyword search.
For example, suppose one has a map of a city with SRC and DST points on it and asks about an algorithm regarding finding the shortest way between the two points. In order to find the algorithm(s) one has to know the "traveling salesman problem" term, which is not obvious. For example, I learned about the term in English less than 10 years ago, though I knew the term in a different language.
In the OP's case plain keyword search yields an answer even without visiting the URLs returned by the search engines (see the attachment in an earlier post of mine).
Nowadays people know how to use WEB search engines from the(ir) teen age.
Going off topic for a moment this assumption is completely incorrect. The global internet penetration is about 26% for more details see Internet World Stats.
Quote:
Originally Posted by Sergei Steshenko
The legitimate questions to ask are the ones which can't be easily answered through keyword search.
As you pointed out earlier the original poster was unaware of the term linking and so by you very definition the question was valid and so didn't warrant you condescending approach.
This arguement about how to use searching is not helping the OP, so let's stop now---OK?
Sergei;
You are of course correct about finding things on Google, but less experienced people often do not know how to do this efficiently. I suggest a less confrontational approach.
...
As you pointed out earlier the original poster was unaware of the term linking and so by you very definition the question was valid and so didn't warrant you condescending approach.
Then he shouldn't be doing "C" programming in the first place (with any library). I.e. the whole thread is invalid - it's like "how do I build a rocket not even bothering to learn physics ?".
Frequently used compilation options
...
Compile myprog.C when it contains Xlib graphics routines.
g++ myprog.C -o myprog -lX11
If "myprog.c" is a C program, then the above commands will all work by replacing g++ with gcc and "myprog.C" with "myprog.c". Below are a few examples that apply only to C programs.
Compile a C program that uses math functions such as "sqrt".
gcc myprog.C -o myprog -lm
...
The short-cut library linking option -l can also be used to link the program, without needing to specify the full filename of the library explicitly:
$ gcc -Wall -L. main.c -lhello -o hello
.
I.e. two very basic keyword searches yield the needed knowledge (both the particular knowledge regarding the math library and the "link" term) if one makes at least the minimal decency effort. I remember I heard at work from a colleague "It takes so much times to read manuals, that's why I'm asking you". And this is really bothering. I.e. the guy didn't want to read the manual even after being told which one to read.
The answer to all such threads should be: "Have you been banned on all WEB search engines ?".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.