November 10, 2022

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

>

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

So I read the responses to this post along with the ImportC documentation and was excited to try this out. I first copied hello.c from the docs and attempted to compile it with dmd. The result:

dmd hello.c
hello.c(1): Error: C preprocessor directive `#include` is not supported
hello.c(1): Error: no type for declarator before `#`
hello.c(5): Error: no type for declarator before `return`
hello.c(6): Error: no type for declarator before `}`

Hmm... that didn't work. No idea how to fix that either. Let me try the next example. Output:

dmd demo.d square.c
demo.d(6): Error: function expected before `()`, not `module square` of type `void`

That didn't work either. But if I replace the call to square() on line 6 with square.square(), it works fine.

Now, let's try an actual library. First clone xlsxio from github and run cd xlsxio; make install. Next create demo.d:

import xlsxio_read;

void main()
{

}

and compile it (I copied the header file into the root project directory):

dmd demo.d xlsxio_read.h libxlsxio_read.a
Error: unrecognized file extension h

Hmmm... What am I missing?

Thanks,
confuzzled!!!

November 10, 2022
On Thursday, 10 November 2022 at 16:25:34 UTC, confuzzled wrote:
> hello.c(1): Error: C preprocessor directive `#include` is not supported

This only works on the dmd master (and maybe the latest beta). It hasn't been formally released yet.

November 10, 2022
On Thursday, 10 November 2022 at 16:40:57 UTC, Adam D Ruppe wrote:
> On Thursday, 10 November 2022 at 16:25:34 UTC, confuzzled wrote:
>> hello.c(1): Error: C preprocessor directive `#include` is not supported
>
> This only works on the dmd master (and maybe the latest beta). It hasn't been formally released yet.

Okay, awesome. Installed v2.101.0-rc.1 and the first example now compiles without issues. 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?

Thanks,
confuzzled!!!
November 10, 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.

I'm actually not sure about that but I don't think it will.

The way it works right now si you make a little .c file that just #include's the .h file you want, then pass that .c file to the compiler.

November 10, 2022
On Thursday, 10 November 2022 at 17:18:27 UTC, Adam D Ruppe wrote:
> 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.
>
> I'm actually not sure about that but I don't think it will.
>
> The way it works right now si you make a little .c file that just #include's the .h file you want, then pass that .c file to the compiler.

Sweet. That'll work for now. Thanks Adam.

confuzzled!!!
November 11, 2022
On Wednesday, 9 November 2022 at 21:00:11 UTC, Walter Bright wrote:
> On 11/9/2022 10:54 AM, Don Allen wrote:
>> Not too surprisingly, given how new ImportC is, more testing *has* resulted in problems. I'll have more to say if/when I better understand the issue(s).
>
> Please post any problems to bugzilla, and tag them with ImportC. Thanks!

I will. I'm still working on trying to sort this out (with limited time at the moment), so that if a bugzilla report is appropriate, it will be useful.
November 11, 2022

On Friday, 11 November 2022 at 15:04:36 UTC, Don Allen wrote:

>

On Wednesday, 9 November 2022 at 21:00:11 UTC, Walter Bright wrote:

>

On 11/9/2022 10:54 AM, Don Allen wrote:

>

Not too surprisingly, given how new ImportC is, more testing has resulted in problems. I'll have more to say if/when I better understand the issue(s).

Please post any problems to bugzilla, and tag them with ImportC. Thanks!

I will. I'm still working on trying to sort this out (with limited time at the moment), so that if a bugzilla report is appropriate, it will be useful.

Incidental to the issues I've encountered, I should mention that the second ImportC example
in Quick Examples, Section 41.1, does not compile with either the current release of dmd or the release candidate, due to the conflict between the module and function names:

(dmd-2.101.0-rc.1)dca@giovanni:/tmp$ dmd demo.d square.c
demo.d(6): Error: function expected before `()`, not `module square` of type `void`

Changing the D code to use the fully qualified function name

import std.stdio;
import square;
void main()
{
    int i = 7;
    writefln("The square of %s is %s", i, square.square(i));
}

fixes it. I will file a bugzilla report.

November 11, 2022
On 11/11/2022 8:50 AM, Don Allen wrote:
> fixes it. I will file a bugzilla report.

Thank you!

November 11, 2022
On Thursday, 10 November 2022 at 17:18:27 UTC, Adam D Ruppe wrote:
> 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.
>
> I'm actually not sure about that but I don't think it will.
>
> The way it works right now si you make a little .c file that just #include's the .h file you want, then pass that .c file to the compiler.

Perhaps D could try to automate this somehow as a "hack" to solve the problem.
November 12, 2022

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!!!