curl / Mailing Lists / curl-library / Single Mail


How to use libcurl in a plugin loaded by a multi-threaded application?

From: Demi Obenour <>
Date: Thu, 6 Apr 2017 00:12:30 -0400

What is the best way to use libcurl in a plugin, that will be loaded by
an application that has already started multiple threads?

Examples include the JVM and any GTK application.

The problem is that there seems to be no good time to call
curl_global_init(). The docs say that it needs to be called before any
threads are launched – but in this case multiple threads have *already*
been launched by the time the plugin receives control.

Given that curl_global_init() calls thread-unsafe functions in other
libraries, the best idea I could think of is to statically link libcurl
and all dependencies to the maximum extent possible, hide any symbols
that libcurl itself does not export (to ensure that libcurl binds to the
copies in its own dependencies), and call curl_global_init from a static
initializer. That won't work on Windows though.

Is there a solution?


Received on 2017-04-06