golang-ui / nuklear

This project provides Go bindings for nuklear.h — a small ANSI C GUI library.
https://github.com/vurtun/nuklear
MIT License
1.57k stars 98 forks source link

building and running on osx issues #3

Closed joeblew99 closed 7 years ago

joeblew99 commented 7 years ago

I am trying to do a build of the example, but got a small issue


x-MacBook-Pro:nk-example apple$ pwd
/Users/apple/workspace/go/src/github.com/golang-ui/nuklear/cmd/nk-example
x-MacBook-Pro:nk-example apple$ go run main.go
# github.com/golang-ui/nuklear/nk
ld: library not found for -lglfw3
clang: error: linker command failed with exit code 1 (use -v to see invocation)

so, i tried to do a build form root, but make fails because it cant find cgogen. where can i get cgogen ?

x-MacBook-Pro:nuklear apple$ pwd
/Users/apple/workspace/go/src/github.com/golang-ui/nuklear
x-MacBook-Pro:nuklear apple$ make
cgogen nk.yml
make: cgogen: No such file or directory
make: *** [all] Error 1

__

Also i checked that glfw works so we knows that good.

x-MacBook-Pro:nuklear apple$ cd $GOPATH/src/github.com/go-gl/glfw/v3.2/glfw
x-MacBook-Pro:glfw apple$ pwd
/Users/apple/workspace/go/src/github.com/go-gl/glfw/v3.2/glfw
x-MacBook-Pro:glfw apple$ ls
GLFW_C_REVISION.txt c_glfw_windows.go   glfw.go         native_darwin.go    vulkan.go
build.go        context.go      input.c         native_linbsd.go    window.c
c_glfw.go       error.c         input.go        native_windows.go   window.go
c_glfw_darwin.go    error.go        monitor.c       time.go
c_glfw_linbsd.go    glfw            monitor.go      util.go
x-MacBook-Pro:glfw apple$ go get -u github.com/go-gl/glfw/v3.2/glfw
x-MacBook-Pro:glfw apple$ pwd
/Users/apple/workspace/go/src/github.com/go-gl/glfw/v3.2/glfw
x-MacBook-Pro:glfw apple$ cd ..
x-MacBook-Pro:v3.2 apple$ pwd
/Users/apple/workspace/go/src/github.com/go-gl/glfw/v3.2
x-MacBook-Pro:v3.2 apple$ cd ..
x-MacBook-Pro:glfw apple$ pwd
/Users/apple/workspace/go/src/github.com/go-gl/glfw
x-MacBook-Pro:glfw apple$ code .
x-MacBook-Pro:glfw apple$ go run main.go
x-MacBook-Pro:glfw apple$ WORKS ! Can see blank screen...
joeblew99 commented 7 years ago

Ok i found cgogen :)

Now have a more helpful erro i hope

x-MacBook-Pro:nuklear apple$ pwd
/Users/apple/workspace/go/src/github.com/golang-ui/nuklear
x-MacBook-Pro:nuklear apple$ make
cgogen nk.yml
  processing nk.yml ⠹[ERR] /usr/local/include/GLFW/glfw3.h:140:12: include file not found: OpenGL/gl.h
make: *** [all] Error 1

Hmm, so lets see whats over there:

x-MacBook-Pro:nuklear apple$ cd /usr/local/include/GLFW
x-MacBook-Pro:GLFW apple$ ls
glfw3.h     glfw3native.h
x-MacBook-Pro:GLFW apple$ 
xlab commented 7 years ago

@joeblew99 Hi!

1) You don't need to run cgogen, it's a developer's tool, used to generate a Go <-> C wrapper for Nuklear.

2) You need to follow OS X installation instructions as in here https://github.com/golang-ui/nuklear#os-x

$ brew install glfw3

To install GLFW3 into your system.

3) Successful compilation of $GOPATH/src/github.com/go-gl/glfw/v3.2/glfw is irrelevant here, because they distribute the sources within and compile them on the fly for their package only. Nuklear C sources themselves need access to GLFW3 shared libs too, those should be installed in system.

I hope this helps.

joeblew99 commented 7 years ago

hey @xlab i already had it installed.

x-MacBook-Pro:GLFW apple$ brew install glfw3
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (dart-lang/dart, homebrew/core).
==> New Formulae
gst-rtsp-server
==> Updated Formulae
heroku

