Ubuntu 14.04 gcc-9 link error

Issue #44 resolved
fei shen created an issue
#include <cstdio>
#include <cstring>
#include <zdb/zdb.h>

int main(int agc, char **argv)
{
    URL_T url = URL_new("mysql://localhost/test?user=root&password=swordfish");
    ConnectionPool_T pool = ConnectionPool_new(url);
    ConnectionPool_start(pool);

    Connection_T con = ConnectionPool_getConnection(pool);
    ResultSet_T result = Connection_executeQuery(con,
                                                 "select id, name, image from employee where salary > %d", 1);
    while (ResultSet_next(result))
    {
        int id = ResultSet_getInt(result, 1);
        const char *name = ResultSet_getString(result, 2);
        int blobSize;
        const void *image = ResultSet_getBlob(result, 3, &blobSize);
    }

    ResultSet_T r = Connection_executeQuery(con, "SELECT count(*) FROM users");
    printf("Number of users: %s\n", ResultSet_next(r) ? ResultSet_getString(r, 1) : "no users");
    return 0;
}

g++ -o test main.cpp -std=c++17 -L /usr/lib/ -lzdb  -I /usr/include/zdb

/tmp/ccVuR7v3.o: In the function main:
main.cpp:(.text+0x15): undefined reference to URL_new
/usr/lib//libzdb.so: undefined reference to ‘URL_getUser’
/usr/lib//libzdb.so: undefined reference to ‘Exception_throw’
/usr/lib//libzdb.so: undefined reference to ‘URL_getParameterNames’
/usr/lib//libzdb.so: undefined reference to ‘URL_getParameter’
/usr/lib//libzdb.so: undefined reference to ‘URL_getHost’
/usr/lib//libzdb.so: undefined reference to ‘URL_getPassword’
/usr/lib//libzdb.so: undefined reference to ‘URL_getPath’
/usr/lib//libzdb.so: undefined reference to ‘URL_getPort’
/usr/lib//libzdb.so: undefined reference to ‘URL_getProtocol’
collect2: error: ld returned 1 exit status

Comments (2)

  1. fei shen reporter

    I really like this project, but I can’t understand why compiling and linking are so difficult

  2. Tildeslash repo owner

    Whoever built /usr/lib/libzdb.so must have used the configure switch -enable-zild when building the library which is wrong. This switch is for internal use only. Try to configure and build libzdb.so again without this switch.

    BTW, if you plan to use libzdb with C++, I recommend including zdbpp.h instead of zdb.h. See C++ Examples Doc.

  3. Log in to comment