gpt4 book ai didi

c - 使用 Makefile 安装软件

转载 作者:行者123 更新时间:2023-11-30 17:48:24 27 4
gpt4 key购买 nike

我正在尝试安装一个 C 软件,然后制作一个使用它的测试程序。

该软件由三个文件组成:

  1. x-as-func.c
  2. x-as-func.h
  3. y.h(只有定义语句)
  4. 可执行文件x

在 makefile 中,我有一个“安装”命令:

 .PHONY: install
install: all
cp ./include/x-as-func.h /usr/local/include/x.h
cp ./include/y.h /usr/local/include/y.h
cp ./x /usr/local/bin/x

当我执行“sudo make install”时,一切运行正常并且文件按预期复制。

但是,当我编译测试程序时,如下所示:

测试.c

 #include "hubo-read-trajectory-as-func.h"

int main(){
char* s ="left_elbow.txt";
someFunctionDefinedInX(s, 0, false, false);
}

我收到错误:

 gcc -o test test.c -include  //usr/local/include/x.h
/tmp/cc6ru89m.o: In function `main':
test.c:(.text+0x27): undefined reference to `someFunctionDefinedInX'
collect2: ld returned 1 exit status

或者如果我执行 -ld 那么我就会得到

 gcc -o test random-test.c -ld x.h
gcc: error: x.h: No such file or directory

我相信头文件和可执行文件没有链接?我对吗?我应该如何纠正这个问题?

最佳答案

您有两个不同的问题。

首先是您没有告诉链接器链接到新安装的库。为此,您必须使用 -L-l(小 L)选项。

第二个问题是/usr/local/include不在头文件的默认搜索路径中,需要使用-I选项添加它。

关于c - 使用 Makefile 安装软件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18584895/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com