【发布时间】:2019-01-09 15:53:41
【问题描述】:
我是数据库社区的初学者。我一直在尝试使用 C/C++ MAPI 与 MonetDB 交互。我在我的 Ubuntu 14.04 LTS 机器上安装了 MonetDB,当我尝试从 here 编译示例程序时,我收到以下错误:
$ gcc test.c -I /usr/include/monetdb -lmapi
test.c:(.text+0x29): 未定义引用
mapi_explain_query' test.c:(.text+0x35): undefined reference tomapi_result_error' test.c:(.text+0x50): 未定义引用mapi_explain_result' test.c:(.text+0x5c): undefined reference tomapi_next_result' test.c:(.text+0x6d): 未定义引用mapi_close_handle' test.c:(.text+0x79): undefined reference tomapi_destroy' test.c:(.text+0x98): 未定义引用mapi_explain' test.c:(.text+0xa4): undefined reference tomapi_destroy' /tmp/cctyQopc.o:在函数query': test.c:(.text+0xf9): undefined reference tomapi_query' test.c:(.text+0x110): 对mapi_error' /tmp/cctyQopc.o: In functionupdate'的未定义引用: test.c:(.text+0x160): 未定义对mapi_close_handle' /tmp/cctyQopc.o: In functionmain'的引用: test.c:(.text+0x1b6): 未定义引用mapi_connect' test.c:(.text+0x1c6): undefined reference tomapi_error' test.c:(.text+0x238): 未定义引用mapi_fetch_field' test.c:(.text+0x24d): undefined reference tomapi_fetch_field' test.c:(.text+0x277): 未定义引用mapi_fetch_row' test.c:(.text+0x287): undefined reference tomapi_close_handle' test.c:(.text+0x293): undefined reference to `mapi_destroy' collect2:错误:ld 返回 1 个退出状态
之前有人问过这个问题here,答案并没有解决问题(虽然答案被接受了,但我不知道为什么)。任何帮助/指导都会很棒!
【问题讨论】:
-
这些是链接错误。您需要使用 -L 选项指定库信息。 -I 选项是告诉编译器包含头文件的位置。
-
@bruceg 我已经有了 -L 选项。抱歉,它不是原始帖子的一部分。我现在编辑了它
-
我没有看到
-L选项,只有-l一个。但我认为你不需要,如果你用你的包管理器安装了 MonetDB 库。 -
你能试试
pkg-config --libs monetdb-mapi和pkg-config --cflags monetdb-mapi吗? -
@9769953 现在可以正常工作了!您指出的命令帮助我找出了一些丢失的包。安装它们后,按照此处所示的步骤编译和链接 (monetdb.org/Documentation/Manuals/SQLreference/Programming/MAPI),它现在可以工作了!谢谢。