Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows and DUB #133

Open
Zardoz89 opened this issue Nov 18, 2015 · 18 comments
Open

Windows and DUB #133

Zardoz89 opened this issue Nov 18, 2015 · 18 comments

Comments

@Zardoz89
Copy link

I'm really having annoying problems with GtkD on Windows.
With a basic hello world (the same that is on the wiki ), I try this :

  • dub build -> Crash with an optlink error.
  • dub build --arch=x86_64 -> Warning when linking and crash when I try to run the .exe file
  • Follow the install procedure for windows that is on the wiki and repeat both previuos steps -> Same result
  • Try dmd source/app.d -L+gtkd.lib -> This works, and I can see the hello world window
  • Try dmd source/app.d -m64 -Lgtkd.lib -> It crash when i try to execute the .exe file on my machine.

dmd version : 2.069.1
dub version: 0.9.24
gtk binaries version 3.8.1-2 , both 32 and 64 bits
vstudio 2015 community with latest windows sdk
OS: Windows 8.1 64bit

Optlink crash :
crash

sc.ini :

[Version]
version=7.51 Build 020


; environment for both 32/64 bit
[Environment]
DFLAGS="-I%@P%\..\..\src\phobos" "-I%@P%\..\..\src\druntime\import" "-I%@P%\..\..\src\gtkd"

; optlink only reads from the Environment section so we need this redundancy
; from the Environment32 section (bugzilla 11302)
LIB="%@P%\..\lib"


[Environment32]
LIB="%@P%\..\lib"
LINKCMD=%@P%\link.exe


[Environment64]
LIB="%@P%\..\lib64"

; needed to avoid COMDAT folding (bugzilla 10664)
DFLAGS=%DFLAGS% -L/OPT:NOICF 

; default to 32-bit linker (can generate 64-bit code) that has a common path
; for VS2008, VS2010, VS2012, and VS2013. This will be overridden below if the
; installer detects VS.
LINKCMD=%VCINSTALLDIR%\bin\link.exe


; -----------------------------------------------------------------------------
; This enclosed section is specially crafted to be activated by the Windows
; installer when it detects the actual paths to VC and SDK installations so
; modify this in the default sc.ini within the dmd git repo with care.
;
; End users: You can fill in the path to VC and Windows SDK and uncomment out
; the appropriate LINKCMD to manually enable support yourself.
;
; Users using Visual Studio 2010 Express with SDK 7.0A: The installer cannot
; determine the path to the 64-bit compiler included with SDK 7.0A. It's
; recommended to install the Windows SDK 7.1A. Alternatively you can set
; LINKCMD as the path to link.exe SDK 7.0A installs. It would typically be:
;   C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\link.exe


; Windows installer replaces the following lines with the actual paths
VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\
WindowsSdkDir=C:\Program Files (x86)\Windows Kits\10\
UniversalCRTSdkDir=C:\Program Files (x86)\Windows Kits\10\
UCRTVersion=10.0.10240.0

; Windows installer uncomments the version detected
LINKCMD=%VCINSTALLDIR%\bin\x86_amd64\link.exe
;VC2013 LINKCMD=%VCINSTALLDIR%\bin\x86_amd64\link.exe
;VC2012 LINKCMD=%VCINSTALLDIR%\bin\x86_amd64\link.exe
;VC2010 LINKCMD=%VCINSTALLDIR%\bin\amd64\link.exe
;VC2008 LINKCMD=%VCINSTALLDIR%\bin\amd64\link.exe

; needed with /DEBUG to find mspdb*.dll (only for VS2012 or VS2013)
PATH=%PATH%;%VCINSTALLDIR%\bin\x86_amd64;%VCINSTALLDIR%\bin
;VC2013 PATH=%PATH%;%VCINSTALLDIR%\bin\x86_amd64;%VCINSTALLDIR%\..\Common7\IDE;%VCINSTALLDIR%\bin
;VC2012 PATH=%PATH%;%VCINSTALLDIR%\bin\x86_amd64;%VCINSTALLDIR%\..\Common7\IDE

; ----------------------------------------------------------------------------


; Add the library subdirectories of all VC and Windows SDK versions so things
; just work for users using dmd from the VS 64-bit Command Prompt

; C Runtime libraries
LIB=%LIB%;"%VCINSTALLDIR%\lib\amd64"

