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

Cannot build on windows 10 with latest version of go #328

Closed
stuartdd opened this issue Apr 29, 2018 · 21 comments
Closed

Cannot build on windows 10 with latest version of go #328

stuartdd opened this issue Apr 29, 2018 · 21 comments
Labels
support This issue was posted by user to ask for help

Comments

@stuartdd
Copy link

I have spent two days configuring a simple go app that uses SDL2. I have done this several times on Linux. I have followed instructions from various places.

  1. Started with git-bash. No GCC
  2. MinGW could not get gcc 64
  3. Sdl2 installation instructions do not match anything in MinGW
  4. Full cygwin 64 + gcc 64. Cannot find headers audio.h
    Copied from SDL zip
    ld cannot find SDL2, copied from zip
    followed by a whole chain of dll(s) that could not be found, about 20.

I have given up... Scrapped cygwin, MinGW and SDL.

Could somone please look at the instructions for building on windows 10.
Why is is so complex?
Could it be prebuilt for Win 10 platform.

Going back to to good old linux for now but I really needto get this working on windows 10 as well.

I have been doing this sort of thing for years and not been so frustrated for a long time :-(

Sorry if this is the wrong forum for this but I could not see any other way to discuss this issue!

@stuartdd
Copy link
Author

Finally got it working... Only took a day! is there no way of simplifying it?

@veeableful
Copy link
Contributor

Sorry @stuartdd, I also wish that I could make it as simple as Linux at setting up go-sdl2. We definitely need a Windows expert for that 😂

@malashin
Copy link
Collaborator

malashin commented Apr 30, 2018

This is the way I do it on Windows 7 (64 bit). Windows 10 might have a proper package manager with its linux subsystem, but since I do not have it, I use choco (though it got quite slow recently). Both msys2 and golang are installed using choco to make it easier to update to the latest versions later on.

  1. Install choco.
  2. choco install msys2
  3. Lunch msys2.exe. In my case it's in c:\tools\msys64\.
  4. In the opened msys2 window type pacman -Syu to update the package database and core system packages.
  5. If it asks you to close the window, close it (X button in the corner, not ctrl+C).
  6. Open msys2.exe again and type pacman -Syu to update the rest of the packages.
  7. Type pacman -S mingw64/mingw-w64-x86_64-SDL2{,_image,_mixer,_ttf,_gfx} to install sdl2 for 64 bit system. If for some reason packages are not found, type pacman -Ss sdl2 to see the correct package names.
  8. Add c:\tools\msys64\mingw64\bin\ to your PATH environment variable. It should contain gcc. If not, you will need to install it in msys2 with pacman -S mingw64/mingw-w64-x86_64-gcc.

It's from the top of my head, apart from package names and I might have missed something, but it's mostly straight forward once you have msys2, just don't forget to add executable to the PATH.

@stuartdd
Copy link
Author

Thanks for the replies. It's a art form - When faced with a combination of choices, make a enough wrong ones to prevent a solution, Iterate!

I chose the wrong version of minGW, then chose badly from the selection of SDL2 downloads. Thought Ubuntu Windows 10, SubSystem would fix the gcc issue but realised too late that it was headless and would not run any way, then tried full fat cygwin, that would have worked if I had the correct SDL2 download, And so it went on.

After uninstalling everything! I started from fresh, made better choices based on my previous bad ones and read the instructions more carefully!

I think some clarity in the instalation instructions would help (nornal people, not me, I am doomed!), other than that I think my comments were borne out of frustration, nothing else.

Keep up the really fine work you are doing.

Regards

Stuart

@stuartdd stuartdd reopened this May 14, 2018
@stuartdd
Copy link
Author

I am finally giving up trying to build on Windows 10. Days of frustration, it should not be this complex.

Building on Linux is fine. On Windows I just cannot get it to work. It's fine until I use GFX.

I need to be able to build on windows so I am scrapping the whole project. Going back to Java to implement.

Sorry to be so negative but it is very frustrating...

@veeableful veeableful added the support This issue was posted by user to ask for help label May 15, 2018
@malashin
Copy link
Collaborator

@stuartdd

On Windows I just cannot get it to work. It's fine until I use GFX.

Can you please post the errors you are getting with GFX in the build?

With MSYS2 it's fairly simple to get all the dependencies. Just follow my earlier post and ask questions if you need help. You can skip first tow steps with choco and install MSYS2 manually.

@stuartdd
Copy link
Author

Thanks for the feedback.

I spent hours installing downloading and failed. I ended up with SDL2/SDL2.h errors. I had gone down this path previously only to get more and more failed includes.. I gave up at that point.

I then tried Ubuntu Windows Subsystem and intended to build (cross compile) a windows exe. This would have been sufficient, at least I could develop on windows. I finally got the cross compiler working on a simple go file but when I tried with sdl + gfx I had the same result. SDL2/SDL2.h errors. That was the final straw for me.

I may come back to it when I have more time and the memory and frustration has faded. I will keep your notes and try MSYS2.

Thanks again

@gen2brain
Copy link
Collaborator

@stuartdd Hi, did you try new -tags static thing that is mentioned in release notes, that should work on windows/darwin/linux ? Prebuilt libraries are available, even for Android, if you have any issues with static build it would be great if you can report those here and I can try to fix.

@stuartdd
Copy link
Author

OK. I spent some time last night and this is the current state:

$ go get -v github.com/veandco/go-sdl2/gfx
github.com/veandco/go-sdl2/gfx
# github.com/veandco/go-sdl2/gfx
..\github.com\veandco\go-sdl2\gfx\sdl_gfx.go:5:10: fatal error: sdl_gfx_wrapper.h: No such file or directory
 //#include "sdl_gfx_wrapper.h"
          ^~~~~~~~~~~~~~~~~~~
compilation terminated.

SDL project directory structure

C:/Users/stuartdd/git/src

image

Contents of gfx directory

image

My Project:

C:/Users/stuartdd/git/src/tools_sdl:

drwxr-xr-x 1 stuartdd 197610 0 May 16 22:42 interfaces/
drwxr-xr-x 1 stuartdd 197610 0 May 16 22:42 objects/
-rw-r--r-- 1 stuartdd 197610 11 May 16 22:42 README.md
-rw-r--r-- 1 stuartdd 197610 1467 May 16 22:42 Setup.go
drwxr-xr-x 1 stuartdd 197610 0 May 16 22:42 tools/

Go ENV

GOPATH=C:\Users\stuartdd\git
GOROOT=C:\Go\

My Path according to GitBash

PATH=
/usr/local/bin:
/usr/bin:/bin:
/mingw64/bin:
/usr/bin:
/c/WINDOWS/system32:
/c/WINDOWS:
/c/WINDOWS/System32/Wbem:
/c/WINDOWS/System32/WindowsPowerShell/v1.0:
/c/Program Files/Intel/WiFi/bin:
/c/Program Files/Common Files/Intel/WirelessCommon:
/c/Program Files/PuTTY:
/c/Go/bin:
/cmd:
/c/Software/mingw-w64/x86_64-7.3.0-posix-seh-rt_v5-rev0/mingw64/bin:
/c/Software/mingw-w64/x86_64-7.3.0-posix-seh-rt_v5-rev0/mingw64/x86_64-w64-mingw32/bin:
/usr/bin/vendor_perl:
/usr/bin/core_perl

@malashin
Copy link
Collaborator

malashin commented May 16, 2018

Did you install sdl_gfx in MinGW? It is a separate package, not a part of SDL2.
pacman -S mingw64/mingw-w64-x86_64-SDL2{,_image,_mixer,_ttf,_gfx}
This command should install SDL2 and all 4 optional packages.

@stuartdd
Copy link
Author

Hi.

I believe that I did. Is that:

Install SDL2 http://libsdl.org/download-2.0.php
    Extract the SDL2 folder from the archive using a tool like 7zip
    Inside the folder, copy the 
i686-w64-mingw32 and/or x86_64-w64-mingw32 
depending on the architecture you chose into your mingw-w64 folder e.g. 
C:\Program Files\mingw-w64\x86_64-6.3.0-win32-seh-rt_v5-rev1\mingw64

I have both:

C:\Software\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\x86_64-w64-mingw32\bin;

and

C:\Software\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\i686-w64-mingw32\bin;

On my class path.
It finds

C:/Software/mingw-w64/x86_64-7.3.0-posix-seh-rt_v5-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/stddef.h

ok. It's the #include_next that throws it!

$ go get -v github.com/veandco/go-sdl2/gfx
github.com/veandco/go-sdl2/gfx
# github.com/veandco/go-sdl2/gfx
In file included from cgo-builtin-prolog:1:0:
C:/Software/mingw-w64/x86_64-7.3.0-posix-seh-rt_v5-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/stddef.h:1:15: fatal error: stddef.h: No such file or directory
 #include_next <stddef.h>
               ^~~~~~~~~~

One thing that might help is understanding which file to download from http://libsdl.org/download-2.0.php. I went for SDL2-devel-2.0.8-mingw.tar.gz (MinGW 32/64-bit).

Also a similar issue exists for Install mingw-w64 from Mingw-builds. I downloaded mingw-w64-install.exe and installed it but my libaries ar rev0. The libraries in the instructions are rev1. Would this be an issue?

Also I to not have pacman so I have no equivilent to:
pacman -S mingw64/mingw-w64-x86_64-SDL2{,_image,_mixer,_ttf,_gfx}

Should I just give up and go the Msys2 route?

@stuartdd
Copy link
Author

@gen2brain; Could you please clarify:

did you try new -tags static thing that is mentioned in release notes

I cannot find where this is detailed...

Maybe I have a gen0brain;-)

