GCC无法在包含的库中找到头文件

时间:2021-11-20 02:06:42

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

我试图在gcc中包含一个名为libmathematica.a的库文件,以便在可执行示例中进行链接。

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

我尝试使用gcc main.c libmathematica.a -o示例执行此操作

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

注意:我必须使用gcc执行此操作,因为ld不会将其与正确的系统库正确链接

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

但我得到:致命错误:mathematica.h:没有这样的文件或目录,这很奇怪,因为mathematica.h在库中。

Can you help?

你能帮我吗?

3 个解决方案

#1


13  

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:

头文件不能在库中。它必须出现在某个位置,您必须使用-I编译器标志指定该位置:

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.

如果头文件位于main.c所在的目录中或在子目录中,那么请确保在#include指令中使用引号而不是尖括号。

#2


1  

Try adding to the gcc call - an option like -I/Full/Path/To/The/Directory/Where/the/desired/header/resides

尝试添加到gcc调用 - 像-I / Full / Path / To / The / Directory / Where / the / desired / header /的选项

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

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

#3


1  

The issue would be in your source file. If the mathematica.h is in the system includes directory then you would use #include <mathematica.h> and if it was in some local directory then you would use something like #include "libs/mathematica.h".

问题出在您的源文件中。如果mathematica.h在系统包含目录中,那么你将使用#include ,如果它在某个本地目录中,那么你将使用类似#include“libs / mathematica.h”的东西。

#1


13  

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:

头文件不能在库中。它必须出现在某个位置,您必须使用-I编译器标志指定该位置:

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.

如果头文件位于main.c所在的目录中或在子目录中,那么请确保在#include指令中使用引号而不是尖括号。

#2


1  

Try adding to the gcc call - an option like -I/Full/Path/To/The/Directory/Where/the/desired/header/resides

尝试添加到gcc调用 - 像-I / Full / Path / To / The / Directory / Where / the / desired / header /的选项

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

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

#3


1  

The issue would be in your source file. If the mathematica.h is in the system includes directory then you would use #include <mathematica.h> and if it was in some local directory then you would use something like #include "libs/mathematica.h".

问题出在您的源文件中。如果mathematica.h在系统包含目录中,那么你将使用#include ,如果它在某个本地目录中,那么你将使用类似#include“libs / mathematica.h”的东西。