; Platform/UCRT libraries (Windows SDK 10.0)
LIB=%LIB%;"%UniversalCRTSdkDir%\Lib\%UCRTVersion%\um\x64"
LIB=%LIB%;"%UniversalCRTSdkDir%\Lib\%UCRTVersion%\ucrt\x64"

; Platform libraries (Windows SDK 8.1)
LIB=%LIB%;"%WindowsSdkDir%\Lib\winv6.3\um\x64"

; Platform libraries (Windows SDK 8)
LIB=%LIB%;"%WindowsSdkDir%\Lib\win8\um\x64"

; Platform libraries (Windows SDK 7 and 6)
LIB=%LIB%;"%WindowsSdkDir%\Lib\x64"

; DirectX (newer versions are included in the Platform SDK but this
; will allow us to support older versions)
LIB=%LIB%;"%DXSDK_DIR%\Lib\x64"


; -----------------------------------------------------------------------------
[Environment32mscoff]
LIB="%@P%\..\lib32mscoff"

; settings very much copied from Environment64, see comments there
; needed to avoid COMDAT folding (bugzilla 10664)
DFLAGS=%DFLAGS% -L/OPT:NOICF

; Windows installer replaces the following lines with the actual paths
VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\
WindowsSdkDir=C:\Program Files (x86)\Windows Kits\10\
UniversalCRTSdkDir=C:\Program Files (x86)\Windows Kits\10\
UCRTVersion=10.0.10240.0

LINKCMD=%VCINSTALLDIR%\bin\link.exe

; needed with /DEBUG to find mspdb*.dll (only for VS2012 or VS2013)
PATH=%PATH%;%VCINSTALLDIR%\bin
;VC2013 PATH=%PATH%;%VCINSTALLDIR%\..\Common7\IDE;%VCINSTALLDIR%\bin
;VC2012 PATH=%PATH%;%VCINSTALLDIR%\..\Common7\IDE

; ----------------------------------------------------------------------------
; Add the library subdirectories of all VC and Windows SDK versions so things
; just work for users using dmd from the VS Command Prompt

; C Runtime libraries
LIB=%LIB%;"%VCINSTALLDIR%\lib"

; Platform/UCRT libraries (Windows SDK 10.0)
LIB=%LIB%;"%UniversalCRTSdkDir%\Lib\%UCRTVersion%\um\x86"
LIB=%LIB%;"%UniversalCRTSdkDir%\Lib\%UCRTVersion%\ucrt\x86"

; Platform libraries (Windows SDK 8.1)
LIB=%LIB%;"%WindowsSdkDir%\Lib\winv6.3\um\x86"

; Platform libraries (Windows SDK 8)
LIB=%LIB%;"%WindowsSdkDir%\Lib\win8\um\x86"

; Platform libraries (Windows SDK 7 and 6)
LIB=%LIB%;"%WindowsSdkDir%\Lib"

; DirectX (newer versions are included in the Platform SDK but this
; will allow us to support older versions)
LIB=%LIB%;"%DXSDK_DIR%\Lib\x86"
@MikeWey
Copy link
Member

MikeWey commented Nov 22, 2015

I don't have any issues with dub.

For the crash with the 64 bit executable, i have the same issue with the 3.8 runtime installed, some access violation in libgobject-2, but the problem go's away after installing the 3.10 runtime.
So it would seem that is an issue with an old version of GTK on a newer version of windows, i'm on windows 10.

The 3.10 runtime can be found here: http://sourceforge.net/projects/gtkd-packages/files/gtk3-runtime/ although there are some other issues with it, #101

@MikeWey
Copy link
Member

MikeWey commented Nov 22, 2015

I've also uploaded a GTK 3.18 installer, that can successfully run the 64 bit application.

@ghost
Copy link

ghost commented Nov 30, 2015

I have exactly the similar thing on windows. The linker hangs instead of crashing though.

Warning 178: .LIB pagesize exceeds 512

@Zardoz89
Copy link
Author

I just try with the updated GTK 3.18 binaries . on 32 bits, I keep with the same issue with optlink. On 64 bits :

>dub build  --arch=x86_64 dedcpu:lem1802
Building package dedcpu:lem1802 in B:\repos\pruebas\DEDCPU-16\
Package gtk-d can be upgraded from 3.2.0 to 3.2.1.
Use "dub upgrade" to perform those changes.
Performing "debug" build using dmd for x86_64.
gtk-d:gtkd 3.2.0: target for configuration "library" is up to date.
dedcpu:lem1802 ~master: building configuration "application"...
Linking...
   Creating library .dub\build\application-debug-windows-x86_64-dmd_2069-1BE5CF4BDA04EED48325696EE0B72709\lem1802.lib and object .dub\build\application-debug-windows-x86_64-dmd_2069-1BE5CF4BDA04EED48325696EE0B72709\lem1802.exp