@gen2brain
Copy link
Collaborator

@stuartdd just try go build -tags static ?

@stuartdd
Copy link
Author

stuartdd commented May 17, 2018

@gen2brain Thanks for the quick reply.
I tried that and got the following:

This is from the GitBash shell:

go build -tags static tools_sdl/Setup.go
go build github.com/veandco/go-sdl2/sdl: invalid flag in #cgo LDFLAGS: -mwindows

I also have SDL2.dll in my path

I also did

$ go install github.com/veandco/go-sdl2/{sdl,img,mix,ttf}

# github.com/veandco/go-sdl2/img
In file included from cgo-builtin-prolog:1:0:
C:/Software/mingw-w64/x86_64-7.3.0-posix-seh-rt_v5-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/stddef.h:1:15: fatal error: stddef.h: No such file or directory
 #include_next <stddef.h>
               ^~~~~~~~~~
compilation terminated.
# github.com/veandco/go-sdl2/mix
In file included from cgo-builtin-prolog:1:0:
C:/Software/mingw-w64/x86_64-7.3.0-posix-seh-rt_v5-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/stddef.h:1:15: fatal error: stddef.h: No such file or directory
 #include_next <stddef.h>
               ^~~~~~~~~~
compilation terminated.
# github.com/veandco/go-sdl2/ttf
In file included from cgo-builtin-prolog:1:0:
C:/Software/mingw-w64/x86_64-7.3.0-posix-seh-rt_v5-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/stddef.h:1:15: fatal error: stddef.h: No such file or directory
 #include_next <stddef.h>
               ^~~~~~~~~~

