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

Building doesn't work on Windows #2

Closed
remorez opened this issue Oct 28, 2016 · 8 comments
Closed

Building doesn't work on Windows #2

remorez opened this issue Oct 28, 2016 · 8 comments
Labels

Comments

@remorez
Copy link

remorez commented Oct 28, 2016

Wanted to try this on Windows and after running:
go get github.com/golang-ui/nuklear/nk
it gave me:

# github.com/golang-ui/nuklear/nk
In file included from Go\src\github.com\golang-ui\nuklear\nk\cgo_helpers.go:11:0:
./nuklear_glfw_gl3.h:16:24: fatal error: GLFW/glfw3.h: No such file or directory

 #include <GLFW/glfw3.h>
                        ^
compilation terminated.

I have GLFW 3.2 for Go installed and I am using go1.7.3 windows/amd64. Also I have MinGW_x64 installed and added to path.

To troubleshoot I copied folder containing missing file:
%GOPATH%\src\github.com\go-gl\glfw\v3.2\glfw\glfw\include\GLFW
to nuklear folder:
%GOPATH%\src\github.com\golang-ui\nuklear\nk
and building started to throw those errors:

# github.com/golang-ui/nuklear/nk
In file included from Go\src\github.com\golang-ui\nuklear\nk\impl_glfw.go:16:0:
./nuklear_glfw_gl3.h: In function 'nk_glfw3_device_create':
./nuklear_glfw_gl3.h:94:18: error: unknown type name 'GLchar'
     static const GLchar *vertex_shader =
                  ^~~~~~
./nuklear_glfw_gl3.h:107:18: error: unknown type name 'GLchar'
     static const GLchar *fragment_shader =
                  ^~~~~~
./nuklear_glfw_gl3.h:121:37: error: 'GL_VERTEX_SHADER' undeclared (first use in
this function)
     dev->vert_shdr = glCreateShader(GL_VERTEX_SHADER);
                                     ^~~~~~~~~~~~~~~~
./nuklear_glfw_gl3.h:121:37: note: each undeclared identifier is reported only o
nce for each function it appears in
./nuklear_glfw_gl3.h:122:37: error: 'GL_FRAGMENT_SHADER' undeclared (first use i
n this function)
     dev->frag_shdr = glCreateShader(GL_FRAGMENT_SHADER);
                                     ^~~~~~~~~~~~~~~~~~
./nuklear_glfw_gl3.h:127:35: error: 'GL_COMPILE_STATUS' undeclared (first use in
 this function)
     glGetShaderiv(dev->vert_shdr, GL_COMPILE_STATUS, &status);
                                   ^~~~~~~~~~~~~~~~~
./nuklear_glfw_gl3.h:134:31: error: 'GL_LINK_STATUS' undeclared (first use in th
is function)
     glGetProgramiv(dev->prog, GL_LINK_STATUS, &status);
                               ^~~~~~~~~~~~~~
./nuklear_glfw_gl3.h:155:22: error: 'GL_ARRAY_BUFFER' undeclared (first use in t
his function)
         glBindBuffer(GL_ARRAY_BUFFER, dev->vbo);
                      ^~~~~~~~~~~~~~~
./nuklear_glfw_gl3.h:156:22: error: 'GL_ELEMENT_ARRAY_BUFFER' undeclared (first
use in this function)
         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo);
                      ^~~~~~~~~~~~~~~~~~~~~~~
./nuklear_glfw_gl3.h: In function 'nk_glfw3_render':
./nuklear_glfw_gl3.h:215:21: error: 'GL_FUNC_ADD' undeclared (first use in this
function)
     glBlendEquation(GL_FUNC_ADD);
                     ^~~~~~~~~~~
./nuklear_glfw_gl3.h:220:21: error: 'GL_TEXTURE0' undeclared (first use in this
function)
     glActiveTexture(GL_TEXTURE0);
                     ^~~~~~~~~~~
./nuklear_glfw_gl3.h:235:22: error: 'GL_ARRAY_BUFFER' undeclared (first use in t
his function)
         glBindBuffer(GL_ARRAY_BUFFER, dev->vbo);
                      ^~~~~~~~~~~~~~~
./nuklear_glfw_gl3.h:236:22: error: 'GL_ELEMENT_ARRAY_BUFFER' undeclared (first
use in this function)
         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo);
                      ^~~~~~~~~~~~~~~~~~~~~~~
./nuklear_glfw_gl3.h:238:64: error: 'GL_STREAM_DRAW' undeclared (first use in th
is function)
         glBufferData(GL_ARRAY_BUFFER, max_vertex_buffer, NULL, GL_STREAM_DRAW);

                                                                ^~~~~~~~~~~~~~
./nuklear_glfw_gl3.h:242:49: error: 'GL_WRITE_ONLY' undeclared (first use in thi
s function)
         vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);

This project looks like what I need so please help me make it work.

@xlab xlab added the bug label Oct 28, 2016
@xlab
Copy link
Member

xlab commented Oct 29, 2016

Hey @remorez I've made the thing working fine under Windows, I tried on Windows 7 32-bit.
https://cl.ly/1r0j2Y3D2I2W/Screen%20Shot%202016-10-29%20at%2015.11.24.png

The key problem you had that your Windows doesn't have OpenGL 3, so the backend failed to link. I've migrated to OpenGL 2.1 and adjusted a couple of compile flags to make sure it builds fine.

