Jump to page: 1 2
Thread overview
Including C sources in a DUB project
May 05, 2022
Alexander Zhirov
May 05, 2022
H. S. Teoh
May 05, 2022
Alexander Zhirov
May 06, 2022
Alexander Zhirov
May 09, 2022
Alexander Zhirov
May 10, 2022
jmh530
May 10, 2022
Dennis
May 10, 2022
jmh530
May 10, 2022
Alexander Zhirov
May 10, 2022
jmh530
May 10, 2022
Dennis
May 11, 2022
Alexander Zhirov
May 11, 2022
Alexander Zhirov
May 05, 2022

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.

{
	"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.

.
├── dub.json
└── src
    ├── app.d
    └── main.c
May 05, 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 06, 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 09, 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:

{
    "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 10, 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/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?

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:

>

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

« First   ‹ Prev
1 2