Quantcast

Compile Windows dll with MinGW with stdcall calling convention?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Compile Windows dll with MinGW with stdcall calling convention?

Bart Smissaert
This is simple in MSVS, but can't see how this can be done with the MinGW
compiler.
Any idea how this can be done with the sqlite3.c amalgation?

RBS
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compile Windows dll with MinGW with stdcall calling convention?

Cezary H. Noweta
Hello,

On 2017-02-18 17:35, Bart Smissaert wrote:
> This is simple in MSVS, but can't see how this can be done with the MinGW
> compiler.
> Any idea how this can be done with the sqlite3.c amalgation?

I have just tried ``CFLAGS=-mrtd -DSQLITE_CDECL=__cdecl'' option on
different compilers and configurations, but without a success. :-(
``-mrtd'' is not working as good as MSVS' ``-Gz''.

-- best regards

Cezary H. Noweta
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compile Windows dll with MinGW with stdcall calling convention?

Bart Smissaert
I think that something like this should work:

gcc -o SQLite3_StdCall.dll -shared sqlite3.c -s -Wl,--subsystem,windows,--
kill-at

It does compile, but I for some reason I can't access the .dll from VB6.
I had a look at the name mangling and corrected for that, but still no luck.
Maybe best to stick with MSVS.

RBS


On Sun, Feb 19, 2017 at 4:00 PM, Cezary H. Noweta <[hidden email]>
wrote:

> Hello,
>
> On 2017-02-18 17:35, Bart Smissaert wrote:
>
>> This is simple in MSVS, but can't see how this can be done with the MinGW
>> compiler.
>> Any idea how this can be done with the sqlite3.c amalgation?
>>
>
> I have just tried ``CFLAGS=-mrtd -DSQLITE_CDECL=__cdecl'' option on
> different compilers and configurations, but without a success. :-(
> ``-mrtd'' is not working as good as MSVS' ``-Gz''.
>
> -- best regards
>
> Cezary H. Noweta
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compile Windows dll with MinGW with stdcall calling convention?

Keith Medcalf
In reply to this post by Bart Smissaert

Can you tell us how you do it with the amalgamation using MSVS?

> -----Original Message-----
> From: sqlite-users [mailto:[hidden email]]
> On Behalf Of Bart Smissaert
> Sent: Saturday, 18 February, 2017 09:35
> To: General Discussion of SQLite Database
> Subject: [sqlite] Compile Windows dll with MinGW with stdcall calling
> convention?
>
> This is simple in MSVS, but can't see how this can be done with the MinGW
> compiler.
> Any idea how this can be done with the sqlite3.c amalgation?
>
> RBS
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compile Windows dll with MinGW with stdcall calling convention?

Cezary H. Noweta
Hello,

On 2017-02-19 22:25, Keith Medcalf wrote:

> Can you tell us how you do it with the amalgamation using MSVS?

``autoconf'' (containing the same amalgamated ``sqlite3.c'') has the
following options for that task:

-Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall
-DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall

dumpbin sqlite3.dll:

_sqlite3_close@4:
   1000F6F0: 6A 00              push        0
   1000F6F2: FF 74 24 08        push        dword ptr [esp+8]
   1000F6F6: E8 35 B4 05 00     call        1006AB30
   1000F6FB: C2 04 00           ret         4

sqlite3Close:
   1006AB30: 56                 push        esi
     [...]
   1006AB89: 5E                 pop         esi
   1006AB8A: C2 08 00           ret         8

@OP: Another question is why are you trying to transform GCC into CL
instead of to make CL working properly? Such things will give you
nothing more then a lot of new problems including a nuclear launch :-).

-- best regards

Cezary H. Noweta
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compile Windows dll with MinGW with stdcall calling convention?

Cezary H. Noweta
In reply to this post by Bart Smissaert
Hello,

On 2017-02-19 18:31, Bart Smissaert wrote:
> gcc -o SQLite3_StdCall.dll -shared sqlite3.c -s -Wl,--subsystem,windows,--
> kill-at

objdump of SQLite3_StdCall.dll sqlite3_close:

6574f392: 55                   push   %ebp
6574f393: 89 e5                 mov    %esp,%ebp
6574f395: 83 ec 18             sub    $0x18,%esp
6574f398: c7 44 24 04 00 00 00 movl   $0x0,0x4(%esp)
6574f39f: 00
6574f3a0: 8b 45 08             mov    0x8(%ebp),%eax
6574f3a3: 89 04 24             mov    %eax,(%esp)
6574f3a6: e8 ed fe ff ff       call   0x6574f298
6574f3ab: c9                   leave
6574f3ac: c3                   ret

Hopefully GCC is not as clever as CL, in particular it is not wiser then
a programmer, who is using it. Thus, it emits 0xC3 instead of 0xC2,
until you will tell it that you want __stdcall. Still, you have C
calling convention -- not stdcall one. If you do not want to make CL
working, I strongly recommend you to stop playing with GCC and to use
other compiler, for example Open Watcom (1.9 or 2.0):

wcl386 -dSQLITE_CDECL=__cdecl -ecd -bd -bm -l=NT_DLL sqlite3.c

-- best regards

Cezary H. Noweta
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compile Windows dll with MinGW with stdcall calling convention?

Keith Medcalf
In reply to this post by Cezary H. Noweta

On Monday, 20 February, 2017 03:58, Cezary H. Noweta <[hidden email]> said:

> On 2017-02-19 22:25, Keith Medcalf wrote:
 
> > Can you tell us how you do it with the amalgamation using MSVS?
 
> ``autoconf'' (containing the same amalgamated ``sqlite3.c'') has the
> following options for that task:
>
> -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_APICALL=__stdcall
> -DSQLITE_CALLBACK=__stdcall -DSQLITE_SYSAPI=__stdcall

Yes, and I see the defines for those in the sqlite3.c file, but they are not used anywhere ...

That is, I would have expected to see:

SQLITE_API void SQLITE_APICALL sqlite3_.....()

in all the function definitions.  But I don't.  Is there some "special" building of the amalgamation required for these macro's to appear in the function definitions?

rather than use symbol=__stdcall, try using symbol=__attribute__((stdcall))

just as you define SQLITE_API=__declspec(dllexport) to have the APIs exported automatically with no need for a .def file (in fact, the compiler will generate one for you).

Note that __declspec(dllexport) is an alias for __attribute__((dllexport))

See https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Function-Attributes.html





_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compile Windows dll with MinGW with stdcall calling convention?

Cezary H. Noweta
Hello,

On 2017-02-20 20:07, Keith Medcalf wrote:
> Yes, and I see the defines for those in the sqlite3.c file, but they are not used anywhere ...

> That is, I would have expected to see:

> SQLITE_API void SQLITE_APICALL sqlite3_.....()

> in all the function definitions.  But I don't.  Is there some "special" building of the amalgamation required for these macro's to appear in the function definitions?

Yes. They are used while building the amalgamation (``sqlite3.c'',
``sqlite3.h'', ``sqlite3ext.h'') from sources (``-+useapicall'' tcl
script option, ``USE_STDCALL'' nmake macro). You can build the
amalgamation in such a way that those macros will appear.

-- best regards

Cezary H. Noweta
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compile Windows dll with MinGW with stdcall calling convention?

Keith Medcalf

On Monday, 20 February, 2017 14:25, Cezary H. Noweta <[hidden email]> wrote:

> On 2017-02-20 20:07, Keith Medcalf wrote:

> > Yes, and I see the defines for those in the sqlite3.c file, but they are
> not used anywhere ...
 
> > That is, I would have expected to see:
 
> > SQLITE_API void SQLITE_APICALL sqlite3_.....()
 
> > in all the function definitions.  But I don't.  Is there some "special"
> building of the amalgamation required for these macro's to appear in the
> function definitions?
 
> Yes. They are used while building the amalgamation (``sqlite3.c'',
> ``sqlite3.h'', ``sqlite3ext.h'') from sources (``-+useapicall'' tcl
> script option, ``USE_STDCALL'' nmake macro). You can build the
> amalgamation in such a way that those macros will appear.

Ok, but I do not see how to do that.  Visual Studio does not run on Linux, nor does NMAKE and I do not see anything in the regular Makefile which would enable this option (nor anything in configure).

Is it not possible to generate an amalgamation in which these macros appear from a fossil pull onto a Linux machine?




_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Compile Windows dll with MinGW with stdcall calling convention?

Keith Medcalf

Ok, found it by hacking the tcl scripts.  The amalgamation code now has the appropriate macros but when compiled -m64 it works fine but does nothing, when compiled -m32 it spits a cascade of errors.  Same thing using either the __attribute__ or __stdcall ...

> -----Original Message-----
> From: sqlite-users [mailto:[hidden email]]
> On Behalf Of Keith Medcalf
> Sent: Monday, 20 February, 2017 14:52
> To: SQLite mailing list
> Subject: Re: [sqlite] Compile Windows dll with MinGW with stdcall calling
> convention?
>
>
> On Monday, 20 February, 2017 14:25, Cezary H. Noweta <[hidden email]>
> wrote:
>
> > On 2017-02-20 20:07, Keith Medcalf wrote:
>
> > > Yes, and I see the defines for those in the sqlite3.c file, but they
> are
> > not used anywhere ...
>
> > > That is, I would have expected to see:
>
> > > SQLITE_API void SQLITE_APICALL sqlite3_.....()
>
> > > in all the function definitions.  But I don't.  Is there some
> "special"
> > building of the amalgamation required for these macro's to appear in the
> > function definitions?
>
> > Yes. They are used while building the amalgamation (``sqlite3.c'',
> > ``sqlite3.h'', ``sqlite3ext.h'') from sources (``-+useapicall'' tcl
> > script option, ``USE_STDCALL'' nmake macro). You can build the
> > amalgamation in such a way that those macros will appear.
>
> Ok, but I do not see how to do that.  Visual Studio does not run on Linux,
> nor does NMAKE and I do not see anything in the regular Makefile which
> would enable this option (nor anything in configure).
>
> Is it not possible to generate an amalgamation in which these macros
> appear from a fossil pull onto a Linux machine?
>
>
>
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Loading...