digitalmars.D.learn - How to use ImportC?
- Leonardo (5/5) Mar 03 2022 I saw the new feature called ImportC, it's cool to be able to use
- forkit (2/7) Mar 03 2022 I think you nailed it... with "incomplete".
- bachmeier (22/27) Mar 03 2022 You just add the C files like D files when you compile and import
- Leonardo (41/41) Mar 03 2022 Thanks but not worked here.
- bachmeier (4/46) Mar 03 2022 They must have introduced a bug. Works for me with DMD 2.098.0
- MoonlightSentinel (5/10) Mar 04 2022 Please retry with the
- bachmeier (2/13) Mar 04 2022 Just had a chance to try this. Works with the beta.
- Leonardo (2/13) Mar 18 2022 Thank you all. In v2.099.0 it works.
- dangbinghoo (5/17) Mar 06 2022 LDC works with DMD fronted the same version v2.098.1
I saw the new feature called ImportC, it's cool to be able to use C code/libraries, but I'm not much experience in C and didn't understand this incomplete documentation: https://dlang.org/spec/importc.html How to use ImportC?
Mar 03 2022
On Thursday, 3 March 2022 at 19:05:22 UTC, Leonardo wrote:I saw the new feature called ImportC, it's cool to be able to use C code/libraries, but I'm not much experience in C and didn't understand this incomplete documentation: https://dlang.org/spec/importc.html How to use ImportC?I think you nailed it... with "incomplete".
Mar 03 2022
On Thursday, 3 March 2022 at 19:05:22 UTC, Leonardo wrote:I saw the new feature called ImportC, it's cool to be able to use C code/libraries, but I'm not much experience in C and didn't understand this incomplete documentation: https://dlang.org/spec/importc.html How to use ImportC?You just add the C files like D files when you compile and import them in your D code as you would a D module. At least that is all I've been doing. Simple example: foo.c: ``` double twice(double x) { return 2.0*x; } ``` program.d: ``` import foo; import std.stdio; void main() { writeln(twice(6.8)); } ``` Compilation: ``` dmd program.d foo.c ```
Mar 03 2022
Thanks but not worked here. ``` [leonardo leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved written by Walter Bright [leonardo leonardo-pc dimportc]$ ls foo.c program.d [leonardo leonardo-pc dimportc]$ cat foo.c double twice(double x) { return 2.0*x; } [leonardo leonardo-pc dimportc]$ cat program.d import foo; import std.stdio; void main() { writeln(twice(6.8)); } [leonardo leonardo-pc dimportc]$ dmd program.d foo.c /usr/include/dlang/dmd/core/stdc/stdio.d(1256): Error: function `core.stdc.stdio.vfprintf` `pragma(printf)` functions must be `extern(C) int vfprintf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1259): Error: function `core.stdc.stdio.vfscanf` `pragma(scanf)` functions must be `extern(C) int vfscanf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1262): Error: function `core.stdc.stdio.vsprintf` `pragma(printf)` functions must be `extern(C) int vsprintf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1265): Error: function `core.stdc.stdio.vsscanf` `pragma(scanf)` functions must be `extern(C) int vsscanf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1268): Error: function `core.stdc.stdio.vprintf` `pragma(printf)` functions must be `extern(C) int vprintf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1271): Error: function `core.stdc.stdio.vscanf` `pragma(scanf)` functions must be `extern(C) int vscanf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1485): Error: function `core.stdc.stdio.vsnprintf` `pragma(printf)` functions must be `extern(C) int vsnprintf([parameters...], const(char)*, va_list)` ```
Mar 03 2022
On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote:Thanks but not worked here. ``` [leonardo leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved written by Walter Bright [leonardo leonardo-pc dimportc]$ ls foo.c program.d [leonardo leonardo-pc dimportc]$ cat foo.c double twice(double x) { return 2.0*x; } [leonardo leonardo-pc dimportc]$ cat program.d import foo; import std.stdio; void main() { writeln(twice(6.8)); } [leonardo leonardo-pc dimportc]$ dmd program.d foo.c /usr/include/dlang/dmd/core/stdc/stdio.d(1256): Error: function `core.stdc.stdio.vfprintf` `pragma(printf)` functions must be `extern(C) int vfprintf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1259): Error: function `core.stdc.stdio.vfscanf` `pragma(scanf)` functions must be `extern(C) int vfscanf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1262): Error: function `core.stdc.stdio.vsprintf` `pragma(printf)` functions must be `extern(C) int vsprintf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1265): Error: function `core.stdc.stdio.vsscanf` `pragma(scanf)` functions must be `extern(C) int vsscanf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1268): Error: function `core.stdc.stdio.vprintf` `pragma(printf)` functions must be `extern(C) int vprintf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1271): Error: function `core.stdc.stdio.vscanf` `pragma(scanf)` functions must be `extern(C) int vscanf([parameters...], const(char)*, va_list)` /usr/include/dlang/dmd/core/stdc/stdio.d(1485): Error: function `core.stdc.stdio.vsnprintf` `pragma(printf)` functions must be `extern(C) int vsnprintf([parameters...], const(char)*, va_list)` ```They must have introduced a bug. Works for me with DMD 2.098.0 and LDC 1.28.0. ImportC is under heavy development right now. Most of the 2.098.1 changelog was related to ImportC.
Mar 03 2022
On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote:Thanks but not worked here. ``` [leonardo leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 ```Please retry with the [beta](https://dlang.org/download.html#dmd_beta) or [nightly build](https://github.com/dlang/dmd/releases/tag/nightly). I think your bug was already fixed since 2.098.1.
Mar 04 2022
On Friday, 4 March 2022 at 17:17:17 UTC, MoonlightSentinel wrote:On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote:Just had a chance to try this. Works with the beta.Thanks but not worked here. ``` [leonardo leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 ```Please retry with the [beta](https://dlang.org/download.html#dmd_beta) or [nightly build](https://github.com/dlang/dmd/releases/tag/nightly). I think your bug was already fixed since 2.098.1.
Mar 04 2022
On Friday, 4 March 2022 at 17:17:17 UTC, MoonlightSentinel wrote:On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote:Thank you all. In v2.099.0 it works.Thanks but not worked here. ``` [leonardo leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 ```Please retry with the [beta](https://dlang.org/download.html#dmd_beta) or [nightly build](https://github.com/dlang/dmd/releases/tag/nightly). I think your bug was already fixed since 2.098.1.
Mar 18 2022
On Friday, 4 March 2022 at 01:30:00 UTC, Leonardo wrote:Thanks but not worked here. ``` [leonardo leonardo-pc dimportc]$ dmd --version DMD64 D Compiler v2.098.1 Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved written by Walter Bright [leonardo leonardo-pc dimportc]$ ls.../usr/include/dlang/dmd/core/stdc/stdio.d(1485): Error: function `core.stdc.stdio.vsnprintf` `pragma(printf)` functions must be `extern(C) int vsnprintf([parameters...], const(char)*, va_list)` ```LDC works with DMD fronted the same version v2.098.1 LDC - the LLVM D compiler (1.28.1): based on DMD v2.098.1 and LLVM 13.0.1
Mar 06 2022