November 12, 2022

On Wednesday, 9 November 2022 at 15:00:39 UTC, Don Allen wrote:

>

On Monday, 7 November 2022 at 22:05:38 UTC, Walter Bright wrote:

>

https://news.ycombinator.com/item?id=33509223

I'm old enough to know that when something seems to be too good to be true, it's probably too good to be true. Unfortunately, I missed this one; my amazement at "how easy it was" was caused by my own error. When I made the first attempt to build my application using ImportC, I had failed to remove my old gtk.d file from the source directory. That is the file that contains all my hand-coded definitions I spoke of in my original post. So the imports of gtk in my source files saw that file and so I was unknowingly repeating my old build method without any use of ImportC.

When I removed that file and tried to rebuild, life got more complicated.

My first issue was that I don't believe that my interpretation of Walter's statement (in his post to ycombinator news) was correct -- I don't think you can directly include C header files in D code. I now believe that the documentation in 41.3.2 is correct.

Once I came to that realization, I created a gtk.c file in a place visible to my source files containing just one line:

#include <gtk/gtk.h>

and then arranged for the clang pre-processor to produce a gtk.i file from it, using the standard pkg-conf method to tell Clang where all the gtk header-file directories are. The 'import gtk's in my D source files now see the gtk.i file and so I am now actually using ImportC, rather than imagining it. The problem is that it produces many errors, due to the expansion of gtk.h generating a lot of C that ImportC doesn't understand.

I tried modifying my gtk.c in an attempt to work around some of the problems, using #defines, a technique suggested in Walter's documentation. This helped, but ultimately, it just kicks the can down the road. The fundamental problem is that the expansion of gtk.h is extremely complex and, crucially, makes use of gcc and/or clang extensions that I could not work around; they are just too far from C11 or too difficult to modify. So to continue to use D, I will have to revert to my original method for dealing with gtk.

I don't think this experience invalidates the ImportC idea, because it seems very clear that gtk is an extreme case. In fact, my application also uses sqlite and I am going to try to use ImportC to deal with that. My hope is that the sqlite header files generate code closer to the C that ImportC supports. What I've learned from the experience I've just described will allow me to test that theory pretty quickly. I will let you know how that goes.

I did see one possible issue that may be worthy of a bug report. I need to investigate this one further and will write the report if I think it's a real problem.

November 12, 2022

On Saturday, 12 November 2022 at 04:36:33 UTC, confuzzled wrote:

>

Don, do you mind helping me out a little? I'm trying to link up to and compile an xlsxio example and am making no progress. The linker is not finding all the libraries. I'm currently hunting down each one and copying them into my working directory and inserting a progma(lib, "libname.a") statement for each. After adding each one, it spits out another set of undefined symbols. Somehow this just feels like I'm doing something wrong but am not sure what.

I would appreciate any assistance/guidance you can provide.

Thanks,
confuzzled!!!

I'd be happy to try to help, but need a lot more detail about what you are doing and I think it would be best to take this offline. The forum software claims you can get at my email address. Why don't you send me a private message with relevant files attached?

/Don

November 12, 2022
On Monday, 7 November 2022 at 22:05:38 UTC, Walter Bright wrote:
> https://news.ycombinator.com/item?id=33509223

Back to the original article.

https://faultlore.com/blah/c-isnt-a-language/

The discussion is that C is the lingua franca when it comes FFI. This is of course a very limited interface, non standard and full of special cases.

Isn't there a room for a common FFI language. Similar to LLVM is some kind intermediate language for code generation, why not an intermediate language that describes interoperability?

In such language, the exact memory layout of types can be described, the type of calling convention etc.. Instead of supporting each language, the language could emit a common FFI format instead so that other languages can import it.

I have personally never seen such attempt, but I really think that could be an interesting project. Maybe you have seen any previous attempt?
November 12, 2022
On 11/12/2022 7:35 AM, Don Allen wrote:
> I tried modifying my gtk.c in an attempt to work around some of the problems, using #defines, a technique suggested in Walter's documentation. This helped, but ultimately, it just kicks the can down the road. The fundamental problem is that the expansion of gtk.h is extremely complex and, crucially, makes use of gcc and/or clang extensions that I could not work around; they are just too far from C11 or too difficult to modify.
Thank you for the correction.

There are an endless number of C extensions, every C compiler does their own thing with this. We've implemented a number of popular ones. We don't want to waste time implementing ones that don't matter to our users.

I'd like to take a stab at the ones gtk needs. If you could please post them to bugzilla, tagging them with the ImportC keyword, we can have a look at the feasibility of implementing them.
November 13, 2022
On Thursday, 10 November 2022 at 17:10:22 UTC, confuzzled wrote:
> Attempts to use the .h file from xlsxio still doesn't work though. Assuming it's in master though. Will this be included in the 2.101.0 release?

Walter has now implemented this in master:
https://issues.dlang.org/show_bug.cgi?id=23479

I'm not sure if it will make the next release.
November 14, 2022
On Saturday, 12 November 2022 at 18:18:13 UTC, Walter Bright wrote:
> On 11/12/2022 7:35 AM, Don Allen wrote:

