Skip to main content
  1. Open your favorite text editor
  2. Create a new file named whatever_you_wantwhatever.h
  3. Put your function prototypes in it

DONE.

Example whatever.h

#ifndef WHATEVER_H_INCLUDED #define WHATEVER_H_INCLUDED int f(int a); #endif 

Note: include guards (preprocessor commands) added thanks to luke. They avoid including the same header file twice in the same compilation. Another possibility (also mentioned on the comments) is to add #pragma once but it is not guaranteed to be supported on every compiler.

Example whatever.c

#include "whatever.h" int f(int a) { return a + 1; } 

And then you can include "whatever.h" into any other .c file, and link it with whatever.c's object file.

Like this:

sample.c

#include "whatever.h" int main(int argc, char **argv) { printf("%d\n", f(2)); /* prints 3 */ return 0; } 

To compile it (if you use GCC):

$ gcc -c whatever.c -o whatever.o $ gcc -c sample.c -o sample.o 

To link the files to create an executable file:

$ gcc sample.o whatever.o -o sample 

You can test sample:

$ ./sample 3 $ 
  1. Open your favorite text editor
  2. Create a new file named whatever_you_want.h
  3. Put your function prototypes in it

DONE.

Example whatever.h

#ifndef WHATEVER_H_INCLUDED #define WHATEVER_H_INCLUDED int f(int a); #endif 

Note: include guards (preprocessor commands) added thanks to luke. They avoid including the same header file twice in the same compilation. Another possibility (also mentioned on the comments) is to add #pragma once but it is not guaranteed to be supported on every compiler.

Example whatever.c

#include "whatever.h" int f(int a) { return a + 1; } 

And then you can include "whatever.h" into any other .c file, and link it with whatever.c's object file.

Like this:

sample.c

#include "whatever.h" int main(int argc, char **argv) { printf("%d\n", f(2)); /* prints 3 */ return 0; } 

To compile it (if you use GCC):

$ gcc -c whatever.c -o whatever.o $ gcc -c sample.c -o sample.o 

To link the files to create an executable file:

$ gcc sample.o whatever.o -o sample 

You can test sample:

$ ./sample 3 $ 
  1. Open your favorite text editor
  2. Create a new file named whatever.h
  3. Put your function prototypes in it

DONE.

Example whatever.h

#ifndef WHATEVER_H_INCLUDED #define WHATEVER_H_INCLUDED int f(int a); #endif 

Note: include guards (preprocessor commands) added thanks to luke. They avoid including the same header file twice in the same compilation. Another possibility (also mentioned on the comments) is to add #pragma once but it is not guaranteed to be supported on every compiler.

Example whatever.c

#include "whatever.h" int f(int a) { return a + 1; } 

And then you can include "whatever.h" into any other .c file, and link it with whatever.c's object file.

Like this:

sample.c

#include "whatever.h" int main(int argc, char **argv) { printf("%d\n", f(2)); /* prints 3 */ return 0; } 

To compile it (if you use GCC):

$ gcc -c whatever.c -o whatever.o $ gcc -c sample.c -o sample.o 

To link the files to create an executable file:

$ gcc sample.o whatever.o -o sample 

You can test sample:

$ ./sample 3 $ 
added 139 characters in body; deleted 3 characters in body
Source Link
Pablo Santa Cruz
  • 182.1k
  • 33
  • 250
  • 300
  1. Open your favorite text editor
  2. Create a new file named whatever_you_want.h
  3. Put your function prototypes in it

DONE.

Example whatever.h

#ifndef WHATEVER_H_INCLUDED #define WHATEVER_H_INCLUDED int f(int a); #endif 

Note: headerinclude guards (preprocessor commands) includedadded thanks to luke. They avoid including the same header file twice in the same compilation. Another possibility (also mentioned on the comments) is to add #pragma once but it is not guaranteed to be supported on every compiler.

Example whatever.c

#include "whatever.h" int f(int a) { return a + 1; } 

And then you can include "whatever.h" into any other .c file, and link it with whatever.c's object file.

Like this:

sample.c

#include "whatever.h" int main(int argc, char **argv) { printf("%d\n", f(2)); /* prints 3 */ return 0; } 

To compile it (if you use GCC):

$ gcc -c whatever.c -o whatever.o $ gcc -c sample.c -o sample.o 

To link the files to create an executable file:

$ gcc sample.o whatever.o -o sample 

You can test sample:

$ ./sample 3 $ 
  1. Open your favorite text editor
  2. Create a new file named whatever_you_want.h
  3. Put your function prototypes in it

DONE.

Example whatever.h

#ifndef WHATEVER_H_INCLUDED #define WHATEVER_H_INCLUDED int f(int a); #endif 

