Static linking with libcurl on Windows

Hello

As the title says, I am compiling my own libcurl on Windows and I am trying to import it using Odin’s foreign system. I am currently able to have everything working properly using dynamic linking and placing the .DLL file alongside my built odin executable.

However, in order to use static linking with libcurl, I found this in the documentation

 When building an application that uses the static libcurl library on Windows,
 you must define `CURL_STATICLIB`. Otherwise the linker will look for dynamic
 import symbols.

(...)

 You must specify any additional dependencies needed by your build of static
 libcurl (for example:
 `advapi32.lib;crypt32.lib;normaliz.lib;ws2_32.lib;wldap32.lib`).

I know that I can also link the necessary extra libraries listed there with the import foreign block like so:

	foreign import curl {
		"./libcurl_a.lib"
		"system:advapi32.lib",
		"system:crypt32.lib",
		"system:normaliz.lib",
		"system:ws2_32.lib",
		"system:wldap32.lib",
	}

I am not too sure on how to correctly define CURL_STATICLIB. When I try to use -define:CURL_STATICLIB=1 with the odin build command, it is reported as unused and libcurl is still trying to use functions from the DLL.

Was anyone able to have something similar working?

I think vendor:raylib has an example doing the exact same thing through the RAYLIB_SHARED define.

I can see that the odin code is using this define to choose either the static or dynamic library when using the foreign import system, but would it work the same if the define is used by the library itself?

In my case, I am only interested in importing the static version of the library, it is just that this CURL_STATICLIB define is required by the libcurl code in order to use the staticlly linked symbols instead of the dynamically loaded ones.

I did try adding this to my odin file

CURL_STATICLIB :: #config(CURL_STATICLIB, 1)

and it stops reporting the define as unused so I know it is being pickup up now. However, as far as I can tell, libcurl is still trying to dynamically load external symbols as if this define was not set for the library code, it seems like it is only set on the Odin code side?

I hope I didn’t misunderstand your reply

You are missing that Odin and C defines are completely separate.

libcurl is a C library so you need a C define. On the command line that is -DFOO iirc, but all build systems will have their own way. So to be clear you define that while compiling the C library libcurl.