Which lib to use? libmariadbclient or libmysqlclient?

后端 未结 1 1520
囚心锁ツ
囚心锁ツ 2021-01-16 12:00

For some unknown reason, my libmysqlclient.a disappeared in my CentOS 7. My program then got linker error, saying cannot find libmysqlclient.

And then I discovered t

相关标签:
1条回答
  • 2021-01-16 12:26

    I had the similar problem when tried to compile my program with "-lmariadbclient" (after apt-get update -lmysqlclient stopped working). The Makefile I used was:

    g++ -std=c++11 *.cpp ../common/*.cpp ../common/*.c -o myprogram -I.. -ldl -Wstack-protector -fstack-protector-all -pthread -ggdb -lssl -lcrypto -lz -lmariadbclient -Wwrite-strings  -fPIC 
    

    I read that commands "-lssl -lcrypto -lz" must be added to fix those errors, but I put them in the wrong place (before lmariadbclient). When I added them after "-lmariadbclient" I was finally able to compile my program:

    g++ -std=c++11 *.cpp ../common/*.cpp ../common/*.c -o myprogram -I.. -ldl -Wstack-protector -fstack-protector-all -pthread -ggdb -lmariadbclient -Wwrite-strings -lssl -lcrypto -lz -fPIC 
    

    UPDATE 22.07.2017:

    I recently tried to compile my program on the new Linux Mint 18.2. Unfortunately I was getting the same compilation errors, and I was unable to fix it with the old method:

    MariaDB version:

     mysql --version
     mysql  Ver 15.1 Distrib 10.2.7-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
    

    Compile errors:

    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
    (.text+0x189): undefined reference to `CRYPTO_num_locks'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
    (.text+0x1a4): undefined reference to `CRYPTO_THREADID_set_callback'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
    (.text+0x1b0): undefined reference to `CRYPTO_set_locking_callback'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
    (.text+0x1b5): undefined reference to `SSL_library_init'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
    (.text+0x1c1): undefined reference to `SSL_load_error_strings'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
    (.text+0x1c6): undefined reference to `OPENSSL_add_all_algorithms_noconf'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
    (.text+0x2a4): undefined reference to `CRYPTO_set_locking_callback'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
    (.text+0x2ab): undefined reference to `CRYPTO_set_id_callback'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
    (.text+0x2cf): undefined reference to `CRYPTO_num_locks'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
    (.text+0x330): undefined reference to `EVP_cleanup'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
    (.text+0x335): undefined reference to `CRYPTO_cleanup_all_ex_data'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
    (.text+0x33a): undefined reference to `ERR_free_strings'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
    (.text+0x33f): undefined reference to `CONF_modules_free'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_init':
    (.text+0x3c1): undefined reference to `SSLv23_client_method'
    /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `my_cb_threadid':
    (.text+0x1e): undefined reference to `CRYPTO_THREADID_set_numeric'
    

    I managed to fix it by changing "-lmariadbclient" to: "-lmariadb". After that I was able to compile my program with no errors. I'm not sure if this solution will work for everyone, but worth to try :)

    My final Makefile is:

    g++ -std=c++11 *.cpp ../common/*.cpp ../common/*.c -o myprogram -I.. -ldl -Wstack-protector -fstack-protector-all -pthread -ggdb -lmariadb -Wwrite-strings -lssl -lcrypto -lz -fPIC 
    

    Good luck!

    0 讨论(0)
提交回复
热议问题