GCC could not find the header file in the included library

I am trying to include a library file called libmathematica.a in gcc, so it is included in the executable.

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

Note. I have to do this with gcc, since ld will not properly link it to 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.

You can help?

+8
c gcc libraries
source share
3 answers

The header file cannot be in the library. It must be present in a specific place, and you must specify this location with the -I flag of the compiler:

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

If the header file is located in the directory where main.c is or is located in a subdirectory, make sure that you use quotation marks and not angle brackets in the #include directive.

+11
source share

The problem will be in your source file. If mathematica.h is on a directory system, you should use #include <mathematica.h> , and if it were in some local directory, you would use something like #include "libs/mathematica.h" .

+1
source share

Try adding gcc to the call - an option, for example -I / Full / path / to / folder // Where // preferably / header / resides

For example: gcc -I / usr / include / mathematica -lmathematica -o example main.c

+1
source share

All Articles