Still hopefull :-)

@stuartdd
Copy link
Author

@malashin @gen2brain
I now have a working GFX build.

For info this is what I had to do.

Remove: Windows installations of GIT, GIT-BASH and MinGW (and any other tools that may clash). Don't remove GO but make sure it is up to date.

  • From http://www.msys2.org/ install the 64bit version of Msys2 windows installer. For example msys2-x86_64-20161025.exe.
  • Follow the instructions on the msys2 site (and above given by @malashin. I did not use Choco).
  • I would recommend using a specific dir like C:\Software\msys64\ to install into as this makes setting the path easier later.
  • Make sure everything is up to date. I found www.msys2.org easier to follow.
    -- Be careful to close the msys2 window using the top right [x] on the msys2 window after the first update (pacman -Suy). You may need to click it multiple times and force it to exit.
    -- Restart msys64 (C:\Software\msys64\msys2_shell.cmd -mingw64) and complete any updates (pacman -Su).
    -- This step took quite a long time!

Exit mysys2.

  • Set up your Windows path to include (in my case) C:\Software\msys64\mingw64\bin and make sure your GO bin directory is also included (in my case) C:\Go\bin.
  • Set up your GO Windows environment variables (in my case).
    -- GOPATH=C:\Users\stuartdd\git
    -- GOROOT=C:\Go\
  • Note that the GOPATH variable should point to the directory containing your GO 'src' directory.

Restart mysys2.

  • Install SDL2 - pacman -S mingw64/mingw-w64-x86_64-SDL2{,_image,_mixer,_ttf,_gfx}
  • Install GCC - pacman -S mingw64/mingw-w64-x86_64-gcc
  • Install GIT - pacman -S git

Exit mysys2.

  • Edit the msys2 .bashrc. In my case it was at: C:\Software\msys64\home\stuartdd.bashrc
    -- On the last line of the file add the GO bin directory to the mysys2 path as follows:
    -- (in my case) PATH=/c/Go/bin:$PATH$.

Restart mysys2.

  • Test git (type git and you should get the help)
  • Test go (type go and you should get the help)

Install SDL2 (inside the msys2 shell)

  • go get -v github.com/veandco/go-sdl2/sdl (This takes some time so be patient)
    -- Check that the GOPATH directory now contains: src\github.com\veandco\go-sdl2
  • go get -v github.com/veandco/go-sdl2/gfx (This was quite quick)
    -- Check that there is naw a gfx directory in src\github.com\veandco\go-sdl2

At this point I did not see any errors so I had a party!

