Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC unable to find header file in a included library

Tags:

c

gcc

libraries

I am trying to include a library file named libmathematica.a in gcc so it gets linked in the executable example.

I attempt to do this with gcc main.c libmathematica.a -o example

Note: I have to do this with gcc, as ld won't link it properly with the correct system libraries

But I get: fatal error: mathematica.h: No such file or directory ,which is odd because mathematica.h is in the library.

Can you help?

like image 976
Corwin Mcknight Avatar asked May 05 '12 17:05

Corwin Mcknight


People also ask

Where are gcc header files located?

GCC looks for headers requested with #include " file " first in the directory containing the current file, then in the directories as specified by -iquote options, then in the same places it would have looked for a header requested with angle brackets. For example, if /usr/include/sys/stat. h contains #include "types.

How do I add a header file path in Makefile?

Including Header file from Different Directories If you have put the header files in different directories and you are running make in a different directory, then it is required to provide the path of header files. This can be done using -I option in makefile. Assuming that functions.

Where does clang look for headers?

Some header files ( stddef. h , stdarg. h , and others) are shipped with Clang — these are called builtin includes. Clang searches for them in a directory relative to the location of the clang binary.


1 Answers

A header file cannot be in the library. It has to be present at a certain location and you have to specify that location with the -I compiler flag:

gcc -I/path/to/mathematica/include main.c libmathematica.a -o example

If the header file is in the directory where the main.c is or in a subdirectory, then be sure that you use quotes and not angle brackets in the #include directive.

like image 116
Hristo Iliev Avatar answered Sep 21 '22 10:09

Hristo Iliev