There is a section dedicated to Windows in readme now: https://github.com/golang-ui/nuklear#windows

I think you'll find this trick useful:

$ CGO_CFLAGS="-I/c/dev/glfw-3.2.1/include" CGO_LDFLAGS="-L/c/dev/glfw-3.2.1/lib-mingw" go install github.com/golang-ui/nuklear/nk

So no need to copy the GLFW libs around, just put them somewhere and reference through CFLAGS/LDFLAGS on build time.

At last, I recommend you to check out this lib https://github.com/therecipe/qt maybe it will provide some rich features you'll need in your project, Nuklear is a cool thing but it's kinda minimalistic for any serious GUI development.

Have fun.

@xlab xlab closed this as completed Oct 29, 2016
@remorez
Copy link
Author

remorez commented Oct 31, 2016

Hey @xlab, I tried to make this work on Windows (7, 64bit) but I was still getting ld.exe: cannot find -lglfw3 error - even when using CGO flags.
Then I tried to compile the example on Linux (Mint 18, 64bit) and got exactly same error.
After some digging I finally could make this work on Linux by compiling GLFW with BUILD_SHARED_LIBS option following these instructions.

@xlab
Copy link
Member

xlab commented Oct 31, 2016

On windows there are 64 and 32 bit precompiled binaries available, just make sure you got the right ones and the path you are specifying points to the correct directory. This really should work. Did you use the MSYS console/shell?

CGO_LDFLAGS="-L/c/dev/glfw-3.2.1/lib-mingw"

@remorez
Copy link
Author

remorez commented Nov 1, 2016

Thanks for all the tips and help @xlab!
So, I fiddled with this on the same machine a bit more to get stuck on:

$ CGO_CFLAGS="-I/c/dev/glfw/include" CGO_LDFLAGS="-L/c/dev/glfw/lib-mingw-w64" go build github.com/golang-ui/nuklear/cmd/nk-example
# github.com/golang-ui/nuklear/cmd/nk-example
C:\go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:\msys64\tmp\go-link-025673147\000002.o:wassert.c:(.text+0x4f5e0): multiple definition of `_wassert'
C:\msys64\tmp\go-link-025673147\000001.o:wassert.c:(.text+0xe650): first defined here
C:\msys64\tmp\go-link-025673147\000002.o:wassert.c:(.text+0x4f720): multiple definition of `_assert'
C:\msys64\tmp\go-link-025673147\000001.o:wassert.c:(.text+0xe790): first defined here
C:\msys64\tmp\go-link-025673147\000002.o:mingw_helpers.c:(.text+0x4f7e0): multiple definition of `_decode_pointer'
C:\msys64\tmp\go-link-025673147\000001.o:mingw_helpers.c:(.text+0xf700): first defined here
C:\msys64\tmp\go-link-025673147\000002.o:mingw_helpers.c:(.text+0x4f7f0): multiple definition of `_encode_pointer'
C:\msys64\tmp\go-link-025673147\000001.o:mingw_helpers.c:(.text+0xf710): first defined here
C:\msys64\tmp\go-link-025673147\000002.o:mingw_helpers.c:(.bss+0x4760): multiple definition of `mingw_app_type'
C:\msys64\tmp\go-link-025673147\000001.o:/tmp/go-build/github.com/go-gl/glfw/v3.2/glfw/_obj/_cgo_export.c:19: first defined here
collect2.exe: error: ld returned 1 exit status

Trying to get to bottom of this I configured everything from scratch on another Win 7 64-bit machine using following:

After making sure all is added to %PATH% I tried to compile the example and got exactly same set of errors as on the first machine.
Dunno how useful this will be for you but I just wanted to let you know in case you want to check if there is problem related to 64-bit Windows.

@xlab
Copy link
Member

xlab commented Nov 1, 2016

@remorez It turns out there is a problem with CGO and MinGW as of today, I've found these issues as well:

The latter says this will be fixed in 1.8 (Feb, 2017).
But the first one provides a temporary solution and it worked for me! A MinGW64 build completed with no errors after the fix: -Wl,--allow-multiple-definition. I updated the files.

Try it out please.

@remorez
Copy link
Author

remorez commented Nov 1, 2016

With your help @xlab I finally made this running on my Win7 64-bit.
To make example compile I ran following command from Git Shell:
CGO_CFLAGS="-I/c/dev/glfw/include" CGO_LDFLAGS="-L/c/dev/glfw/lib-mingw-w64" go build -o "$GOPATH/bin/nuklear.exe" -ldflags "-extldflags=-Wl,--allow-multiple-definition" github.com/golang-ui/nuklear/cmd/nk-example

@xlab
Copy link
Member

xlab commented Nov 1, 2016

@remorez I included that flag into the file that links GLFW, so should be working even without that extra flag by hand. Glad it finally worked, have fun.

@wsw0108
Copy link

wsw0108 commented Mar 27, 2018

After upgrade go to 1.8.7/1.9.4/1.10, then environment variable CGO_LDFLAGS_ALLOW should be set to -Wl,--allow-multiple-definition.

Reference: golang/go#23672

CGO_LDFLAGS_ALLOW='-Wl,--allow-multiple-definition' go get/install
$env:CGO_LDFLAGS_ALLOW='-Wl,--allow-multiple-definition'
go get/install

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

No branches or pull requests

3 participants