Warning: glfw-3.2.1 already installed
x-MacBook-Pro:GLFW apple$ 

trying the example again:


x-MacBook-Pro:gu-x apple$ cd /Users/apple/workspace/go/src/github.com/golang-ui/nuklear/cmd/nk-example
x-MacBook-Pro:nk-example apple$ go build
# github.com/golang-ui/nuklear/nk
ld: library not found for -lglfw3
clang: error: linker command failed with exit code 1 (use -v to see invocation)
go version
go version go1.7.4 darwin/amd64
xlab commented 7 years ago

@joeblew99 this is strange, the brew libs should be accessible by the linker in default configuration.. By the way, you can avoid this issue by running it that way:

$ CGO_LDFLAGS="-L/usr/local/Cellar/glfw3/3.2.1/lib" go build

Check the correctness of the path. This will tell linker where to search GFLW libs explicitly.

P.S.

$ pkg-config --libs glfw3
-L/usr/local/Cellar/glfw3/3.2.1/lib -lglfw3

suggests correct ldflags

joeblew99 commented 7 years ago

@xlab thanks for the tip...

ok so where does it live ?

x-MacBook-Pro:nuklear apple$ pkg-config --libs glfw3
-L/usr/local/Cellar/glfw/3.2.1/lib -lglfw

so, I try to run the example again hinting the location, but same error:


x-MacBook-Pro:nk-example apple$ pwd
/Users/apple/workspace/go/src/github.com/golang-ui/nuklear/cmd/nk-example
x-MacBook-Pro:nk-example apple$ CGO_LDFLAGS="-L/usr/local/Cellar/glfw/3.2.1/lib" go build
# github.com/golang-ui/nuklear/nk
ld: library not found for -lglfw3
clang: error: linker command failed with exit code 1 (use -v to see invocation)

So, go check the folder for glfw:

x-MacBook-Pro:lib apple$ pwd
/usr/local/Cellar/glfw/3.2.1/lib
x-MacBook-Pro:lib apple$ ls
cmake           libglfw.3.2.dylib   libglfw.3.dylib     libglfw.dylib       pkgconfig

What about building from root ?


x-MacBook-Pro:nuklear apple$ pwd
/Users/apple/workspace/go/src/github.com/golang-ui/nuklear
x-MacBook-Pro:nuklear apple$ make
cgogen nk.yml
  processing nk.yml ⠹[ERR] /usr/local/include/GLFW/glfw3.h:140:12: include file not found: OpenGL/gl.h
make: *** [all] Error 1

SO, it cant find the gl.h file it seems. Lets see if its there:


x-MacBook-Pro:nuklear apple$ cd /usr/local/include/GLFW/
x-MacBook-Pro:GLFW apple$ ls -al
total 336
drwxr-xr-x  4 apple  admin     136 Aug 18 13:32 .
drwxr-xr-x  3 apple  admin     102 Aug 18 13:32 ..
-rw-r--r--  1 apple  admin  152470 Aug 18 13:32 glfw3.h
-rw-r--r--  1 apple  admin   13594 Aug 18 13:32 glfw3native.h
x-MacBook-Pro:GLFW apple$ 

This is a long shot but, I remember a few months ago with OSX update that brew permissions went a bit weird. If there a way to check permissions are correct inside /usr/local/Cellar/glfw/3.2.1/lib ?

xlab commented 7 years ago

@joeblew99 please don't try to run make in this context, it simply starts cgogen which have nothing to do with installation & usage of this package. This is a cool tool though, but let's handle a single problem at a time.

The problem we have is with linker and GLFW shared library.

On my machine:

$ ls -la /usr/local/Cellar/glfw/3.2.1/lib
ls: /usr/local/Cellar/glfw/3.2.1/lib: No such file or directory

$ ls -la /usr/local/Cellar/glfw3/3.2.1/lib
total 232
drwxr-xr-x  7 xlab  wheel     238 Nov 30 23:51 ./
drwxr-xr-x  8 xlab  wheel     272 Dec  6 16:04 ../
drwxr-xr-x  3 xlab  wheel     102 Nov 30 23:51 cmake/
-r--r--r--  1 xlab  wheel  107492 Nov 30 23:51 libglfw3.3.2.dylib
lrwxr-xr-x  1 xlab  wheel      18 Nov 30 23:51 libglfw3.3.dylib@ -> libglfw3.3.2.dylib
lrwxr-xr-x  1 xlab  wheel      16 Nov 30 23:51 libglfw3.dylib@ -> libglfw3.3.dylib
drwxr-xr-x  3 xlab  wheel     102 Nov 30 23:51 pkgconfig/

