Re: Including C sources in a DUB project
On Wednesday, 11 May 2022 at 05:11:10 UTC, Alexander Zhirov wrote: dub.settings.json It's written about it [here](https://dub.pm/settings)
Re: Including C sources in a DUB project
On Tuesday, 10 May 2022 at 22:12:52 UTC, Dennis wrote: It depends on whether your DMD or LDC installation comes first in your PATH environment variable. Both ship with a `dub` executable that uses their compiler as default. I came across something else like this. Created a `dub.settings.json` file in the dub project, but still requires `dmd`: ```sh $ dub Performing "debug" build using dmd for x86_64. app ~master: building configuration "application"... Running pre-build commands... Error: unrecognized switch '-Os' run `dmd` to print the compiler manual run `dmd -man` to open browser on manual dmd failed with exit code 1. ``` *dub.settings.json*: ```js { "defaultArchitecture": "x86_64", "defaultCompiler": "ldc" } ```
Re: Including C sources in a DUB project
On Tuesday, 10 May 2022 at 20:50:12 UTC, Alexander Zhirov wrote: And if there are two compilers in the system - `dmd` and `ldc`, which compiler chooses `dub.json`? It depends on whether your DMD or LDC installation comes first in your PATH environment variable. Both ship with a `dub` executable that uses their compiler as default. And how do I specify the specific compiler I want? On the command line you can use the `--compiler=dmd` flag. You can't specify this in the dub.json, since your project is supposed to be compiler agnostic.
Re: Including C sources in a DUB project
On Tuesday, 10 May 2022 at 20:50:12 UTC, Alexander Zhirov wrote: On Tuesday, 10 May 2022 at 19:13:21 UTC, Dennis wrote: It has an example directory: https://github.com/dlang/dub/tree/master/examples And if there are two compilers in the system - `dmd` and `ldc`, which compiler chooses `dub.json`? And how do I specify the specific compiler I want? Following the command line documentation [1], you can use the --compiler option to select which to use. You can make the dub.json do different things depending on the target and/or compiler, but the default works fine regardless if you're doing something simple. https://dub.pm/commandline.html
Re: Including C sources in a DUB project
On Tuesday, 10 May 2022 at 19:13:21 UTC, Dennis wrote: It has an example directory: https://github.com/dlang/dub/tree/master/examples And if there are two compilers in the system - `dmd` and `ldc`, which compiler chooses `dub.json`? And how do I specify the specific compiler I want?
Re: Including C sources in a DUB project
On Tuesday, 10 May 2022 at 19:13:21 UTC, Dennis wrote: [snip] It has an example directory: https://github.com/dlang/dub/tree/master/examples If your configuration is missing, you could make a Pull Request to add it. So it does. Thanks. We might also link to that on the dub.pm website.
Re: Including C sources in a DUB project
On Tuesday, 10 May 2022 at 17:19:23 UTC, jmh530 wrote: It would be nice if dub included a directory of example configurations for common issues like this. It has an example directory: https://github.com/dlang/dub/tree/master/examples If your configuration is missing, you could make a Pull Request to add it.
Re: Including C sources in a DUB project
On Monday, 9 May 2022 at 09:17:06 UTC, Alexander Zhirov wrote: [snip] It would be nice if dub included a directory of example configurations for common issues like this.
Re: Including C sources in a DUB project
On Friday, 6 May 2022 at 11:31:27 UTC, Alexander Zhirov wrote: Does anyone have examples of such a configuration? I managed to do it like this: ```js { "name": "app", "authors": [ "Alexander Zhirov" ], "description": "MyProgram", "dflags": [ "-i" ], "libs": [ "pq" ], "preBuildCommands": [ "gcc -Os -c c/*.c -o obj/ip_addresses.o" ], "sourceFiles": [ "obj/*.o" ] } ```
Re: Including C sources in a DUB project
On Thursday, 5 May 2022 at 06:05:55 UTC, Alexander Zhirov wrote: It turns out to compile everything manually, but I would like to do it all through the dub project. Does anyone have examples of such a configuration?
Re: Including C sources in a DUB project
On Thursday, 5 May 2022 at 16:23:18 UTC, H. S. Teoh wrote: I don't know how to do it using dub, but you could use pragma(lib) in one (or more) of your source files as a workaround: pragma(lib, "m"); pragma(lib, "X11"); pragma(lib, "Xrandr"); I remember a long time ago, when I first started learning D, I set up a project in dub.json so that he compiled the sources written in C, linked the necessary libraries and then assembled the project in D along with the C object files. How to do it now - I have already forgotten.
Re: Including C sources in a DUB project
On Thu, May 05, 2022 at 06:05:55AM +, Alexander Zhirov via Digitalmars-d-learn wrote: > I'm sure there is such a topic on the forum, but after scrolling > through the search, I didn't find anything. The bottom line is that I > want to enable compilation of C sources in DUB and then build the > project with the connection of libraries. I would like to see an > example of such a `dub.json` project. > > Enable libraries (flags) `-lm`, `-lX11`, `-lXrandr`. I don't know how to do it using dub, but you could use pragma(lib) in one (or more) of your source files as a workaround: pragma(lib, "m"); pragma(lib, "X11"); pragma(lib, "Xrandr"); T -- MACINTOSH: Most Applications Crash, If Not, The Operating System Hangs