Hi, I'm new to kotlin-native and trying to underst...
# kotlin-native
f
Hi, I'm new to kotlin-native and trying to understand if I'm able to interact with a DLL on a windows environment. To understand if it is possible (it seems so) I've built curl from source (to get a sample DLL, I'm going to work with a different one on the actual project) and linked it in my project following what is done on ktor-client-curl. Something seems to work as I am able to build the project and some klibs (e.g. http-client-cinterop-libcurl.klib) are generated. Build starts failing when i try to call some method from the DLL, for example in my main method I call:
Copy code
curl_easy_init()
When this line is added I get this error on build:
Copy code
The C:\Users\Francesco\.konan\dependencies\llvm-11.1.0-windows-x64-essentials/bin/clang++ command returned non-zero exit code: 1.
output:
lld: error: unable to find library -lcurl
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
This is my libcurl.def:
Copy code
package = libcurl
headers = curl.h
headerFilter = *
linkerOpts.mingw_x64 = -LC:/msys64/mingw64/lib -LC:/Tools/msys64/mingw64/lib -lcurl -L/opt/homebrew/opt/curl/include/curl
compilerOpts.mingw_x64 = -IC:/msys64/mingw64/include/curl -IC:/Tools/msys64/mingw64/include/curl
Please let me know if someone has some clues on how to get it working or if I can provide more information. Thanks. This is a repo with my current project: https://github.com/francescopedronomnys/kotlin-native-libcurl-dll Something that I find strange is that this is part of libcurl.def as defined on ktor-client-curl:
Copy code
linkerOpts.mingw_x64 = -LC:/msys64/mingw64/lib -LC:/Tools/msys64/mingw64/lib -LC:/Tools/msys2/mingw64/lib -lcurl -L/opt/homebrew/opt/curl/include/curl
compilerOpts.mingw_x64 = -I/usr/include/curl -I/usr/include/x86_64-linux-gnu/curl -I/opt/homebrew/opt/curl/include/curl
I do not understand if those paths on
compilerOpts.mingw_x64
are correct or just a copy/paste error, to me they don't look like Windows paths and so on my libcurl.def I've set the path where curl's dll, lib and headers are (
C:/Tools/msys64/mingw64
)
m
AFAIK if you have in .def file: -LC:/Tools/msys64/mingw64/lib -lcurl linker will look for C:/Tools/msys64/mingw64/lib/libcurl.dll.a import library.
f
Hello @msink I have no
libcurl.dll.a
, this is what I have inside lib folder:
Copy code
Directory: C:\Tools\msys64\mingw64\lib


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        12/01/2022     17:46          11415 libcurl.exp
-a----        12/01/2022     17:46          19226 libcurl.lib
What I tried to do now is changing
-lcurl
to
-llibcurl
inside .def file and it works! Let me know if it makes sense to you. Here's the commit that made it work: https://github.com/francescopedronomnys/kotlin-native-libcurl-dll/commit/3b1ffbd5cdc9beb394d3dfbc5171e71f962f01d7 I also found out that I have to put libcurl.dll in
Copy code
C:\Windows\System32
to make it work at runtime, otherwise the exe will exit immediately.
m
Your
libcurl.lib
is import library for
libcurl.dll
? Then AFAIK what should work in your case is
-l:libcurl.lib
-llibcurl
is something weird... then linker should look for
liblibcurl.a
or something similar.
About
.dll
- in runtime it should be in same folder with
.exe
, or somewhere in system PATH
f
Thank you very much! I can confirm both
-l:libcurl.lib
instead of
-llibcurl
and the hint about the
.dll
in the same folder as exe.