search

Home  >  Q&A  >  body text

How do I link to a custom library when building MySQL server from source?

I installed MySQL server using the standard source distribution (mysql-server-8.0) according to: https://dev.mysql.com/doc/refman/8.0/en/installing-source-distribution.html. For some purpose I added some code to the MySQL source code in mysql-server-8.0/sql/mysqld.cc and the code I added uses /usr/lib Custom .so library in .

I wanted to link to this library when building MySQL source code, so when I built MySQL I used the following command:

cmake .. -DWITH_BOOST=/home/ubuntu/mysql-server-8.0/boost \
         -DCMAKE_C_FLAGS="-lmy_lib_name -L/usr/lib" \
         -DCMAKE_CXX_FLAGS="-lmy_lib_name -L/usr/lib" \
         -DCMAKE_C_LINK_FLAGS="-lmy_lib_name -L/usr/lib" \
         -DCMAKE_CXX_LINK_FLAGS="-lmy_lib_name -L/usr/lib" \
         -DCONFIG_CLIENT_LIBS="-lmy_lib_name -L/usr/lib" \
         -DCONFIG_LIBS_PRIVATE="-lmy_lib_name -L/usr/lib" \
         -DCMAKE_EXE_LINKER_FLAGS="-lmy_lib_name -L/usr/lib" \
         -DCMAKE_MODULE_LINKER_FLAGS="-lmy_lib_name -L/usr/lib" \
         -DCMAKE_SHARED_LINKER_FLAGS="-lmy_lib_name -L/usr/lib" \
make

Although I tried adding the flag when compiling and linking, the build failed to complete, reporting error: undefined reference to 'symbols in my library' . Is there any way to make it work? Thanks!

P粉087951442P粉087951442244 days ago418

reply all(1)I'll reply

  • P粉976737101

    P粉9767371012024-04-02 13:27:24

    Thank you for your comment! I discovered that I was not using C correctly in the .cc source file. It should be noted that in the .cc file, the usage of the C header file should be as follows:

    extern "C" {
      #include "mylib.h"
    }

    So the linking process is running fine. The compiler didn't recognize the function signature because I misused the library header in the .cc file.

    reply
    0
  • Cancelreply