V
V
Vadim Ushakov2017-10-31 14:49:08
MinGW
Vadim Ushakov, 2017-10-31 14:49:08

Windows compatible dll built with gcc, is it real?

In general, the essence is this, there is some source code for a library written under Linux.
After building under Windows using mingw, we get a supposedly ready-made module for use in the lua environment.
But, lua does not understand this module as a dll.
The command to build an object file from source.

$ gcc -c *.c -I../include -I../klib -I../uthash -I../src -I./luah

Executable build command
$ gcc -shared -o ucl.dll lua_ucl.o -L. -llua51 -lucl

As a result, we get the output file ucl.dll. That seems to be done, but what's the problem?
But in what, when loading this library as a module for lua, namely, when calling LoadLibrary, an error occurs as if the module was not found. But the error is not that require cannot physically find the module, but that ucl.dll is not defined as a dynamic link library! Prompt knowing people how it is possible to force LoadLibrary to understand ucl.dll as a library?
The project itself is taken from here https://github.com/vstakhov/libucl/
For comparison, two screenshots of the file headers
1. ucl.dll
5z_-BsprTBW9csdnibHPcQ.png
2. utf8.dll (working, fully defined and can be used)
VdP0l8l8SiK7vBWhzm-EqQ.png
We see that for the first option Dll Characteristics is not defined or null, and for the second option the subsystem is defined as Win32 Gui instead of Win32 Console. Therefore, the conclusion suggests itself, gcc builds the program not as a dll, but as an application, so LoadLibrary cannot load this application. Is there any solution to this problem? Perhaps you need to specify flags unknown to me when building the application through gcc, or patch the output file so that it is defined as a dll library, but I don’t know how to do this yet.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
theg4sh, 2018-10-24
@theg4sh

It's worth trying to add the `-shared` flag to the object assembly as well.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question