I think you could reinstall the lib, making sure that no residual files remain. Sorry for such inconvenience, managing shared C dependencies could be painful sometimes (if not always).

joeblew99 commented 7 years ago

Sorry about garbage last message. I deleted it.

i am looking into it.

I uninstalled brew and reinstalled it then did a "brew install glfw3", but it puts it in: ls -la /usr/local/Cellar/glfw/3.2.1/lib

Cant work out why, but i saw it happening on a few other gists on github.

Just not sure whats going on right now...

xlab commented 7 years ago

I reinstalled GLFW3 via brew again and now I have /usr/local/Cellar/glfw/3.2.1/lib too.

Also:

$ ls -la /usr/local/lib/libglfw*
lrwxr-xr-x  1 xlab  wheel      42 Dec  8 16:58 /usr/local/lib/libglfw.3.2.dylib@ -> ../Cellar/glfw/3.2.1/lib/libglfw.3.2.dylib
lrwxr-xr-x  1 xlab  wheel      40 Dec  8 16:58 /usr/local/lib/libglfw.3.dylib@ -> ../Cellar/glfw/3.2.1/lib/libglfw.3.dylib
lrwxr-xr-x  1 xlab  wheel      38 Dec  8 16:58 /usr/local/lib/libglfw.dylib@ -> ../Cellar/glfw/3.2.1/lib/libglfw.dylib
-rw-r--r--  1 xlab  wheel  190944 Nov  6 23:26 /usr/local/lib/libglfw3.a

And nuklear installs fine... :/

xlab commented 7 years ago

Try

go build -v --ldflags '-extldflags "-L/usr/local/lib"'
joeblew99 commented 7 years ago

On so we now have the same location of the libs. But i dont have the "/usr/local/lib/libglfw3.a". Not sure why:

x-MacBook-Pro:nk-example apple$ pwd
/Users/apple/workspace/go/src/github.com/golang-ui/nuklear/cmd/nk-example
x-MacBook-Pro:nk-example apple$ ls -la /usr/local/lib/libglfw*
lrwxr-xr-x  1 apple  admin  42 Dec  8 14:03 /usr/local/lib/libglfw.3.2.dylib -> ../Cellar/glfw/3.2.1/lib/libglfw.3.2.dylib
lrwxr-xr-x  1 apple  admin  40 Dec  8 14:03 /usr/local/lib/libglfw.3.dylib -> ../Cellar/glfw/3.2.1/lib/libglfw.3.dylib
lrwxr-xr-x  1 apple  admin  38 Dec  8 14:03 /usr/local/lib/libglfw.dylib -> ../Cellar/glfw/3.2.1/lib/libglfw.dylib

when i try to build, it fails:

x-MacBook-Pro:nk-example apple$ go build -v --ldflags '-extldflags "-L/usr/local/lib"'
github.com/golang-ui/nuklear/nk
# github.com/golang-ui/nuklear/nk
ld: library not found for -lglfw3
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Because i dont have the "/usr/local/lib/libglfw3.a", its failing ?

xlab commented 7 years ago

I removed it and now my build fails with the same error. Apparently they broke GLFW 6 days ago https://github.com/Homebrew/homebrew-core/commit/283671e26449a6261bda080253229e2bd13b3099

GJ WP -___-

xlab commented 7 years ago

The solution is to install GLFW this way:

$ brew install --without-shared-library glfw3

Now it's ok for me, please check @joeblew99

joeblew99 commented 7 years ago

works for me too, using both ways of building.

go build -v --ldflags '-extldflags "-L/usr/local/lib"'

go build

thanks for adding the brew install instructions to the readme until they fix it, and persisting with me to sort this out. I learnt allot about shared libs just going through this with you.

Shall we close this ?

xlab commented 7 years ago

Might be worth adding the brew install instructions to the readme until they fix it.

Yes, I've added to both READMEs (see commits above). Thanks for your reports, that was tough stuff.