dlang / dub

Package and build management system for D
MIT License
676 stars 227 forks source link

Not linking correctly with --compiler=ldc2 #146

Closed Kelet closed 11 years ago

Kelet commented 11 years ago

Hello,

dub run works with my project which uses Derelict-SDL2. However, if I try to do dub --compiler=ldc2 run I get a linker error:

C:\Users\Kyle\Desktop\keleworld>dub --compiler=ldc2 run
Checking dependencies in 'C:\Users\Kyle\Desktop\keleworld'
Building configuration "application", build type debug
Running ldc2...
c:/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bi
n/ld.exe: cannot find -lderelictSDL2
collect2.exe: error: ld returned 1 exit status
Error: C:/mingw32/bin/gcc.exe failed with status: 1
Error: LDC compile run failed with exit code 1

Run 'dub help' for usage information.

I am using dub v0.9.19 on Windows 7. My dependencies in my package.json are as such:

"dependencies": {
    "derelict-sdl2" : "~master"       
}

I am trying to use LDC v0.12.0 using their Windows MinGW binaries (ldc2-0.12.0-mingw-x86.7z). These binaries require an up-to-date installation of MinGW. I use their suggested MinGW binaries from http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/gcc-4.8-dw2-release/i686-w64-mingw32-gcc-dw2-4.8.0-win32_rubenvb.7z/download

Kelet commented 11 years ago

Here's the output of running the aforementioned command with -v

C:\Users\Kyle\Desktop\keleworld>dub -v --compiler=ldc2 run
Using dub registry url 'http://code.dlang.org/'
Looking for local package map at C:\ProgramData\dub\packages\local-packages.json

Looking for local package map at C:\Users\Kyle\AppData\Roaming\dub\packages\loca
l-packages.json
Looking for local package map at C:\ProgramData\dub\packages\local-packages.json

Looking for local package map at C:\Users\Kyle\AppData\Roaming\dub\packages\loca
l-packages.json
Looking for local package map at C:\ProgramData\dub\packages\local-packages.json

Looking for local package map at C:\Users\Kyle\AppData\Roaming\dub\packages\loca
l-packages.json
Looking for local package map at C:\ProgramData\dub\packages\local-packages.json

Looking for local package map at C:\Users\Kyle\AppData\Roaming\dub\packages\loca
l-packages.json
Note: Failed to determine version of package keleworld at C:\Users\Kyle\Desktop\
keleworld. Assuming ~master.
Collecting dependencies for keleworld
Found dependency derelict-sdl2 ~master: true
Collecting dependencies for derelict-sdl2
Found dependency derelict-util ~master: true
Collecting dependencies for derelict-util
Checking dependencies in 'C:\Users\Kyle\Desktop\keleworld'
Required package 'derelict-util' found with version '~master'
Required package 'derelict-sdl2' found with version '~master'
Generating using build
Building configuration "application", build type debug
Application output name is 'C:\Users\Kyle\AppData\Local\Temp\dub\2605820444\kele
world.exe'
Running ldc2...
ldc2 -ofC:\Users\Kyle\AppData\Local\Temp\dub\2605820444\keleworld.exe -oq -od=.d
ub/obj -d-version=Have_keleworld -d-version=Have_derelict_sdl2 -d-version=Have_d
erelict_util -Isource -I..\..\AppData\Roaming\dub\packages\derelict-sdl2-master\
source -I..\..\AppData\Roaming\dub\packages\derelict-util-master\source source\a
pp.d source\namegen\markovtextgen.d ..\..\AppData\Roaming\dub\packages\derelict-
sdl2-master\source\derelict\sdl2\functions.d ..\..\AppData\Roaming\dub\packages\
derelict-sdl2-master\source\derelict\sdl2\image.d ..\..\AppData\Roaming\dub\pack
ages\derelict-sdl2-master\source\derelict\sdl2\mixer.d ..\..\AppData\Roaming\dub
\packages\derelict-sdl2-master\source\derelict\sdl2\net.d ..\..\AppData\Roaming\
dub\packages\derelict-sdl2-master\source\derelict\sdl2\sdl.d ..\..\AppData\Roami
ng\dub\packages\derelict-sdl2-master\source\derelict\sdl2\ttf.d ..\..\AppData\Ro
aming\dub\packages\derelict-sdl2-master\source\derelict\sdl2\types.d ..\..\AppDa
ta\Roaming\dub\packages\derelict-util-master\source\derelict\util\exception.d ..
\..\AppData\Roaming\dub\packages\derelict-util-master\source\derelict\util\loade
r.d ..\..\AppData\Roaming\dub\packages\derelict-util-master\source\derelict\util
\sharedlib.d ..\..\AppData\Roaming\dub\packages\derelict-util-master\source\dere
lict\util\system.d ..\..\AppData\Roaming\dub\packages\derelict-util-master\sourc
e\derelict\util\wintypes.d ..\..\AppData\Roaming\dub\packages\derelict-util-mast
er\source\derelict\util\xtypes.d
c:/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bi
n/ld.exe: cannot find -lderelictSDL2
collect2.exe: error: ld returned 1 exit status
Error: C:/mingw32/bin/gcc.exe failed with status: 1
Error: LDC compile run failed with exit code 1

Full exception: object.Exception@source\dub\compilers\ldc.d(159): LDC compile ru
n failed with exit code 1
----------------
0x004A9D72 in pure @safe void std.exception.bailOut(immutable(char)[], uint, con
st(char[]))
0x00425F0E in void dub.compilers.ldc.LdcCompiler.invoke(const(dub.compilers.comp
iler.BuildSettings), const(dub.compilers.compiler.BuildPlatform)) at C:\Users\sl
udwig\Develop\dub\source\dub\compilers\ldc.d(159)
0x004267BD in void dub.generators.build.BuildGenerator.generateProject(dub.gener
ators.generator.GeneratorSettings) at C:\Users\sludwig\Develop\dub\source\dub\ge
nerators\build.d(118)
0x0040B199 in void dub.dub.Dub.generateProject(immutable(char)[], dub.generators
.generator.GeneratorSettings) at C:\Users\sludwig\Develop\dub\source\dub\dub.d(1
78)
0x00403534 in _Dmain at C:\Users\sludwig\Develop\dub\source\app.d(280)
0x004AD520 in extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int f
unction(char[][])*).void runMain()
0x004AD55B in extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int f
unction(char[][])*).void runAll()
0x004AD159 in _d_run_main
0x0049D2A0 in main
0x74F233CA in BaseThreadInitThunk
0x76FD9ED2 in RtlInitializeExceptionChain
0x76FD9EA5 in RtlInitializeExceptionChain
0x004E7744 in mainCRTStartup
Run 'dub help' for usage information.
s-ludwig commented 11 years ago

Is that using a modified package.json file for derelictSDL2? It's not normal that it tries to link against -lderelictSDL2 AFAICS (everything works for me, at least for the git HEAD version of DUB).

If you do have a modified version for building derelict-sdl separately, it appears that the generated library binary still needs to be copied to the MinGW lib folder, so that it becomes visible to LDC.

Kelet commented 11 years ago

Thanks for the information Ludwig --

I am not using a modified package.json for derelictSDL2; however, I did have

pragma(lib, "derelictSDL2.lib");

in my source code, which is obviously the offender. My SDL2 program seems to work without the pragma, so I suppose it's not necessary, but I had picked up the pragma from a tutorial on using Derelict-SDL2 and thus thought it necessary.

s-ludwig commented 11 years ago

Oh I see. Yeah that was necessary before Derelict was available as a DUB package AFAIK.