'How can I link to a custom library when building MySQL Server from source?

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

I want to link to this library when building MySQL source code, so when I built MySQL, I used following commands:

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 to add flag when compiling and linking, it failed to complete building, reporting that error: undefined reference to 'symbols in my library' . Is there any way to make it work? Thanks!



Solution 1:[1]

Thanks for your comments! I found that I didn't correctly use C in .cc source file. It should be noticed that in .cc file C headers should be used like:

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

So the linking procedure worked fine. The compiler can't identify the function signature because of my misuse of the library headers in .cc file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hsyhhh