0

I'm a beginner in the Database community. I have been trying to interface with MonetDB using C/C++ MAPI. I have installed MonetDB on my Ubuntu 14.04 LTS machine and when I try to compile a sample program from here, I get the following error:

$ gcc test.c -I /usr/include/monetdb -lmapi

test.c:(.text+0x29): undefined reference to mapi_explain_query' test.c:(.text+0x35): undefined reference tomapi_result_error' test.c:(.text+0x50): undefined reference to mapi_explain_result' test.c:(.text+0x5c): undefined reference tomapi_next_result' test.c:(.text+0x6d): undefined reference to mapi_close_handle' test.c:(.text+0x79): undefined reference tomapi_destroy' test.c:(.text+0x98): undefined reference to mapi_explain' test.c:(.text+0xa4): undefined reference tomapi_destroy' /tmp/cctyQopc.o: In function query': test.c:(.text+0xf9): undefined reference tomapi_query' test.c:(.text+0x110): undefined reference to mapi_error' /tmp/cctyQopc.o: In functionupdate': test.c:(.text+0x160): undefined reference to mapi_close_handle' /tmp/cctyQopc.o: In functionmain': test.c:(.text+0x1b6): undefined reference to mapi_connect' test.c:(.text+0x1c6): undefined reference tomapi_error' test.c:(.text+0x238): undefined reference to mapi_fetch_field' test.c:(.text+0x24d): undefined reference tomapi_fetch_field' test.c:(.text+0x277): undefined reference to mapi_fetch_row' test.c:(.text+0x287): undefined reference tomapi_close_handle' test.c:(.text+0x293): undefined reference to `mapi_destroy' collect2: error: ld returned 1 exit status

This question has previously been asked here and the answer did not solve the problem (although the answer was accepted, I'm not sure why). Any help/directions would be great!

Denzil
  • 326
  • 3
  • 15
  • These are link errors. You need to specify the library info with the -L option. The -I option is to tell the compiler where the include header files are located. – bruceg Aug 02 '18 at 01:30
  • @bruceg I have the -L option in place already. Sorry that it was not part of the original post. I have edited it now – Denzil Aug 02 '18 at 03:05
  • I don't see the `-L` option, just the `-l` one. But I don't think you need, if you installed the MonetDB library with your package manager. – 9769953 Aug 02 '18 at 03:08
  • 2
    Can you try `pkg-config --libs monetdb-mapi` and `pkg-config --cflags monetdb-mapi`? – 9769953 Aug 02 '18 at 03:14
  • @9769953 works perfectly fine now! The commands you pointed out helped me figure out some of the missing packages. After installing them, and after following the steps to compile and link as shown here (https://www.monetdb.org/Documentation/Manuals/SQLreference/Programming/MAPI), it works now! Thank you. – Denzil Aug 02 '18 at 05:27
  • Could you self-answer your question by what exactly you did now? E.g., what flags did you pass to the compiler? What were the results of above commands? – 9769953 Aug 02 '18 at 07:47

1 Answers1

0

On Ubuntu 18.04 using:

pkg-config --libs monetdb-mapi and pkg-config --cflags monetdb-mapi

Won't work because Ubuntu doesn't have a bzip2.pc:

Here how it worked:

gcc main.c -I /usr/include/monetdb -lmapi -lssl -lcrypto -lstream -lcurl -llzma -lbz2