0

When I run the hello_mongoc test app (renamed to mongotest), the output looks like this:

{ "ok" : 1 }
./mongotest: symbol lookup error: /usr/local/lib/libmongoc-1.0.so.0: undefined symbol: bson_validate_with_error

The app is build with:

cc -o mongotest mongotest.o -lmongoc-1.0 -lbson-1.0

and gives no compilation warnings/errors.

This is in /usr/local/lib:

lrwxrwxrwx  1 root staff      16 Oct  5 11:38 libbson-1.0.so -> libbson-1.0.so.0
lrwxrwxrwx  1 root staff      20 Oct  5 11:38 libbson-1.0.so.0 -> libbson-1.0.so.0.0.0
-rw-r--r--  1 root staff  549180 Oct  5 11:29 libbson-1.0.so.0.0.0
-rw-r--r--  1 root staff  744738 Oct  5 11:30 libbson-static-1.0.a
lrwxrwxrwx  1 root staff      18 Oct  5 11:38 libmongoc-1.0.so -> libmongoc-1.0.so.0
lrwxrwxrwx  1 root staff      22 Oct  5 11:38 libmongoc-1.0.so.0 -> libmongoc-1.0.so.0.0.0
-rw-r--r--  1 root staff 2162580 Oct  5 11:31 libmongoc-1.0.so.0.0.0
-rw-r--r--  1 root staff 3553982 Oct  5 11:33 libmongoc-static-1.0.a

I am running on a raspberry pi 3B+

willemx
  • 530
  • 7
  • 19

1 Answers1

0

According to libbson source, bson_validate_with_error was added in 1.7.0, while you have 1.0.

EDIT 1:

This seems to be a linker issue. More info in comments below.

EDIT 2:

One way of solving this is to use static linking:

gcc -o mongotest mongotest.c $(pkg-config --libs --cflags libmongoc-static-1.0)
Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95
  • As far as I can tell I am using the most recent version (1.13) of mongo-c-driver: http://mongoc.org/libmongoc/current/installing.html , or do you know of a more recent one? – willemx Nov 04 '18 at 18:58
  • I checked, and `validate_with_error` does exist in the bson lib that I am using. So there must be something wrong with the linking process? – willemx Nov 04 '18 at 19:20
  • I believe the documentation might be out of date, and hence you're installing quite old version. What I can suggest - build and install library by yourself. Check out the sources, then run: `autoconf`, `/.configure`, `make`, `sudo make install`. – Andrejs Cainikovs Nov 04 '18 at 19:42
  • This is exactly what I did. Therefore I can see in the source (`bson.c`) that the function `validate_with_error` does exist in the lib that I build. – willemx Nov 05 '18 at 10:11
  • Could you provide output of following: `readelf -Ws /usr/local/lib/libmongoc-1.0.so.0` – Andrejs Cainikovs Nov 05 '18 at 10:16
  • `readelf -Ws /usr/local/lib/libmongoc-1.0.so.0 | grep validate_with_error 269: 00000000 0 FUNC GLOBAL DEFAULT UND bson_validate_with_error 4021: 00000000 0 FUNC GLOBAL DEFAULT UND bson_validate_with_error` – willemx Nov 05 '18 at 10:33
  • and the same for libbson: `readelf -Ws /usr/local/lib/libbson-1.0.so.0 | grep validate_with_error 239: 0000f51c 72 FUNC GLOBAL DEFAULT 11 bson_validate_with_error 1298: 0000f51c 72 FUNC GLOBAL DEFAULT 11 bson_validate_with_error` – willemx Nov 05 '18 at 10:36
  • Ok, this might sound strange to you, but please try to reorder libraries in a command line that links your binary: `cc -o mongotest mongotest.o -lbson-1.0 -lmongoc-1.0`, and report your observations. – Andrejs Cainikovs Nov 05 '18 at 10:40
  • same result: `{ "ok" : 1 } ./mongotest: symbol lookup error: /usr/local/lib/libmongoc-1.0.so.0: undefined symbol: bson_validate_with_error` – willemx Nov 05 '18 at 10:42
  • It's clear that it has something to do with the linker. Is there any particular reason why you are not using `pkg-config`? Like: `gcc -o mongotest mongotest.c $(pkg-config --libs --cflags libmongoc-1.0)` – Andrejs Cainikovs Nov 05 '18 at 10:44
  • This is my first C-project again since 20 years so I don't know `pkg-config` ;) But I will do some research now... Thanks for your tips! – willemx Nov 05 '18 at 10:48
  • 1
    `pkg-config` adds all the dependencies for you, so you don't have to mess around with flags or libraries. I'm pretty sure you will get past this problem by using the command I provided (which, by the way, is used MongoDB C Driver tutorial). – Andrejs Cainikovs Nov 05 '18 at 10:52
  • finally got it working with: `gcc -o mongotest mongotest.c $(pkg-config --libs --cflags libmongoc-static-1.0)` – willemx Nov 05 '18 at 13:57
  • Glad to hear! I've updated my answer, so others could potentially save some time. – Andrejs Cainikovs Nov 05 '18 at 14:02