Can someone help me with the task of compiling a d...
# kotlin-native
p
Can someone help me with the task of compiling a dynamic lib using mingwx64. What I tried so far is this:
Copy code
dlltool.exe -d test.def -l test.lib.a
This gives me a static lib loader (as far as I can understand) Now I need to compile it using gcc:
Copy code
gcc main.c -o main -L. -ltest
This works and returns main.exe. However when I execute it I get this error:
Copy code
---------------------------
main.exe - System Error
---------------------------
The code execution cannot proceed because (null).DLL was not found. Reinstalling the program may fix this problem. 
---------------------------
OK   
---------------------------
a
Hello, @Patrick! Can you please tell if this is Kotlin/Native related? If so, why won’t you just create dynamic library using
-p dynamic
compiler flag?
p
Yes this is Kotlin Native related. I tried to follow the tutorial for compiling it with MSVC but as far as I understand it MSVC support has been deprecated in 1.3.70. That's why I'm trying it with mingwx64. Where should I add this compiler flag?
The documentation https://kotlinlang.org/docs/tutorials/native/dynamic-libraries.html still uses MSVC, I opened an issue
Ok, apparently there is a workaround https://youtrack.jetbrains.com/issue/KT-39258
👍 1
Yeah the workaround does not work for me, I get the error message described in the issue
I'm not sure if this is expected. I assume it is
Also it would be helpful to understand what a "vectory-typed kotlin function" is so I can identify it in my code and remove it if necessary
a
AFAIK, it could be found across your generated headers. If there are no such functions in it, please post a note on it in the ticket you found.
p
I have this line in my header
typedef float __attribute__ ((__vector_size__ (16))) nimmstaWindows_KVector128;
Does this mean I can't export the code as a dynamic library until the bug is fixed?
s
Also it would be helpful to understand what a “vectory-typed kotlin function” is so I can identify it in my code and remove it if necessary
Exact quote from the issue:
if your C/C++ code uses vector-typed Kotlin functions (which have 
${prefix}_KVector128
 in their signature in generated C header
Does this mean I can’t export the code as a dynamic library until the bug is fixed?
No, it doesn’t. You can apply the workaround described in the issue.
p
Hmm well I applied the workaround in the issue which allows me to compile a binary. But when I execute the binary I get this error: --------------------------- main.exe - Entry Point Not Found --------------------------- The procedure entry point nimmstaWindows_symbols could not be located in the dynamic link library C:\Users\Patrick\Documents\nimmsta-shared-lib\main.exe. --------------------------- OK ---------------------------
As I mentioned everything (except the code that produced the shared lib) is the same and it worked exactly like this using a previous version of Kotlin Native
Is there anything else I need to do to get it to work?
Is this because of this issue:
Note: after applying this workaround, your program will crash if your C/C++ code uses vector-typed Kotlin functions (which have ${prefix}_KVector128 in their signature in generated C header).
This shouldn't be a problem because I am not using it in my C code, correct?
My file just looks like this:
Copy code
#include "nimmstaWindows_api.h"

int main(int argc, char** argv) {
    nimmstaWindows_ExportedSymbols *lib = nimmstaWindows_symbols();
}
I ran this command:
Copy code
lib /def:nimmstaWindows.def /out:nimmstaWindows.lib
and then this command:
Copy code
cl.exe main.c nimmstaWindows.lib
that's it
s
Is this because of this issue: 
Note: after applying this workaround, your program will crash if your C/C++ code uses vector-typed Kotlin functions (which have ${prefix}_KVector128 in their signature in generated C header).
Unlikely.
This shouldn’t be a problem because I am not using it in my C code, correct?
Exactly.
Is there anything else I need to do to get it to work?
We have to reproduce the issue on our side first.
p
Should I try to create a minimal reproducer?
Could take some time though since the project is quite large
a
No, I went through all steps you described, but was unable to get an error like yours. I made a sample dll, used
lib.exe
from Visual studio build tools, and used the result .lib file in a simple c file, similar to the one you’ve posted above:
Copy code
#define __attribute__(x)
#include "kotlinlib_api.h"
int main(int argc, char** argv) {
    kotlinlib_ExportedSymbols *lib = kotlinlib_symbols();
}
. For some reason, it works fine.
p
I think it has something to do with the source sets
I am on it now
Can you try this:
Copy code
commonMain {
            dependencies {
                implementation(kotlin("stdlib-common"))
                implementation("com.github.msink:libui:0.1.7")
            }}
đź‘€ 1
Same error?
I noticed that this dependency is not used in the project anymore. Could this have something to do with the error message?
a
To be fair, I was unable to reproduce the error with all info I’ve got for now. If it’s possible, please try to minimize the project and post it with build instructions on the YT ticket.
p
I can do that, sure. My project now only consists of one class that I only need so I can even run the export (interestingly the export still works but produces an invalid .h file) and this one dependency, nothing else. If I remove the dependency the problem goes away.
🙏 1