digitalmars.D - D interface for C library problems
- Oleg (28/28) Oct 15 2012 Hello everyone.
- Jacob Carlborg (7/27) Oct 15 2012 You need to declare all functions you want to use from C as:
- Oleg (5/10) Oct 15 2012 I have extern wrapper:
- Oleg (2/2) Oct 15 2012 There is code
- 1100110 (18/20) Oct 15 2012 Looks pretty good, haven't tried it or anything yet.
- Jacob Carlborg (6/13) Oct 15 2012 For structs the size only need to be the same. Depending on how you
- 1100110 (5/18) Oct 16 2012 That's what I suspected, but It's nice to know that for a fact.
- denizzzka (3/11) Oct 15 2012 I think you missed a library with err codes and functions. You
Hello everyone. I creating interface for gpgme (http://www.gnupg.org/related_software/gpgme/) and have several problems: 1. Library have variable with D keyword name: /* The version string of the installed engine. */ char *version; How can I create this variable in D interface? 2. Have an error in static function: gpgme_err_code_t gpgme_err_code_from_syserror (void); static inline gpgme_error_t gpgme_error_from_syserror (void) { return gpgme_error (gpgme_err_code_from_syserror ()); } When I write D code like this: gpgme_err_code_t gpgme_err_code_from_syserror(); gpgme_error_t gpgme_error_from_syserror() { return gpgme_error(gpgme_err_code_from_syserror()); } I got error: In function `gpgme_error_from_syserror': src/main.d:(.text.gpgme_error_from_syserror+0x5): undefined reference to `gpgme_err_code_from_syserror' --- errorlevel 1 collect2: ld returned 1 exit status Anyone knows how to fix this? Thanks and sorry for my English.
Oct 15 2012
On 2012-10-15 13:37, Oleg wrote:2. Have an error in static function: gpgme_err_code_t gpgme_err_code_from_syserror (void); static inline gpgme_error_t gpgme_error_from_syserror (void) { return gpgme_error (gpgme_err_code_from_syserror ()); } When I write D code like this: gpgme_err_code_t gpgme_err_code_from_syserror(); gpgme_error_t gpgme_error_from_syserror() { return gpgme_error(gpgme_err_code_from_syserror()); } I got error: In function `gpgme_error_from_syserror': src/main.d:(.text.gpgme_error_from_syserror+0x5): undefined reference to `gpgme_err_code_from_syserror' --- errorlevel 1 collect2: ld returned 1 exit status Anyone knows how to fix this? Thanks and sorry for my English.You need to declare all functions you want to use from C as: extern (C) gpgme_err_code_t gpgme_err_code_from_syserror(); Then you also need to link with the C library. http://dlang.org/interfaceToC.html -- /Jacob Carlborg
Oct 15 2012
On Monday, 15 October 2012 at 11:42:41 UTC, Jacob Carlborg wrote:On 2012-10-15 13:37, Oleg wrote: You need to declare all functions you want to use from C as: extern (C) gpgme_err_code_t gpgme_err_code_from_syserror(); Then you also need to link with the C library. http://dlang.org/interfaceToC.htmlI have extern wrapper: extern (C) { // code here }
Oct 15 2012
On Mon, 15 Oct 2012 06:46:40 -0500, Oleg <gaolong i.ua> wrote:There is code http://pastebin.com/KyhFdx36Looks pretty good, haven't tried it or anything yet. One suggestion that I would make is that you have code like: enum _gpgme_attr_t { ... } alias _gpgme_attr_t gpgme_attr_t; It would probably be better to just use: enum gpgme_attr_t { ... } from the beginning. Also the names of the particular fields do not have to match exactly. In a few C projects, you will find a field with the name 'version' which is a D keyword. It seems to work just fine if you simply change it to 'ver' on similar. Take a look at the deimos project to see a few examples in action. (Also please attempt to get it into deimos if that is what you are thinking about.) -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Oct 15 2012
On 2012-10-16 01:33, 1100110 wrote:Also the names of the particular fields do not have to match exactly. In a few C projects, you will find a field with the name 'version' which is a D keyword. It seems to work just fine if you simply change it to 'ver' on similar. Take a look at the deimos project to see a few examples in action. (Also please attempt to get it into deimos if that is what you are thinking about.)For structs the size only need to be the same. Depending on how you operate on the struct the size of the individual fields, alignment and padding should match as well. -- /Jacob Carlborg
Oct 15 2012
On Tue, 16 Oct 2012 01:42:07 -0500, Jacob Carlborg <doob me.com> wrote:On 2012-10-16 01:33, 1100110 wrote:That's what I suspected, but It's nice to know that for a fact. Thank you. -- Using Opera's revolutionary email client: http://www.opera.com/mail/Also the names of the particular fields do not have to match exactly. In a few C projects, you will find a field with the name 'version' which is a D keyword. It seems to work just fine if you simply change it to 'ver' on similar. Take a look at the deimos project to see a few examples in action. (Also please attempt to get it into deimos if that is what you are thinking about.)For structs the size only need to be the same. Depending on how you operate on the struct the size of the individual fields, alignment and padding should match as well.
Oct 16 2012
On Monday, 15 October 2012 at 11:37:22 UTC, Oleg wrote:I got error: In function `gpgme_error_from_syserror': src/main.d:(.text.gpgme_error_from_syserror+0x5): undefined reference to `gpgme_err_code_from_syserror' --- errorlevel 1 collect2: ld returned 1 exit status Anyone knows how to fix this? Thanks and sorry for my English.I think you missed a library with err codes and functions. You should used -L compiler flag or pragma(lib, "nameoflib");
Oct 15 2012