>
> I'd like to take a stab at the ones gtk needs. If you could please post them to bugzilla, tagging them with the ImportC keyword, we can have a look at the feasibility of implementing them.

Done.
November 26, 2022

On Saturday, 12 November 2022 at 16:13:37 UTC, Don Allen wrote:

>

On Saturday, 12 November 2022 at 04:36:33 UTC, confuzzled wrote:

>

Don, do you mind helping me out a little? I'm trying to link up to and compile an xlsxio example and am making no progress. The linker is not finding all the libraries. I'm currently hunting down each one and copying them into my working directory and inserting a progma(lib, "libname.a") statement for each. After adding each one, it spits out another set of undefined symbols. Somehow this just feels like I'm doing something wrong but am not sure what.

I would appreciate any assistance/guidance you can provide.

Thanks,
confuzzled!!!

I'd be happy to try to help, but need a lot more detail about what you are doing and I think it would be best to take this offline. The forum software claims you can get at my email address. Why don't you send me a private message with relevant files attached?

/Don

Don,

My apologies for not responding earlier. I ran with the explanation given by Mike and Andrey in this thread:

https://forum.dlang.org/post/ombwclqltsghqnjqraju@forum.dlang.org

I was able to get the library built and actually compiled the program. Turns out the .configure script for xlsxio builds a wonky makefile on osx and wasn't locating all the libraries because it was looking in the wrong place. After a whole lot of manual configuration I got it to build and produce a .dylib file which I linked against without issues from D.

I'm not sure if I did everything correctly though. While the example can spit out the names of all sheets in a workbook, I cannot get it to display the content of any of the sheets. This issue appears in both the original code and the D adoption. I'm wondering what I could have done wrong when I changed the makefile but haven't gone back to try and figure it out as yet.

Just wanted to say thanks for your assistance.

confuzzled!!!

November 26, 2022

On Saturday, 12 November 2022 at 16:13:37 UTC, Don Allen wrote:

>

On Saturday, 12 November 2022 at 04:36:33 UTC, confuzzled wrote:

>

Don, do you mind helping me out a little? I'm trying to link up to and compile an xlsxio example and am making no progress. The linker is not finding all the libraries. I'm currently hunting down each one and copying them into my working directory and inserting a progma(lib, "libname.a") statement for each. After adding each one, it spits out another set of undefined symbols. Somehow this just feels like I'm doing something wrong but am not sure what.

I would appreciate any assistance/guidance you can provide.

Thanks,
confuzzled!!!

I'd be happy to try to help, but need a lot more detail about what you are doing and I think it would be best to take this offline. The forum software claims you can get at my email address. Why don't you send me a private message with relevant files attached?

/Don

Don,

My apologies for not responding earlier. I ran with the explanation given by Mike and Andrey in this thread:

https://forum.dlang.org/post/ombwclqltsghqnjqraju@forum.dlang.org

I was able to get the library built and actually compiled the program. Turns out the .configure script for xlsxio builds a wonky makefile on osx and wasn't locating all the libraries because it was looking in the wrong place. After a whole lot of manual configuration I got it to build and produce a .dylib file which I linked against without issues from D.

I'm not sure if I did everything correctly though. While the example can spit out the names of all sheets in a workbook, I cannot get it to display the content of any of the sheets. This issue appears in both the original code and the D adoption. I'm wondering what I could have done wrong when I changed the makefile but haven't gone back to try and figure it out as yet.

Just wanted to say thanks for your assistance.

confuzzled!!!

November 26, 2022
On 11/14/2022 8:56 AM, Don Allen wrote:
> Done.

good!
March 21, 2023

On Saturday, 12 November 2022 at 15:35:03 UTC, Don Allen wrote:

>

On Wednesday, 9 November 2022 at 15:00:39 UTC, Don Allen wrote:

>

On Monday, 7 November 2022 at 22:05:38 UTC, Walter Bright wrote:

>

https://news.ycombinator.com/item?id=33509223

Once I came to that realization, I created a gtk.c file in a place visible to my source files containing just one line:

#include <gtk/gtk.h>

and then arranged for the clang pre-processor to produce a gtk.i file from it, using the standard pkg-conf method to tell Clang where all the gtk header-file directories are. The 'import gtk's in my D source files now see the gtk.i file and so I am now actually using ImportC, rather than imagining it. The problem is that it produces many errors, due to the expansion of gtk.h generating a lot of C that ImportC doesn't understand.

I tried modifying my gtk.c in an attempt to work around some of the problems, using #defines, a technique suggested in Walter's documentation. This helped, but ultimately, it just kicks the can down the road. The fundamental problem is that the expansion of gtk.h is extremely complex and, crucially, makes use of gcc and/or clang extensions that I could not work around; they are just too far from C11 or too difficult to modify. So to continue to use D, I will have to revert to my original method for dealing with gtk.

Hi Don,

I've looked at this thread for a while now and made several attempts at getting it to work. Unfortunately, my experience with ImportC follows exactly what you describe.

I'm actually more curious about the details of how you originally worked with gtk in D. I've tried the same method with some success but its not entirely obvious how you deal with certain cases. For example, g_signal_connect is actually a macro for calling another function with specific parameters. That seems to have no direct equivalent in D.