Thread overview
[Issue 20690] Static LibCurl
Mar 21, 2020
Richard Cattermole
Mar 21, 2020
Mathias LANG
Mar 21, 2020
Jacob Carlborg
Mar 21, 2020
svnpenn@gmail.com
Mar 21, 2020
kinke
Mar 22, 2020
kinke
Dec 17, 2022
Iain Buclaw
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=20690

Richard Cattermole <alphaglosined@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alphaglosined@gmail.com

--- Comment #1 from Richard Cattermole <alphaglosined@gmail.com> ---
The dynamic loading facilities such as dlsym and GetProcAddress can be used to look for symbols in the host executable image.

As per: https://github.com/dlang/phobos/blob/d5dc0115/std/net/curl.d#L4206

It is configured to do this by default, allowing for static linking into the executable.

My guess is that the symbol its looking for has an underscore prepended to its name which is not uncommon. This would cause the issues that you are seeing.

The simplest way to confirm, is to compile curl without the leading underscore or to i.e. objdump its symbol table.

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=20690

Mathias LANG <pro.mathias.lang@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pro.mathias.lang@gmail.com

--- Comment #2 from Mathias LANG <pro.mathias.lang@gmail.com> ---
As Richard mentioned, the first lookup is on the binary itself. Do you have `libcurl.dll` in the folder your binary is in ?

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=20690

Jacob Carlborg <doob@me.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |doob@me.com

--- Comment #3 from Jacob Carlborg <doob@me.com> ---
This is required for iOS derived platforms where "dlopen" is not allowed.

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=20690

--- Comment #4 from svnpenn@gmail.com ---
> My guess is that the symbol its looking for has an underscore prepended to its name which is not uncommon. This would cause the issues that you are seeing.
>
> The simplest way to confirm, is to compile curl without the leading underscore or to i.e. objdump its symbol table.

That sounds promising, but I dont think thats the problem:

~~~
$ objdump -x libcurl.lib | ag curl_global_init
[17](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 curl_global_init
[32](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x000000a0 curl_global_init_mem
0000000000000000 IMAGE_REL_AMD64_ADDR32NB curl_global_init
0000000000000004 IMAGE_REL_AMD64_ADDR32NB curl_global_init
000000000000000c IMAGE_REL_AMD64_ADDR32NB curl_global_init_mem
0000000000000010 IMAGE_REL_AMD64_ADDR32NB curl_global_init_mem
~~~

> As Richard mentioned, the first lookup is on the binary itself. Do you have `libcurl.dll` in the folder your binary is in ?

Have you ever built a D program that uses static LibCurl? Because I find it
hard
to believe what you are saying. I have built hundreds of static Windows
programs
over the years, and the shared libary was never required at runtime or build
time.

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=20690

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke@gmx.net

--- Comment #5 from kinke <kinke@gmx.net> ---
(In reply to Richard Cattermole from comment #1)
> The dynamic loading facilities such as dlsym and GetProcAddress can be used to look for symbols in the host executable image.
> 
> As per: https://github.com/dlang/phobos/blob/d5dc0115/std/net/curl.d#L4206
> 
> It is configured to do this by default, allowing for static linking into the executable.

In that case, the custom static curl library will almost certainly need to be built with a special config, using `__declspec(dllexport)` for the implementations, so that the executable will export the symbols for GetProcAddress() usage.

--
March 22, 2020
https://issues.dlang.org/show_bug.cgi?id=20690

--- Comment #6 from kinke <kinke@gmx.net> ---
(In reply to kinke from comment #5)
> In that case, the custom static curl library will almost certainly need to be built with a special config, using `__declspec(dllexport)` for the implementations, so that the executable will export the symbols for GetProcAddress() usage.

Nope, it's simpler than that - the linker just needs the .exp file (auto-generated when building the DLL, just like the import library) as additional input file when linking the executable (besides the static curl library of course). The executable then features the exports, and std.net.curl works as expected. See https://github.com/ldc-developers/ldc/issues/3376 (incl. a link to a prebuilt package).

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=20690

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--