Questions about C

In this forum members can discuss topics about specific programming languages.
Post Reply
User avatar
thedoctar
Posts: 74
Joined: Fri Apr 15, 2011 11:57 am
Location: Sydney, Australia

Questions about C

Post by thedoctar »

Just a few questions about C.

When using #include <math.h>, why is it that when compiling, I need to add the option -lm. I understand that -l links to some libraries, but why does the compiler need to be linked to whatever 'm' links to? Why can't the compiler find math.h by itself?

And can I make my own C libraries with my own code in it, like how custom modules can be used in python? And how would I use these custom libraries in other code?
4x Intel(R) Core(TM) i3-2330M CPU @ 2.20GHz
Image
fabas indulcet fames

thundre
Posts: 356
Joined: Sun Mar 27, 2011 10:01 am

Re: Questions about C

Post by thundre »

I can answer some of these questions partially, but really they should be asked on a forum specific to your chosen C compiler (gcc or whatever).

The compiler can find math.h by itself. But that's only good for the compile step, not the link step. The library is modular, so that if you want to build for a fancier processor (i386 vs. i586 vs. amd64), you can install that version of libm.so. You can also create your own math library and use that instead of the one distributed with the compiler.

Yes you can create your own libraries and your own include files. On large software projects, that's standard practice. Responsibility for the code is split up, and you only have to compile the libraries you work on -- just use the released binary versions of the others (in library form).
Image

pimspelier
Posts: 41
Joined: Tue Jan 21, 2014 2:06 pm
Location: The Netherlands

Re: Questions about C

Post by pimspelier »

I've made a C code, but it gives a weird error: expected ';' before '{' token. I've tried googling it, but I can't find it, and when I put a ; after int main(void), the error goes away, but of course another error shows up: expected identifier or '(' before '{' token.
But because it's for problem 2, I can't put it here. Does anyone know what to do/Can I PM my code to anyone who has solved it?
Image

User avatar
TheEvil
Posts: 84
Joined: Sun Nov 13, 2011 10:38 am
Location: Szeged, Hungary

Re: Questions about C

Post by TheEvil »

You can send it to me.
Image

Post Reply