-1

I am new to C++ and am learning C90 as a pre-introduction to the language. I noticed that when I include an external header (such as an OpenGL header), I also need to include the binary library file containing the exports.

Anything included which is part of the C standard library is automatically added to my project, but I am able to include sys/socket.h without needing to explicitly define any extra library locations!

Are the sys/*.h header files all included in the standard library on Unix by default or am I missing something?

Does the linker have to scan all libraries you include until it finds the right one with the correct definitions?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
  • 1) Don't spam tags for unrelated languages! C++ is not C; your text does not make any sense! 2) unclear. What is your problem? 3) Headers and linking are completely unrelated. – too honest for this site Jun 18 '17 at 14:56
  • It's completely unecessary, and probably undesirable, to learn C before learning C++. –  Jun 18 '17 at 14:59
  • 3
    C is **not** an introduction to C++. Why do you use the C++ tag while asking a C90 question? You never need a library to include a header. You need a library to use functions declared in that header. –  Jun 18 '17 at 15:00
  • @manni66 Yes, and the functions defined in the `sys/socket.h` header can be included without a library - as I stated. It makes no sense why there aren't any errors as the C standard doesn't define these functions yet it seems to compile perfectly fine. Where is the actual definitions for these functions located and how is the linker locating them? – Timothy Riddle Jun 18 '17 at 15:07
  • @NeilButterworth: It depends on what one wants to learn. If the target is to learn C, one should learn C (just not ancient C90, but modern C11, at worst C99). If one want to learn C++, it should be C++ (C++11/14/17 actually). – too honest for this site Jun 18 '17 at 15:09
  • Why do you learn C90? Get a more recent book and learn modern C. C90 is outdated since 18 years! – too honest for this site Jun 18 '17 at 15:10
  • 1
    @Olaf To see the roots of the language! I fully understand that C practices are bad in C++ and they share some syntax, but are different languages. I'm not going in-depth into learning C, I just want to get a fundamental grasp on the roots and behind the scenes first. I still don't understand how my declarations are linked unless the linker scans every single library on my system... perhaps answering questions is better than criticizing. – Timothy Riddle Jun 18 '17 at 15:13
  • @TimothyRiddle: That's a wrong approach! If you want ot see the roots of the languages, you really should learn B and assembly language (PDP/11 IIRC). Get a good **recent** book and work through the chapters. – too honest for this site Jun 18 '17 at 15:17
  • 1
    @Olaf I don't think you quite understand - I'm not looking to learn the language in-depth as I already said. I just wanted a knowledge of how the compilation works to generate executable files, static/dynamic libraries, etc. Any books you recommend on basics of compilation? I'm not writing a compiler so no over-complications. :) – Timothy Riddle Jun 18 '17 at 15:22
  • I s Amazon down? Google? Stack Overflow? Please undertand we are not a tutoring site. Use your search skills. If there are none, you should learn how to search anyway, it's a vital skill nowadays. – too honest for this site Jun 18 '17 at 15:32
  • 1
    @Olaf Well seeing as you don't seem to know the answer to the question, I guess I'll have to do that. Thanks anyways. :p – Timothy Riddle Jun 18 '17 at 15:34
  • @TimothyRiddle if you don't use the function in **your** C code there is no need to link anything. –  Jun 18 '17 at 15:35

1 Answers1

2

The C POSIX library is a superset of the C standard library. After opening it up, it looks like the function definitions to the sys/*.h files are all there even though they aren't an explicit component of the original C standard.

The actual function definitions are included inside of the standard library on Unix.

Also found this, interesting read: Difference between C standard library and C POSIX library