Build your GO code.

  • cd to the GOPATH/src directory:
    -- go build main.go (in my case it was go build tools_sdl/Setup.go)
    -- There should now be an exe in the same directory as your main.go file. In my case it was tools_sdl.exe (not Setup.exe)

Assuming there were no compilation errors you should be good to go!

I hope this helps:

Stuart

@sawaYch
Copy link

sawaYch commented Oct 23, 2018

This is the way I do it on Windows 7 (64 bit). Windows 10 might have a proper package manager with its linux subsystem, but since I do not have it, I use choco (though it got quite slow recently). Both msys2 and golang are installed using choco to make it easier to update to the latest versions later on.

  1. Install choco.
  2. choco install msys2
  3. Lunch msys2.exe. In my case it's in c:\tools\msys64\.
  4. In the opened msys2 window type pacman -Syu to update the package database and core system packages.
  5. If it asks you to close the window, close it (X button in the corner, not ctrl+C).
  6. Open msys2.exe again and type pacman -Syu to update the rest of the packages.
  7. Type pacman -S mingw64/mingw-w64-x86_64-SDL2{,_image,_mixer,_ttf,_gfx} to install sdl2 for 64 bit system. If for some reason packages are not found, type pacman -Ss sdl2 to see the correct package names.
  8. Add c:\tools\msys64\mingw64\bin\ to your PATH environment variable. It should contain gcc. If not, you will need to install it in msys2 with pacman -S mingw64/mingw-w64-x86_64-gcc.

It's from the top of my head, apart from package names and I might have missed something, but it's mostly straight forward once you have msys2, just don't forget to add executable to the PATH.

Thank You. I have same issue (i have no idea why this problem happen suddenly) and your solution save my life 👍 I just do update(pacman -Syu) and everything work again.

@suryanshv23
Copy link

suryanshv23 commented Feb 11, 2019

This is the way I do it on Windows 7 (64 bit). Windows 10 might have a proper package manager with its linux subsystem, but since I do not have it, I use choco (though it got quite slow recently). Both msys2 and golang are installed using choco to make it easier to update to the latest versions later on.

  1. Install choco.
  2. choco install msys2
  3. Lunch msys2.exe. In my case it's in c:\tools\msys64\.
  4. In the opened msys2 window type pacman -Syu to update the package database and core system packages.
  5. If it asks you to close the window, close it (X button in the corner, not ctrl+C).
  6. Open msys2.exe again and type pacman -Syu to update the rest of the packages.
  7. Type pacman -S mingw64/mingw-w64-x86_64-SDL2{,_image,_mixer,_ttf,_gfx} to install sdl2 for 64 bit system. If for some reason packages are not found, type pacman -Ss sdl2 to see the correct package names.
  8. Add c:\tools\msys64\mingw64\bin\ to your PATH environment variable. It should contain gcc. If not, you will need to install it in msys2 with pacman -S mingw64/mingw-w64-x86_64-gcc.

It's from the top of my head, apart from package names and I might have missed something, but it's mostly straight forward once you have msys2, just don't forget to add executable to the PATH.

I have the same prblem and i am new to this part can you explain what happens during this process as I am not able to solve the problem after many attempts
and how to check this method worked

@malashin
Copy link
Collaborator

@suryanshv23
Hello, I'm not really sure what exactly is the issue you are having. Some more info of what did you do and where is fails would be great to have.

go-sdl2 is just bindings for the SDL2 itself and in order to use it you need to have SDL2 source files. What I explained in the post you've quoted is how to get SDL2 on Windows.

Step 1 is installing choco package manager.
Step 2 is installing msys2 from choco.
Steps 3-6 are updating msys2 and it's packages.
Step 7 is installing SDL2
Step 8 is adding path to SDL2 to your PATH environment variable. So that OS knows where to find it.

Once this is done you can try running any go project with go-sdl2 in it and see if it works. We have some examples here, you can use this one:
https://github.com/veandco/go-sdl2-examples/blob/4298a5894b3ec15532eb78de70c71a528095865e/examples/gfx/gfx.go

If it works then everything is all right, otherwise you will get an error.

@gonutz
Copy link
Contributor

gonutz commented Feb 16, 2019

You might be interested in issue 382. If we can remove CGo on Windows, you only need a Go compiler and the SDL2.dll.

@AndrewSav
Copy link

AndrewSav commented Feb 4, 2020

Just to leave some feedback - I picked up it today on Windows, and had no problem whatsoever of building and running the example in readme - just followed the steps. This may be no longer an issue.

@veeableful
Copy link
Contributor

Thanks @AndrewSav for confirming that it builds now. I will close this issue then. Feel free to reopen if it's not solved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support This issue was posted by user to ask for help
Projects
None yet
Development

No branches or pull requests

8 participants