开发者

Problems converting a C header to D

开发者 https://www.devze.com 2023-02-14 20:11 出处:网络
I\'m trying to translating the MySql C connector 6.02 headers to D, but I get some weird crashes. My guess is I\'ve made some mistakes on translating the structs or function (I\'m not very good at C).

I'm trying to translating the MySql C connector 6.02 headers to D, but I get some weird crashes. My guess is I've made some mistakes on translating the structs or function (I'm not very good at C).

I used implib /system on the libmysql.dll to create a lib file.

I couldn't get htod.exe to work. Using -hs (include system files) complained it couldn't find system files.

Coffimplib.exe didn't have an option to prepend _ to exported internal names.

I couldn't find a free version of coff2omf.

mysql.d is the wrapper. I've included the C definition before each wrapped definition to easier spot bugs. The file includes the mysql dll 开发者_开发技巧and converted libfile too.

When compiling mytest_fails.d it crashes. mytest_works.d only has an assert, and this makes it work.. Compiling mytest_works with -release makes it crash too.

I've been using dmd 2.051

Download mytest.zip from share1t.com

Update: I've also asked some question regarding this on the D.learn newsgroup, but I don't think anyone has gone through the code.

  • C Const
  • Compiler extensions
  • Connot get htod.exe to work
  • The weird crashes


stdcall is a Windows function calling convention (very different from the C calling convention). HTOD failed to mark several functions with extern(Windows). This is normal, since HTOD isn't equipped to handle macros (STDCALL is defined as a macro, I can see that from the leftover comments in msyql.d).

Here's an updated mysql.d file: http://dl.dropbox.com/u/9218759/mysql.d

Now, you need the proper import library in OMF format. I'd generally advise that you do not use implib for this. I've had several problems with it and others have reported having problems using it. Using coffimplib is the way to go. But first, you will need a COFF import library.

If you need it, the Mysql release with the COFF import library can be downloaded from here: http://dev.mysql.com/downloads/mirror.php?id=377977#mirrors (Libraries in DLL form marked for Visual Studio usually come with a COFF import library).

But I'm providing you the translated COFF import library in OMF format here: http://dl.dropbox.com/u/9218759/libmysql.lib

I've tried both of your test cases and they both seem to work fine now. In case of problems, try to check the translated header file again (mysql.d), it's possible that I might have missed to specify all the calling conventions properly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号