# Compiling devel/dub with gcc instead of clang



## Alain De Vos (Sep 1, 2022)

devel/dub does not compile good with clang on my pc.
I want to force the usage of the gcc compiler for the specific dub port.
What should I enter in make.conf in order to do so ?


----------



## zirias@ (Sep 1, 2022)

Nothing. In theory, `CC` and/or `CXX`, but properly building with gcc requires more than that, because the resulting binaries link gcc runtime libs, and to find the correct version on a system with multiple gcc versions installed, `rpath` must be set correctly.

There's a helper to add to the port Makefile itself, `USE_GCC`. But *just don't do that!* Instead, solve the actual building problem. It seems to be related to your system, otherwise the official builders wouldn't be able to successfully build a package.


----------



## jbo (Sep 1, 2022)

You'll also have to make sure that dependencies on both sides are compiled with GCC as well. Except for some cases it won't be enough to just compile one package with a different compiler due to ABI incompatibilities.
The only way (?) to avoid this is to ensure that all binary interfaces are fully "standard C" interfaces. i.e. the port(s) upstream needs to be written in a way to ensure that the resulting ABI is the same across different compilers. If any of the dependencies on either side doesn't do that you're gonna re-compile a lot of stuff with GCC. And all of this is on top of what zirias@ already mentioned.

And after all of this, you'll run into more problems down the road. More or less inevitably. So unless you know what you're doing: Fix the actual problem, don't create new ones.


----------



## SirDice (Sep 1, 2022)

Alain De Vos said:


> devel/dub does not compile good with clang on my pc.


It isn't compiled with Clang? It's using lang/ldc. 


```
BUILD_DEPENDS=	ldmd2:lang/ldc
...
do-build:
	@cd ${WRKSRC} && ${SH} build.sh
```


----------



## SirDice (Sep 1, 2022)

Oh, it does seem to use LLVM, at least indirectly:

```
The LDC project aims to provide a portable D programming language compiler
with modern optimization and code generation capabilities.

The compiler uses the official DMD frontends to support the latest version of
D2, and relies on the LLVM Core libraries for code generation.
```
I don't think you can replace this with GCC. But I didn't know there was such a thing as a "D programming language" until a couple of minutes ago, so I could be mistaken


----------



## zirias@ (Sep 1, 2022)

He! Hm, should have checked the port first, checked upstream right now, it indeed contains nothing but D code 

Ok, now I have to drop this here: The XY Problem


----------



## Alain De Vos (Sep 1, 2022)

I compiled 3400 ports from source without any problem. Only dub fails in it's weirdness.
I have here a cross reference of the same problem i posted  on the D-lang forum ,








						freebsd dub linker error
					

D Programming Language Forum




					forum.dlang.org


----------



## jbo (Sep 1, 2022)

SirDice said:


> I don't think you can replace this with GCC. But I didn't know there was such a thing as a "D programming language" until a couple of minutes ago, so I could be mistaken


Let me tell you about F then


----------



## SirDice (Sep 1, 2022)

jbodenmann said:


> Let me tell you about F then


Wait. What? Programmers are a weird bunch


----------



## jbo (Sep 1, 2022)

SirDice said:


> Wait. What? Programmers are a weird bunch


Well, I didn't want to ruin it but we also have E, J, K, P, Q, S, R...






						List of programming languages - Wikipedia
					






					en.wikipedia.org


----------



## Alain De Vos (Sep 1, 2022)

I might have found a possible reason,

I have in make.conf

```
#10
DEFAULT_VERSIONS+= llvm=14
```
... Maybe it wants an older version eg 10.
On my PC "clang --version" returns 13.0.0.


----------



## SirDice (Sep 1, 2022)

Alain De Vos said:


> Maybe it wants an older version.


It should pick the LLVM from the base. Which is 13.0.0 on 13.1

```
% clang -v
FreeBSD clang version 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)
Target: x86_64-unknown-freebsd13.1
Thread model: posix
InstalledDir: /usr/bin
```

13-STABLE has 14.0.5:

```
% clang -v
FreeBSD clang version 14.0.5 (https://github.com/llvm/llvm-project.git llvmorg-14.0.5-0-gc12386ae247c)
Target: x86_64-unknown-freebsd13.1
Thread model: posix
InstalledDir: /usr/bin
```


----------



## zirias@ (Sep 1, 2022)

SirDice said:


> It should pick the LLVM from the base.


It doesn't. But it doesn't respect `LLVM_DEFAULT` either, and it depends on two different versions at the same time, I have really no idea what's going on there: https://cgit.freebsd.org/ports/tree/lang/ldc/Makefile#n17

But in general, in case of build problems, removing non-default stuff from make.conf should be the first thing you try!


----------



## SirDice (Sep 1, 2022)

zirias@ said:


> I have really no idea what's going on there


Yes, that's very strange. It depends on LLVM 7.0 and 10.0 for some reason. But CC and friends seem to get set to LLVM 10, so why does it need 7.0?


----------



## SirDice (Sep 1, 2022)

For giggles, I removed those LLVM 7.0 dependencies and have a test build running now. But it has to build LLVM 10 first, so it's going to take a while.


----------



## Alain De Vos (Sep 1, 2022)

I've set the default version of llvm to 10 but my problem remains. This is a mystery.


----------



## Alain De Vos (Sep 2, 2022)

I've tracked down the problem to the solution where i specify as linker to use gcc12 instead of a clang/llvm.
export CC=clang14 
ldc2 --link-defaultlib-shared --gcc=gcc12 ...


----------



## Alain De Vos (Sep 2, 2022)

SirDice said:


> For giggles, I removed those LLVM 7.0 dependencies and have a test build running now. But it has to build LLVM 10 first, so it's going to take a while.


I cloned github dub and patched build.sh, now i run dub version:
dub --version 
DUB version 1.29.2-beta.1, built on Sep  2 2022
Note: Quarterly has dub version :   1.18.3 (which might? be old)


----------



## Alain De Vos (Sep 2, 2022)

I have a host a jail and within the jail i perform poudriere-jails.
How can i check the versions of these 3 ?
If the jail is newer then the host or the poudriere jail is newer then the jail it's running in I can expect problems...


----------

