12

I want to manually add some header files like math.h and graphic.h for gcc but don't know where to put them.

Mateusz Piotrowski
  • 467
  • 2
  • 10
  • 22
Chirag Soni
  • 131
  • 1
  • 1
  • 7

2 Answers2

19

First take a look in /usr/include or /usr/local/include.

If you find nothing there, try :

`gcc -print-prog-name=cc1plus` -v

This command asks gcc which C++ preprocessor it is using, and then asks that preprocessor where it looks for includes.

You will get a reliable answer for your specific setup.

Likewise, for the C preprocessor:

`gcc -print-prog-name=cc1` -v
Sachin S Kamath
  • 1,417
  • 1
  • 12
  • 20
9

To look for header locations just use the locate command:

locate -b '\math.h'
locate -b '\graphics.h'

or a simpler approach

locate \*/math.h
locate \*/graphics.h

If you are more familiar with regular expression use

locate -r \/math.h$

To make sure the database is up-to-date start:

sudo updatedb

That's the way I'm searching my headers location. It's much faster than using the find command.

Finding headers in not installed packages

For sake of completeness I post a one liner script which is in my mind very useful in finding apt packages involving a special header file.

#!/usr/bin/env bash
apt-file search $1 | cut -f 1 -d ":" | sort -u

Save this one liner for instance in your ~/.local/bin directory as e.g. aptfilesearch and make it executable with chmod +x aptfilesearch. Now you get a list of all packages including the header file you are searching for. Here a simple demonstration:

aptfilesarch math.h
abu_bua
  • 10,473
  • 10
  • 45
  • 62
  • `math.h` should already be present. Example : `/usr/include/c++/7.3.0/math.h` – Knud Larsen Apr 08 '18 at 13:21
  • How does the backslash act to prevent matching by files with preceding characters in their basename? The string `\math.h` should evaluate to `math.h`, but I see that `\math.h` avoids matching files like `tgmath.h` and `quadmath.h`. – user001 Dec 23 '19 at 00:31
  • 1
    FROM 'man locate' : To search for a file named exactly NAME (not \*NAME\*), use locate -b '\NAME' Because \ is a globbing character, this disables the implicit replacement of NAME by \*NAME\*. – abu_bua Dec 23 '19 at 00:43
  • Thanks. I had checked `man locate`, but I guess I have a different version of the `locate(1)` man page (which doesn't have one instance of `\ `). – user001 Dec 23 '19 at 00:53
  • ```info locate``` or http://man7.org/linux/man-pages/man1/locate.1.html – abu_bua Dec 23 '19 at 13:09