title: Kotlin/Native Windows cinterop using built library dll
body: <p>I am using Windows to follow the Kotlin-Native libcurl example here <a href="https://kotlinlang.org/docs/tutorials/native/curl.html" rel="nofollow noreferrer">https://kotlinlang.org/docs/tutorials/native/curl.html</a></p>
  <p>Unfortunately, this has been a bigger challenge then I could have imagined. I have been learning how to compile C binaries on windows from source using tools such as CMake and have followed this tutorial to build libcurl on Windows: <a href="https://jonnyzzz.com/blog/2018/10/29/kn-libcurl-windows/" rel="nofollow noreferrer">https://jonnyzzz.com/blog/2018/10/29/kn-libcurl-windows/</a></p>
  <p>After quite a few days of trial and error with the .def file for cinterop on Windows, and using compilerOpts to point to my header file for curl in my built library, I have hit a brick wall.</p>
  <p>I can't seem to get Gradle to recognize the dll file. Task ':linkDebugExecutableMingw' keeps failing. I have no idea where I am supposed to put the dll file. I have tried putting it in to the build output folder next to the exe, but it still fails to compile, with this error:</p>
  <pre><code>C:\Users\yous\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1\bin\ld: C:\Users\yous\AppData\Local\Temp\konan_temp6326583690522756621\result.o:out:(.rdata$.refptr.knifunptr_sample35_curl_easy_strerror[.refptr.knifunptr_sample35_curl_easy_strerror]+0x0): undefined reference to `knifunptr_sample35_curl_easy_strerror'
  </code></pre>
  <p>And a similar list of header file errors, then the final message is:</p>
  <pre><code>e: C:\Users\yabde\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1/bin/clang++ invocation reported errors
  </code></pre>
  <p>This is after I succesfully located the header files. I believe this is an issue with the dll file not being included.</p>
  <p>Here is my relevant Gradle build script:</p>
  <pre><code>mingwX64(&quot;mingw&quot;) {
          compilations.main {
              cinterops {
                  libcurl {
                      // Def-file describing the native API.
                      // The default path is src/nativeInterop/cinterop/&lt;interop-name&gt;.def
                      defFile project.file(&quot;src/nativeInterop/cinterop/libcurl.def&quot;)
  
                      // Package to place the Kotlin API generated.
                      packageName 'libcurl'
  
                      // Options to be passed to compiler by cinterop tool.
                      compilerOpts '-Isrc\\nativeInterop\\cinterop\\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\\include -o libcurl'
                      //linkerOpts '-Isrc\\nativeInterop\\cinterop\\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\\bin'
  
                      // Directories for header search (an analogue of the -I&lt;path&gt; compiler option).
                      //includeDirs.allHeaders(&quot;path1&quot;, &quot;path2&quot;)
  
                      // Additional directories to search headers listed in the 'headerFilter' def-file option.
                      // -headerFilterAdditionalSearchPrefix command line option analogue.
                      includeDirs.headerFilterOnly(&quot;src/nativeInterop/cinterop/libcurl-vc-x86-release-dll-ipv6-sspi-winssl/include&quot;)
  
                      // A shortcut for includeDirs.allHeaders.
                      //includeDirs(&quot;include/directory&quot;, &quot;another/directory&quot;)
                  }
              }
          }
          binaries {
              executable {
                  // Change to specify fully qualified name of your application's entry point:
                  entryPoint = 'sample.main'
                  // Specify command-line arguments, if necessary:
                  //runTask?.args('-Lsrc/nativeInterop/cinterop/libcurl-vc-x86-release-dll-ipv6-sspi-winssl/bin')
                  runTask?.args('')
              }
          }
      }
  </code></pre>
  <p>I believe this issue may be with linker options to locate the dll, but uncommenting the linkerOpts line does not help.</p>
  <p>I think I have given up on Kotlin/Native and will be sticking to C for data-oriented native programming...</p>
  <p><strong>EDIT:</strong>
  <strong>Also, note that any text commented out is things that I have attempted</strong>
  Ok so, this is my def file:</p>
  <pre><code>headers = curl/curl.h
  headerFilter = curl/*
  
  compilerOpts.linux = -I/usr/include -I/usr/include/x86_64-linux-gnu
  
  linkerOpts.osx = -L/opt/local/lib -L/usr/local/opt/curl/lib -lcurl
  linkerOpts.linux = -L/usr/lib/x86_64-linux-gnu -lcurl
  linkerOpts.mingw = -Llibcurl-vc-x86-release-dll-ipv6-sspi-winssl/lib
  </code></pre>
  <p>Ok so, this is my project structure:</p>
  <p><a href="https://i.stack.imgur.com/cHZOV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cHZOV.jpg" alt="structure" /></a></p>