Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8183241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:06:03+00:00 2026-06-07T01:06:03+00:00

I am building a C application on Linux platform. I need to use libmysqlclient

  • 0

I am building a C application on Linux platform. I need to use libmysqlclient for interfacing to database.

I downloaded Linux source code package mysql-connector-c-6.0.2.tar.gz. I compiled it as per the instructions. I get the below libraries:

libmysqlclient.a     libmysqlclient.so  libmysql.so.16
libmysqlclient_r.so  libmysql.so        libmysql.so.16.0.0

If my application is multi-threaded, can I link my application with libmysqlclient.a? As per mysql documentation (http://forge.mysql.com/wiki/Autotools_to_CMake_Transition_Guide), with cmake tool, clients are always thread safe.

After linking my application with libmysqlclient.a, I get a crash in my application with below call stack:

#0  0x0867878a in my_stat ()
No symbol table info available.
#1  0x08671611 in init_available_charsets.clone.0 ()
No symbol table info available.
#2  0x086720d5 in get_charset_by_csname ()
No symbol table info available.
#3  0x086522af in mysql_init_character_set ()
No symbol table info available.
#4  0x0865266d in mysql_real_connect ()

In my application, I have below code in the thread function:

if (NULL == (pMySQL = mysql_init(NULL)))
{
    return -1;
}

if (NULL == mysql_real_connect(pMySQL, ServerName, UserName, Password, Name, Port, NULL, 0))
{
    mysql_close(pMySQL);
    return -1;  
}

if (0 != mysql_query(pMySQL, pQuery))
{
    mysql_close(pMySQL);
    return -1;
}

mysql_close(pMySQL);

I am not using libmysqlclient_r.so as I want to link to mysql client library statically. Is there any way to generate libmysqlclient_r.a with cmake?

Update:

Without doing anything else, I just changed mysql client build type to debug. Now I get the crash in mysql_init() function.

On the application console, I get below print:

safe_mutex: Trying to lock unitialized mutex at /install/mysqlconnc/mysql-connector-c-6.0.2/mysys/safemalloc.c, line 520

The call stack of the crash is as below:

#0  0x00556430 in __kernel_vsyscall ()
No symbol table info available.
#1  0x45fdf2f1 in raise () from /lib/libc.so.6
No symbol table info available.
#2  0x45fe0d5e in abort () from /lib/libc.so.6
No symbol table info available.
#3  0x086833e5 in safe_mutex_lock (mp=0x915e8e0, my_flags=0, 
    file=0x895b9d8 "/install/mysqlconnc/mysql-connector-c-6.0.2/mysys/safemalloc.c", line=520)
    at /install/mysqlconnc/mysql-connector-c-6.0.2/mysys/thr_mutex.c:178
        error = 140915306
        __PRETTY_FUNCTION__ = "safe_mutex_lock"
#4  0x08682715 in _sanity ( 
    filename=0x895a87c "/install/mysqlconnc/mysql-connector-c-6.0.2/mysys/my_error.c", lineno=195)
    at /install/mysqlconnc/mysql-connector-c-6.0.2/mysys/safemalloc.c:520
        irem = 0xf2300468
        flag = 0
        count = 0
#5  0x0868186b in _mymalloc (size=16,
    filename=0x895a87c "/install/mysqlconnc/mysql-connector-c-6.0.2/mysys/my_error.c", lineno=195, MyFlags=16)
    at /install/mysqlconnc/mysql-connector-c-6.0.2/mysys/safemalloc.c:130
        irem = 0x0
        data = 0x0
        _db_stack_frame_ = {func = 0x6d617266 <Address 0x6d617266 out of bounds>, file = 0x65685f65 <Address 0x65685f65 out of bounds>,
          level = 0, prev = 0x0}
#6  0x0867e0e1 in my_error_register (errmsgs=0x89a7760, first=2000, last=2058)
    at /install/mysqlconnc/mysql-connector-c-6.0.2/mysys/my_error.c:194
        meh_p = 0x46087568
        search_meh_pp = 0x1000
#7  0x08655f7e in init_client_errs ()
    at /install/mysqlconnc/mysql-connector-c-6.0.2/libmysql/errmsg.c:238
No locals.
#8  0x08655fe3 in mysql_server_init (argc=0, argv=0x0, groups=0x0)
    at /install/mysqlconnc/mysql-connector-c-6.0.2/libmysql/libmysql.c:128
        result = 0
#9  0x08651fc0 in mysql_init (mysql=0x0)
    at /install/mysqlconnc/mysql-connector-c-6.0.2/libmysql/client.c:1606

Solution:

I put a call to mysql_library_init() before creation of threads and put a call to mysql_library_end() after termination of threads. In each thread, I put a call to mysql_thread_init() at the start of thread function and put a call to mysql_thread_end() at the end of thread function. This solved the problem of crashing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:06:05+00:00Added an answer on June 7, 2026 at 1:06 am

    Update:

    It seems that you need to call mysql_library_init() before mysql_init():

    You must either call mysql_library_init()
    prior to spawning any threads, or else use a mutex to protect the
    call, whether you invoke mysql_library_init() or indirectly through
    mysql_init(). Do this prior to any other client library call.

    Regarding your original question, libmysqlclient_r.so is actually a symbolic link to libmysql.so. You can change libmysql/CMakeLists.txt to produce a static library (libmysql.a) instead by removing the SHARED keyword from the following line:

    ADD_LIBRARY(libmysql          SHARED ${CLIENT_SOURCES} libmysql.def)
    

    However, I would recommend (1) trying to run the same code without using threads and see if the problem persists, (2) building and using the debug version of the libraries:

    cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug
    make
    

    This way you could investigate the problem in more details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an application for a linux platform in C, with a GTK+2 GUI.
I'm building an application that needs to use the Linux group keyring to share
I'm building an application, which is cross-platform (Linux, Win, OS X), and especially does
I'm building a python application from some source code I've found Here I've managed
I'm building a C++ Linux application and I need to log its activity. What
I am in the process of building a PHP/MySql database application which could have
I want to use an embed an sqlite database into an existing tcl application
I'm building a socket application that need to shuffle a lot of small/medium sized
I'm building an application (both client and sever sides) that may need to send
I am using SFML, and I am building an application in Code::Blocks and mingw32.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.