我使用的是MacBook,最近刚在HomeBrew上安装了CUnit。安装进行得很顺利(没有出现错误或警告,所以我想这没问题)。之后,我想运行一个测试文件:
#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}遗憾的是,在运行这行gcc -o test test.c之后,我得到了这个错误:
test.c:3:10: fatal error: 'CUnit/Basic.h' file not found
#include <CUnit/Basic.h>
^~~~~~~~~~~~~~~
1 error generated.有人能帮我吗?我真的不明白为什么会发生这种情况,即使安装进行得很顺利(我猜)。
发布于 2021-02-23 16:02:42
所以问题是,Homebrew将包安装在/opt/homebrew/Cellar/cunit/2.1-3/路径下,但是对于/usr/local/include或/usr/include中的所有头文件,gcc看起来都是默认的。
要指向已安装的Homebrew软件包路径,请执行以下步骤:https://web.archive.org/web/20090129230009if_/http://www.network-theory.co.uk/docs/gccintro/gccintro_23.html
只需配置环境变量即可;)
https://stackoverflow.com/questions/66323570
复制相似问题