digitalmars.D.learn - Including C sources in a DUB project
- Alexander Zhirov (23/23) May 04 2022 I'm sure there is such a topic on the forum, but after scrolling
- H. S. Teoh (9/16) May 05 2022 I don't know how to do it using dub, but you could use pragma(lib) in
- Alexander Zhirov (6/12) May 05 2022 I remember a long time ago, when I first started learning D, I
- Alexander Zhirov (2/4) May 06 2022 Does anyone have examples of such a configuration?
- Alexander Zhirov (23/24) May 09 2022 I managed to do it like this:
- jmh530 (3/4) May 10 2022 It would be nice if dub included a directory of example
- Dennis (5/7) May 10 2022 It has an example directory:
- jmh530 (3/8) May 10 2022 So it does. Thanks.
- Alexander Zhirov (4/6) May 10 2022 And if there are two compilers in the system - `dmd` and `ldc`,
- jmh530 (7/13) May 10 2022 Following the command line documentation [1], you can use the
- Dennis (7/10) May 10 2022 It depends on whether your DMD or LDC installation comes first in
- Alexander Zhirov (21/24) May 10 2022 I came across something else like this. Created a
- Alexander Zhirov (2/3) May 10 2022 It's written about it [here](https://dub.pm/settings)
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`. ```sh { "name" : "test", "description" : "Test project", "dependencies" : { } } ``` It turns out to compile everything manually, but I would like to do it all through the dub project. ```sh . ├── dub.json └── src ├── app.d └── main.c ```
May 04 2022
On Thu, May 05, 2022 at 06:05:55AM +0000, 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
May 05 2022
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.
May 05 2022
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?
May 06 2022
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" ] } ```
May 09 2022
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.
May 10 2022
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.
May 10 2022
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.
May 10 2022
On Tuesday, 10 May 2022 at 19:13:21 UTC, Dennis wrote:It has an example directory: https://github.com/dlang/dub/tree/master/examplesAnd 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?
May 10 2022
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: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.htmlIt has an example directory: https://github.com/dlang/dub/tree/master/examplesAnd 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?
May 10 2022
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.
May 10 2022
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" } ```
May 10 2022
On Wednesday, 11 May 2022 at 05:11:10 UTC, Alexander Zhirov wrote:dub.settings.jsonIt's written about it [here](https://dub.pm/settings)
May 10 2022