user2073659
user2073659

Reputation: 42

How compiled c programs execute when my system is missing GTK header files?

I am trying to compile a simple ANSI C program which requires GTK header files.

I know how to link the source code with gtk.h when compiling with GCC.

My question is how come applications such as gedit (GTK lib) is running on my system considering that GTK header files are missing? Presumably Gedit was compiled on a system which did have the GTK library. But why does Gedit not require header files on my system during execution?

As a Java programmer to compile a program the class files always have to be packaged with the main executable. Also I would need the JVM installed on the target system.

Thank you for your helpful responses.

Upvotes: 1

Views: 296

Answers (2)

cnicutar
cnicutar

Reputation: 182684

But why does Gedit not require header files on my system during execution?

Header files are only needed in the preprocessing phase. Once the preprocessor is done with them the compiler never even sees them. Obviously, the target system doesn't need them either for execution (the same way .c files aren't needed).

You're probably thinking of libraries, and you're right. Indeed: if a program is dynamically linked and the target environment doesn't have the necessary libraries, in the right places, with the right versions it won't run. One way to ensure it will run on most systems is to statically link stuff, but this will also bloat your executable and make poorer use of memory.

Also I would need the JVM installed on the target system.

Well, for C nothing like that is needed since once you compile it you get native code. Native code is very different from the intermediate stuff (bytecode) you get from java. There's no need for anything like an interpreter: you just feed it your binary stuff to the CPU and it does its thing.

Upvotes: 5

David Schwartz
David Schwartz

Reputation: 182827

Everything the executable needs from the header files is built into the executable when it's compiled. In C, header files are just included literally in the source file when referenced and then compiled.

Upvotes: 4

Related Questions