www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Passing lots of C flas to the D compilers and DUB

reply data pulverizer <data.pulverizer gmail.com> writes:
Hi,

A [previous 
post](https://forum.dlang.org/post/hxlhyalzqmzzzihdjdof forum.dlang.org) shows
how to link individual C flags with `-L`, but is there a convenient way of
linking lots of C flags? I've tried variations of

```
dmd `pkg-config --libs libR` `pkg-config --cflags libR`  main.d
dmd `pkg-config --cflags --libs libR`  main.d
dmd -L`pkg-config --cflags --libs libR`  main.d
...
```

for linking the R library C backend on Ubuntu Linux and it hasn't 
worked. I'm getting the usual unrecognized switch errors:

```
Error: unrecognized switch '-Wl,--export-dynamic'
Error: unrecognized switch '-fopenmp'
Error: unrecognized switch '-Wl,-Bsymbolic-functions'
Error: unrecognized switch '-Wl,-z,relro'
Error: unrecognized switch '-lR'
...
```


If there is a method, it would be really useful to know if and 
how it changes for the LDC compiler and also for DUB.

Many thanks
May 25 2021
parent reply Witold Baryluk <witold.baryluk gmail.com> writes:
On Wednesday, 26 May 2021 at 02:57:46 UTC, data pulverizer wrote:
 Hi,

 A [previous 
 post](https://forum.dlang.org/post/hxlhyalzqmzzzihdjdof forum.dlang.org) shows
how to link individual C flags with `-L`, but is there a convenient way of
linking lots of C flags? I've tried variations of

 ```
 dmd `pkg-config --libs libR` `pkg-config --cflags libR`  main.d
 dmd `pkg-config --cflags --libs libR`  main.d
 dmd -L`pkg-config --cflags --libs libR`  main.d
 ...
 ```

 for linking the R library C backend on Ubuntu Linux and it 
 hasn't worked. I'm getting the usual unrecognized switch errors:

 ```
 Error: unrecognized switch '-Wl,--export-dynamic'
 Error: unrecognized switch '-fopenmp'
 Error: unrecognized switch '-Wl,-Bsymbolic-functions'
 Error: unrecognized switch '-Wl,-z,relro'
 Error: unrecognized switch '-lR'
 ...
 ```


 If there is a method, it would be really useful to know if and 
 how it changes for the LDC compiler and also for DUB.

 Many thanks
try: ```bash dmd "-L$(pkg-config --libs libR)" main.d ``` if that doesn't work there are some other tricks (with `sed` for example), but I think the above should work.
May 26 2021
next sibling parent Alain De Vos <devosalain ymail.com> writes:
I pass many flags using dub.
Relevant line in my dub.json,
```
"name": "gparted",
	"dflags-ldc": 
["--gcc=cc","--vcolumns","--oq","--dip1000","--dip25","--safe-stack-layout","--boundscheck=on","--D","--g","--w","--de","--d-debug"]
```

Or just direct command,
```
ldc2 --gcc=cc --vcolumns --oq --dip1000 --dip25 
--safe-stack-layout --boundscheck=on --D --g --w --de --d-debug 
`find . -name \*.d -print`
```
May 27 2021
prev sibling parent data pulverizer <data.pulverizer gmail.com> writes:
On Thursday, 27 May 2021 at 01:55:15 UTC, Witold Baryluk wrote:
 try:

 ```bash
 dmd "-L$(pkg-config --libs libR)" main.d
 ```

 if that doesn't work there are some other tricks (with `sed` 
 for example), but I think the above should work.
Thanks
May 31 2021