gtkd-3.lib(MenuItem.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(Menu.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(Application.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(Action.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(Window.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(Pixbuf.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(AppLaunchContext.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(Device.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
To force a rebuild of up-to-date targets, run again with --force.

> ./lem1802.exe

lem1802.exe' terminated by signal SIGSEGV (Address boundary error)

@ghost
Copy link

ghost commented Nov 30, 2015

There are two different problems here it seems, (1) is optlink hanging/crashing

The other problem might be in the application you are building, have you tried with a simple gtk application you can post the code for?

@Zardoz89
Copy link
Author

Yep, I try the simple "hello world" and I check that my app works on Linux using dub and on Windows if I build it running dmd by hand with "-L+gtkd.lib"

@MikeWey
Copy link
Member

MikeWey commented Nov 30, 2015

Do the same errors occur when invoking dub with: --build-mode=allAtOnce

dub build  --arch=x86_64 --build-mode=allAtOnce dedcpu:lem1802

You might run out of memory tough.

Dub builds the modules one at a time by default, and because there are some modules that have the same name but are in a different package. You end up with multiple objects with the same name in the library.

@Zardoz89
Copy link
Author

I end doing an workaround : https://github.com/Zardoz89/DEDCPU-16/blob/master/dub.sdl
Ideally doing this with dub shouldn't be necessary. Any body would expect that simply runs like on Linux or, at least, have a explicit and detailed why is necessary to do this.

I would try your solution tomorrow (on the computer where i installed the latest gtk binaries), but I don't think that I run out RAM when I have 8GiB of RAM on both computers. Also, building with "--arch=x86_64" generates a .exe file that simply crashes when I try to run it. I can't build it on 32 bit without doing these workaround.

@Zardoz89
Copy link
Author

Zardoz89 commented Dec 1, 2015

> dub build  --arch=x86_64 --build-mode=allAtOnce dedcpu:lem1802
Building package dedcpu:lem1802 in B:\repos\pruebas\DEDCPU-16\
Fetching gtk-d 3.2.1 (getting selected version)...
Placing gtk-d 3.2.1 to C:\Users\luis.panadero\AppData\Roaming\dub\packages\...
Performing "debug" build using dmd for x86_64.
gtk-d:gtkd 3.2.1: building configuration "library"...
dedcpu:lem1802 ~master: building configuration "application"...
   Creating library .dub\build\application-debug-windows-x86_64-dmd_2069-1BE5CF4BDA04EED48325696EE0B72709\lem1802.lib and object .dub\build\application-debug-windows-x86_64-dmd_2069-1BE5CF4BDA04EED48325696EE0B72709\lem1802.exp
gtkd-3.lib(MenuItem.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(Menu.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(Application.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(Action.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(Window.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(Pixbuf.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(AppLaunchContext.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
gtkd-3.lib(Device.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
> .em1802.exe
'lem1802.exe' terminated by signal SIGSEGV (Address boundary error)

And if you have any doubt that my program is doing something weird ... (using the workaround on dub to avoid grab gtkd on Windows and simply link against gtkd.lib)
dedcpu

@MikeWey
Copy link
Member

MikeWey commented Dec 3, 2015

The errors seem to be caused by the debug information, dub includes debug symbols by default.

building without debugging symbols (--build=plain) i don't get the errors/warnings.
So this might be a dmd / linker bug.

@ghost
Copy link

ghost commented Dec 7, 2015

I can confirm that --build=plain makes the link work. Has anybody filed a bug report on optlink?

@MikeWey
Copy link
Member

MikeWey commented Dec 7, 2015

@BoQsc
Copy link

BoQsc commented May 13, 2020

I can confirm that --build=plain makes the link work. Has anybody filed a bug report on optlink?

It does work.
However I noticed strange behaviour: After building and testing the executable produced: executing the executable starts Command Prompt and by using it launches the gtk gui hello program.
Are there any ways to prevent Command Prompt from showing up?

Working example

dub run --single --arch=x86 --build=plain hello.d

hello.d

#!/usr/bin/env dub
/+ dub.sdl:
	name "hello"
	dependency "gtk:gtkd" version="*"
+/
import gtk.MainWindow;
import gtk.Label;
import gtk.Main;

void main(string[] args)
{
    Main.init(args);
    MainWindow win = new MainWindow("Hello World");
    win.setDefaultSize(200, 100);
    win.add(new Label("Hello World"));
    win.showAll();
    Main.run();
}

image

@MikeWey
Copy link
Member

MikeWey commented May 13, 2020

On Windows you have to tell the linker that you don't want the command prompt.

For optlink this whould be /SUBSYSTEM:WINDOWS when using dmd you can use -L/SUBSYSTEM:CONSOLE to tell it to pass the flag to the linker.

For dub you probably have to add it to your dub.json file.

@BoQsc
Copy link

BoQsc commented May 13, 2020

On Windows you have to tell the linker that you don't want the command prompt.

For optlink this whould be /SUBSYSTEM:WINDOWS when using dmd you can use -L/SUBSYSTEM:CONSOLE to tell it to pass the flag to the linker.

For dub you probably have to add it to your dub.json file.

Yep, I red about it on this thread: https://forum.dlang.org/post/ihsgepcxnwzoobzmgzva@forum.dlang.org

I had tried many times and somehow it still didn't work out for me using dub, maybe I'm having syntax misunderstandings of dflags option, unsure. Seems to not produce any errors.

https://dub.pm/package-format-sdl#build-settings

#!/usr/bin/env dub
/+ dub.sdl:
	name "hello"
	dependency "gtk-d:gtkd" version="*"
	dflags "-L/SUBSYSTEM:WINDOWS"
+/
import gtk.MainWindow;
import gtk.Label;
import gtk.Main;

void main(string[] args)
{
    Main.init(args);
    MainWindow win = new MainWindow("Hello World");
    win.setDefaultSize(200, 100);
    win.add(new Label("Hello World"));
    win.showAll();
    Main.run();
}
C:\Users\vaida\Desktop\Command prompt shell>dub run --single --arch=x86 --build=plain --force hello.d
Fetching gtk-d 3.9.0 (getting selected version)...
Performing "plain" build using C:\D\dmd2\windows\bin\dmd.exe for x86.
gtk-d:gtkd 3.9.0: building configuration "library"...
hello ~master: building configuration "application"...
Linking...
Running .\hello.exe

@MikeWey
Copy link
Member

MikeWey commented May 13, 2020

I think you need to put the flag in the lflags variable instead of the dflags variable.

It might also be -Subsystem:Windows although i think that is for one of the other linkers.

@BoQsc
Copy link

BoQsc commented May 13, 2020

@MikeWey you are right, I somehow figured it out just right before your comment.

The final working example

In this example there is no Command Prompt window when launching the executable.

HelloWorld.d

#!/usr/bin/env dub
/+ dub.sdl:
	name "HelloWorld"
	dependency "gtk-d:gtkd" version="*"
	lflags "-L/SUBSYSTEM:WINDOWS"
+/
import gtk.MainWindow;
import gtk.Label;
import gtk.Main;

void main(string[] args)
{
    Main.init(args);
    MainWindow win = new MainWindow("Hello World");
    win.setDefaultSize(200, 100);
    win.add(new Label("Hello World"));
    win.showAll();
    Main.run();
}

Command Line Input and Results

C:\Users\vaida\Desktop\Command prompt shell>dub run --single --arch=x86 --build=plain --force HelloWorld.d
Performing "plain" build using C:\D\dmd2\windows\bin\dmd.exe for x86.
gtk-d:gtkd 3.9.0: building configuration "library"...
hello ~master: building configuration "application"...
Linking...
Running .\HelloWorld.exe

Screenshot showing that example works well with --arch=x86 --build=plain

image

@webloft
Copy link

webloft commented Sep 28, 2021

This didn't work for me anymore...

The correct line should be
lflags "/SUBSYSTEM:WINDOWS"
or
dflags "-L/SUBSYSTEM:WINDOWS"
because dflags are instructions to dmd to pass the variable.

However, I got the error
error LNK2019: unresolved external symbol WinMain referenced in function ...

which means one also needs to specify
"/ENTRY:mainCRTStartup"
or
"/ENTRY:wmainCRTStartup"
depending on the compiler version - linked against default libcmt.lib

Tested on dmd 2.097, dub 1.26.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants