Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include custom .h files in /usr/include

Tags:

c

I have some custom .h files placed under /usr/include, but in a directory (/usr/include/itsmag1c), and I'm trying to include them in my C file. I'm guessing that because I use

#include "filename.h";

for files in the same directory, and I would use angle brackets for including a file like math.h or stdio.h. Am I right in guessing that I would use the angle brackets for including my custom header files? If so, my program wont compile, I get the error that the included files cannot be found. Can someone please point to me how I would include these files, or would it be best to have them in the same directory as my program?

like image 979
Matthew Avatar asked Oct 23 '25 11:10

Matthew


1 Answers

Two choices:

  1. Use #include <itsmagic1c/filename.h>

  2. Use #include <filename.h> as before but add a -I switch.

Boost etc use method 1. (which works well provided you have Boost installed in system locations as you would on a reasonably standard Linux box with reasonable package management).

Method 2. is fine too, but more work on the build system, Makefiles, etc.

like image 123
Dirk Eddelbuettel Avatar answered Oct 25 '25 02:10

Dirk Eddelbuettel