r/C_Programming • u/Majestic-Instance704 • Jul 25 '26
why do header files contain only function declarations instead of full code body ? why have the code in a sepreate lib files ?
for context I am trying to learn gamedev on my own and setting up raylib/sfml confused me , then I learnt that the ( include )files only contained function declarations and the actual code was in( lib ) files (mind you but it is a weird name) , wouldn't it be more convenient to have them in the same file instead of linking ?
sorry if I sound stupid.
104
Upvotes
View all comments
Show parent comment
1
u/NotThatJonSmith Aug 01 '26
You’re just listing languages without telling me how this mechanism works for any one of them.
Just taking a look at rust, when you ship a crate, it’s static linkage only. If you want a shared library - code that maps into the VA space of more than one process at a time without needing to be duplicated physically (like how static linkage just embeds the library code into your application) then they officially instruct us to use extern C linkage and provide - you guessed it - header files. Rust doesn’t provide a way to explain to the compiler the contents of a binary such that it can be linked to on its own.