Monday, February 21, 2022

[SOLVED] How do I compile a self made header in C with gcc?

Issue

So I wanto to compile a program that has included these headers:

#include <stdio.h>
#include "teclas_tictac.h"

The header teclas_tictac.h has prototypes for functions in teclas_tictac.c file.

How do I do that?

I usually do gcc myprogram.c -o myprogram.

Thanks


Solution

Not to get too technical, but the function implementations is what needs to be assembled, converted to object code and finally linked, the header file is not used directly in the compilation process, its contents are simply copied to where you use the #include directive.

So what you need for the compilation process is the .c file not the header file.

gcc myprogram.c teclas_tictac.c -o myprogram

You can also include warning flags in the process which can help detect problems you may otherwise miss.

Here are some of the more commonly used:

gcc myprogram.c teclas_tictac.c -o myprogram -Wall -Wextra -pedantic


Answered By - anastaciu
Answer Checked By - Dawn Plyler (WPSolving Volunteer)