gpt4 book ai didi

c - Make 找不到函数

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:36:37 28 4
gpt4 key购买 nike

我正在尝试编译 C 程序,同时链接 APR 库。我收到以下错误消息:

cc -g -Wall -pthread -I/usr/local/apr/include/apr-1  -I/usr/local/apr/include/apr-util-1  -L/usr/local/apr/lib -L .aprutil-1 -L .apr-1  devpkg.c bstrlib.o db.o shell.o commands.o   -o devpkg/tmp/cczC53x5.o: In function `main':/home/yotam/Dropbox/Development/C/devpkg/devpkg.c:14: undefined reference to `apr_pool_initialize'/home/yotam/Dropbox/Development/C/devpkg/devpkg.c:15: undefined reference to `apr_pool_create_ex'/home/yotam/Dropbox/Development/C/devpkg/devpkg.c:29: undefined reference to `apr_getopt_init'/home/yotam/Dropbox/Development/C/devpkg/devpkg.c:31: undefined reference to `apr_getopt'db.o: In function `DB_init':/home/yotam/Development/C/devpkg/db.c:89: undefined reference to `apr_pool_initialize'/home/yotam/Development/C/devpkg/db.c:90: undefined reference to `apr_pool_create_ex'/home/yotam/Development/C/devpkg/db.c:93: undefined reference to `apr_dir_make_recursive'/home/yotam/Development/C/devpkg/db.c:105: undefined reference to `apr_pool_destroy'/home/yotam/Development/C/devpkg/db.c:109: undefined reference to `apr_pool_destroy'shell.o: In function `Shell_exec':/home/yotam/Development/C/devpkg/shell.c:16: undefined reference to `apr_pool_create_ex'/home/yotam/Development/C/devpkg/shell.c:38: undefined reference to `apr_pool_destroy'/home/yotam/Development/C/devpkg/shell.c:44: undefined reference to `apr_pool_destroy'shell.o: In function `Shell_run':/home/yotam/Development/C/devpkg/shell.c:55: undefined reference to `apr_procattr_create'/home/yotam/Development/C/devpkg/shell.c:58: undefined reference to `apr_procattr_io_set'/home/yotam/Development/C/devpkg/shell.c:62: undefined reference to `apr_procattr_dir_set'/home/yotam/Development/C/devpkg/shell.c:65: undefined reference to `apr_procattr_cmdtype_set'/home/yotam/Development/C/devpkg/shell.c:68: undefined reference to `apr_proc_create'/home/yotam/Development/C/devpkg/shell.c:71: undefined reference to `apr_proc_wait'commands.o: In function `Command_fetch':/home/yotam/Development/C/devpkg/commands.c:44: undefined reference to `apr_uri_parse'/home/yotam/Development/C/devpkg/commands.c:48: undefined reference to `apr_fnmatch'/home/yotam/Development/C/devpkg/commands.c:51: undefined reference to `apr_fnmatch'/home/yotam/Development/C/devpkg/commands.c:70: undefined reference to `apr_fnmatch'/home/yotam/Development/C/devpkg/commands.c:78: undefined reference to `apr_dir_make_recursive'/home/yotam/Development/C/devpkg/commands.c:84: undefined reference to `apr_fnmatch'/home/yotam/Development/C/devpkg/commands.c:90: undefined reference to `apr_dir_make_recursive'collect2: error: ld returned 1 exit statusmake: *** [devpkg] Error 1

这是我的makefile,应该可以在不同的电脑上编译,其中PREFIX变量是相对于电脑的位置。(这个程序本质上应该有一天可以移植到任何操作系统。现在我只希望能够成功编译它)

PREFIX?=/usr/localLDFLAGS= -L${PREFIX}/apr/lib -L .aprutil-1 -L .apr-1CFLAGS=-g -Wall -pthread -I${PREFIX}/apr/include/apr-1  -I${PREFIX}/apr/include/apr-util-1all: devpkgdevpkg: bstrlib.o db.o shell.o commands.oinstall: all \    install -d $(DESTDIR)/$(PREFIX)/bin/ \    install devpkg $(DESTDIR)/$(PREFIX)/bin/clean:     rm -f *.o \    rm -f devpkg \    rm -rf *.dSYM

我自己去文件夹里搜索了一下,结果是这样的:

yotam@yotam-HP-ProBook-450://usr$ grep -r apr_pool_initialize ../local/apr/include/apr-1/apr_pools.h:APR_DECLARE(apr_status_t) apr_pool_initialize(void);Binary file ./local/apr/lib/libapr-1.so.0.4.6 matchesBinary file ./local/apr/lib/libapr-1.a matchesBinary file ./local/apr/lib/libapr-1.so.0.5.1 matchesBinary file ./local/apr/lib/libapr-1.so.0.4.5 matches./local/apr/lib/apr.exp:apr_pool_initialize

经过我的研究,我清楚地知道这是一个链接器问题。但我找不到执行此操作的命令。

提前致谢。

最佳答案

看起来您缺少告诉 cc 要链接到哪个库的链接选项。我不确定你的 LDFLAGS 宏中的 .aprutil-1.apr-1 是什么,因为你用 -L 指定了它们,我假设它们是目录。

但是,如果您更改行以添加 -l 选项来指定库,它应该会让您更接近。

编辑:因为链接器是单 channel 工具,所有库都需要在对象之后列出,所以符号不会被优化掉。 LDLIBS 是指定库的宏的典型名称,您可以将它们附加到编译/链接命令的末尾,它应该可以工作。

LDFLAGS= -L${PREFIX}/apr/lib -L .aprutil-1 -L .apr-1
LDLIBS= -lapr-1 -laprutil-1

最后两个参数告诉链接器要使用哪个库名称(前缀为 lib 并附加 .a)。 -L 选项指定用于搜索库的其他目录,它实际上不包含任何内容。

或者,您也可以将 LD_LIBRARY_PATH 设置为指向您的库目录。

可以咨询this site (除其他外)作为引用,如果您需要更多帮助调试。

关于c - Make 找不到函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29288248/

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