4

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?

0

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

The first provides some isolation between components, so it's the better choice.
if I add a folder to /usr/include/ do i need to reboot in order to have gcc find it?
2

Usually, you would put your own headers in the same directory or in a subdirectory. Same-dir includes work with "". For bracket includes, if you use gcc, you can pass additional include directories with

  -Irelativedir 

or

  -I/usr/local/yourpath.

2 Comments

I have them in the /usr/local directory because more than one of my programs use the .h files, and they are packaged with all my programs, but only copied if they are not already present.
The -I option is supported by tcc, clang and icc as well. Microsoft's compilers use /I.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.