Note: header guards (preprocessor commands) included thanks to luke. They avoid including the same header file twice in the same compilation.

Example whatever.c

#include "whatever.h" int f(int a) { return a + 1; } 

And then you can include "whatever.h" into any other .c file, and link it with whatever.c's object file.

Like this:

sample.c

#include "whatever.h" int main(int argc, char **argv) { printf("%d\n", f(2)); /* prints 3 */ return 0; } 

To compile it (if you use GCC):

$ gcc -c whatever.c -o whatever.o $ gcc -c sample.c -o sample.o 

To link the files to create an executable file:

$ gcc sample.o whatever.o -o sample 

You can test sample:

$ ./sample 3 $ 
  1. Open your favorite text editor
  2. Create a new file named whatever_you_want.h
  3. Put your function prototypes in it

DONE.

Example whatever.h

#ifndef WHATEVER_H_INCLUDED #define WHATEVER_H_INCLUDED int f(int a); #endif 

Note: include guards (preprocessor commands) added thanks to luke. They avoid including the same header file twice in the same compilation. Another possibility (also mentioned on the comments) is to add #pragma once but it is not guaranteed to be supported on every compiler.

Example whatever.c

#include "whatever.h" int f(int a) { return a + 1; } 

And then you can include "whatever.h" into any other .c file, and link it with whatever.c's object file.

Like this:

sample.c

#include "whatever.h" int main(int argc, char **argv) { printf("%d\n", f(2)); /* prints 3 */ return 0; } 

To compile it (if you use GCC):

$ gcc -c whatever.c -o whatever.o $ gcc -c sample.c -o sample.o 

To link the files to create an executable file:

$ gcc sample.o whatever.o -o sample 

You can test sample:

$ ./sample 3 $ 
added 223 characters in body
Source Link
Pablo Santa Cruz
  • 182.1k
  • 33
  • 250
  • 300
  1. Open your favorite text editor
  2. Create a new file named whatever_you_want.h
  3. Put your function prototypes in it

DONE.

Example whatever.h

#ifndef WHATEVER_H_INCLUDED #define WHATEVER_H_INCLUDED int f(int a); #endif 

Note: header guards (preprocessor commands) included thanks to luke. They avoid including the same header file twice in the same compilation.

Example whatever.c

#include "whatever.h" int f(int a) { return a + 1; } 

And then you can include "whatever.h" into any other .c file, and link it with whatever.c's object file.

Like this:

sample.c

#include "whatever.h" int main(int argc, char **argv) { printf("%d\n", f(2)); /* prints 3 */ return 0; } 

To compile it (if you use GCC):

$ gcc -c whatever.c -o whatever.o $ gcc -c sample.c -o sample.o 

To link the files to create an executable file:

$ gcc sample.o whatever.o -o sample 

You can test sample:

$ ./sample 3 $ 
  1. Open your favorite text editor
  2. Create a new file named whatever_you_want.h
  3. Put your function prototypes in it

DONE.

Example whatever.h

int f(int a); 

Example whatever.c

#include "whatever.h" int f(int a) { return a + 1; } 

And then you can include "whatever.h" into any other .c file, and link it with whatever.c's object file.

Like this:

sample.c

#include "whatever.h" int main(int argc, char **argv) { printf("%d\n", f(2)); /* prints 3 */ return 0; } 

To compile it (if you use GCC):

$ gcc -c whatever.c -o whatever.o $ gcc -c sample.c -o sample.o 

To link the files to create an executable file:

$ gcc sample.o whatever.o -o sample 

You can test sample:

$ ./sample 3 $ 
  1. Open your favorite text editor
  2. Create a new file named whatever_you_want.h
  3. Put your function prototypes in it

DONE.

Example whatever.h

#ifndef WHATEVER_H_INCLUDED #define WHATEVER_H_INCLUDED int f(int a); #endif 

Note: header guards (preprocessor commands) included thanks to luke. They avoid including the same header file twice in the same compilation.

Example whatever.c

#include "whatever.h" int f(int a) { return a + 1; } 

And then you can include "whatever.h" into any other .c file, and link it with whatever.c's object file.

Like this:

sample.c

#include "whatever.h" int main(int argc, char **argv) { printf("%d\n", f(2)); /* prints 3 */ return 0; } 

To compile it (if you use GCC):

$ gcc -c whatever.c -o whatever.o $ gcc -c sample.c -o sample.o 

To link the files to create an executable file:

$ gcc sample.o whatever.o -o sample 

You can test sample:

$ ./sample 3 $ 
Source Link
Pablo Santa Cruz
  • 182.1k
  • 33
  • 250
  • 300
Loading