Questions about linking libraries in C

Posted by james on Programmers See other posts from Programmers or by james
Published on 2012-10-09T09:01:01Z Indexed on 2012/10/09 9:52 UTC
Read the original article Hit count: 303

Filed under:
|
|
|

I am learning C (still very much a beginner) on Linux using the GCC compiler. I have noticed that some libraries, such as the library used with the math.h header, need to be linked in manually when included. I have been linking in the libraries using various flags of the form -l[library-name], such as -lm for the above-mentioned math library.

However, after switching from the command line and/or Geany to Code::Blocks, I noticed that Code::Blocks uses g++ to compile the programs instead of the gcc that I am used to (even though the project is definitely specified as C). Also, Code::Blocks does not require the libraries to be manually linked in when compiling - libraries such as the math library just work.

I have two questions:

Firstly, is it "bad" to compile C programs with the g++ compiler? So far it seems to work, but after all, C++ is not C and I am quite sure that the g++ compiler is meant for C++.

Secondly, is it the g++ compiler that is doing the automatic linking of the libraries in Code::Blocks?

© Programmers or respective owner

Related posts about c

    Related posts about libraries