May 05, 2023

On Friday, 5 May 2023 at 22:56:20 UTC, bachmeier wrote:

>

Maybe I can come up with a simpler/more practical example without the complexity of this library. This is the first time ImportC has worked well enough for me to compile C files.

Here's a simpler example using math.h that works for me:

https://gist.github.com/bachmeil/6da28f934454864b7ddf80e2d1eaa5e5

May 05, 2023

On Friday, 5 May 2023 at 22:56:20 UTC, bachmeier wrote:

>

The import qnorm line tells DMD to pull in the code from qnorm.c in that same directory. I don't need to add qnorm.c in the compilation command, which is

dmd test.d -P-I. -P-I../gnuwin32/fixed/h -P-I../include -L/usr/lib/libR.so

This statement is wrong. If it's included in the compilation command like this

dmd test.d qnorm.c -P-I. -P-I../gnuwin32/fixed/h -P-I../include -L/usr/lib/libR.so

the file qnorm.c is compiled and Rf_qnorm5 comes from there. If it's excluded

dmd test.d -P-I. -P-I../gnuwin32/fixed/h -P-I../include -L/usr/lib/libR.so

it's pulled from libR.so.

May 06, 2023

On Friday, 5 May 2023 at 23:05:02 UTC, bachmeier wrote:

>

On Friday, 5 May 2023 at 22:56:20 UTC, bachmeier wrote:

>

Maybe I can come up with a simpler/more practical example without the complexity of this library. This is the first time ImportC has worked well enough for me to compile C files.

Here's a simpler example using math.h that works for me:

https://gist.github.com/bachmeil/6da28f934454864b7ddf80e2d1eaa5e5

I’m afk this weekend, but I didn’t have a .c file that included the math header. I just wanted to use the c header directly in the d file. I want to try having a blank .c file that includes the math header and see if I can use that with D.

May 05, 2023
On 5/5/2023 5:35 PM, jmh530 wrote:
> I want to try having a blank .c file that includes the math header and see if I can use that with D.

That should work.

May 06, 2023

On Saturday, 6 May 2023 at 00:35:46 UTC, jmh530 wrote:

>

On Friday, 5 May 2023 at 23:05:02 UTC, bachmeier wrote:

>

On Friday, 5 May 2023 at 22:56:20 UTC, bachmeier wrote:

>

Maybe I can come up with a simpler/more practical example without the complexity of this library. This is the first time ImportC has worked well enough for me to compile C files.

Here's a simpler example using math.h that works for me:

https://gist.github.com/bachmeil/6da28f934454864b7ddf80e2d1eaa5e5

I’m afk this weekend, but I didn’t have a .c file that included the math header. I just wanted to use the c header directly in the d file. I want to try having a blank .c file that includes the math header and see if I can use that with D.

I updated the gist so the c file contains only #include <math.h>. It works.

May 06, 2023

On Saturday, 6 May 2023 at 01:07:15 UTC, bachmeier wrote:

>

On Saturday, 6 May 2023 at 00:35:46 UTC, jmh530 wrote:

>

On Friday, 5 May 2023 at 23:05:02 UTC, bachmeier wrote:

>

On Friday, 5 May 2023 at 22:56:20 UTC, bachmeier wrote:

>

[...]

Here's a simpler example using math.h that works for me:

https://gist.github.com/bachmeil/6da28f934454864b7ddf80e2d1eaa5e5

I’m afk this weekend, but I didn’t have a .c file that included the math header. I just wanted to use the c header directly in the d file. I want to try having a blank .c file that includes the math header and see if I can use that with D.

I updated the gist so the c file contains only #include <math.h>. It works.

Thanks!

May 08, 2023

On Saturday, 6 May 2023 at 01:07:15 UTC, bachmeier wrote:

>

On Saturday, 6 May 2023 at 00:35:46 UTC, jmh530 wrote:

>

On Friday, 5 May 2023 at 23:05:02 UTC, bachmeier wrote:

>

On Friday, 5 May 2023 at 22:56:20 UTC, bachmeier wrote:

>

Maybe I can come up with a simpler/more practical example without the complexity of this library. This is the first time ImportC has worked well enough for me to compile C files.

Here's a simpler example using math.h that works for me:

https://gist.github.com/bachmeil/6da28f934454864b7ddf80e2d1eaa5e5

I’m afk this weekend, but I didn’t have a .c file that included the math header. I just wanted to use the c header directly in the d file. I want to try having a blank .c file that includes the math header and see if I can use that with D.

I updated the gist so the c file contains only #include <math.h>. It works.

I was able to get nlopt's tutorial example working with importC. I can write a bit more up later.

The only thing that I wasn't able to get working was using the HUGE_VAL macro in math.h. Would anyone else be able to confirm if they are able to get that working?

May 08, 2023

On Monday, 8 May 2023 at 13:22:44 UTC, jmh530 wrote:

>

I was able to get nlopt's tutorial example working with importC. I can write a bit more up later.

The only thing that I wasn't able to get working was using the HUGE_VAL macro in math.h. Would anyone else be able to confirm if they are able to get that working?

In the .c file or the .d file? If in the .d file, you'll need to use core.stdc.math.HUGE_VAL. If in the .c file, it's a bug.

May 08, 2023

On Monday, 8 May 2023 at 14:36:10 UTC, bachmeier wrote:

>

On Monday, 8 May 2023 at 13:22:44 UTC, jmh530 wrote:

>

I was able to get nlopt's tutorial example working with importC. I can write a bit more up later.

The only thing that I wasn't able to get working was using the HUGE_VAL macro in math.h. Would anyone else be able to confirm if they are able to get that working?

In the .c file or the .d file? If in the .d file, you'll need to use core.stdc.math.HUGE_VAL. If in the .c file, it's a bug.

I was just trying out using it directly in the .d file without importing core.stdc.math. I am able to use HUGE_VAL in the .c file (so not a bug that way). The c math header should be setting HUGE_VAL based on a preprocessor macro (on WSL I assume it should run automatically). I was assuming that importC would re-write that to an enum that I could use directly in the D file, but the spec says that it doesn't support all uses of metaprogramming with these. You think that's what I'm running into?

May 08, 2023

On Monday, 8 May 2023 at 15:34:32 UTC, jmh530 wrote:

>

[snip]
I was assuming that importC would re-write that to an enum that I could use directly in the D file, but the spec says that it doesn't support all uses of metaprogramming with these. You think that's what I'm running into?

Hmm, I'm not sure how much sense that makes since I'm able to use it in the .c file...