Search code examples
c++g++maxmind

C++ / G++ Maxmind geolite2++ third party shared object undefined reference


I posted this question yesterday which was marked as a duplicate, after reading the original I was able to get my compile to go a bit further. (Will delete the linked question once I've got this resolved or given up).

Now I have two g++ commands compiling to a .o file but remain with the undefined reference errors regarding a third party .so that I obtained from this library (geolite2++).

Here are my compile commands:

sudo g++ -std=c++11 -I/home/ubuntu -L/home/ubuntu -g -lstdc++ -lgeolite2++ -c -O2 -MMD -MP -MF "main.o.d" -o main.o main.cpp

(appears to work)

sudo g++ -std=c++11 -L/home/ubuntu -I/home/ubuntu -pthread -g -o main main.o -lstdc++ -lgeolite2++ -lz -ldl

(generates the following errors)

/home/ubuntu/libgeolite2++.so: undefined reference to `MMDB_lookup_string'
/home/ubuntu/libgeolite2++.so: undefined reference to `MMDB_free_entry_data_list'
/home/ubuntu/libgeolite2++.so: undefined reference to `MMDB_open'
/home/ubuntu/libgeolite2++.so: undefined reference to `MMDB_strerror'
/home/ubuntu/libgeolite2++.so: undefined reference to `MMDB_lib_version'
/home/ubuntu/libgeolite2++.so: undefined reference to `MMDB_aget_value'
/home/ubuntu/libgeolite2++.so: undefined reference to `MMDB_get_entry_data_list'
/home/ubuntu/libgeolite2++.so: undefined reference to `MMDB_get_metadata_as_entry_data_list'
/home/ubuntu/libgeolite2++.so: undefined reference to `MMDB_close'
collect2: error: ld returned 1 exit status

I've done more research and read here (answer by Dmitry Yudakov) that I can use the ldd command to see if the /home/ubuntu/libgeolite2++.so shared object has found it's dependencies. My output indicates this isn't the case:

ldd /home/ubuntu/libgeolite2++.so
        linux-vdso.so.1 =>  (0x00007ffe7fae1000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fb281442000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb28122c000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb280e64000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb280b5e000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fb2819d6000)

Here is my programs code:

#include <cstdlib>
#include <iostream>

#include <GeoLite2PP.hpp>
#include <GeoLite2PP_error_category.hpp>
#include <GeoLite2PP_version.hpp>

using namespace std;
using namespace GeoLite2PP;

int main(int argc,char* argv[]) {

    GeoLite2PP::DB db( "./GeoIP2-City.mmdb" );
    std::string json = db.lookup( "216.58.216.163" );
    std::cout << json << std::endl;
}

As such my question is, is this a problem with the /home/ubuntu/libgeolite2++.soshared library that's my fault or is it a problem with the library? Is the answer to be found in the duplicate of my original question (link above) or is it something else? Apologies in advance if this question is very newbie, but I am a bit out of my depth. Thanks in advance for any help.

Regards,

James


Solution

  • Googling those undefined symbols, it seems libgeolite2++ has an undeclared (and undocumented) dependency on libmaxminddb.

    Since it's undeclared, ldd is of no help; however, even it were declared, you'd still need to link that other dependency into your executable.

    You can dive into installing and linking that dependency, and/or you can talk to the author of libgeolite2++.