go-flutter-desktop / go-flutter

Flutter on Windows, MacOS and Linux - based on Flutter Embedding, Go and GLFW.
https://hover.build/
BSD 3-Clause "New" or "Revised" License
5.85k stars 283 forks source link

mac build failing on export CGO_LDFLAGS="-F${PWD} -Wl,-rpath,@executable_path" #93

Closed ghost closed 5 years ago

ghost commented 5 years ago

Flutter version

x-MacBook-Pro:go-flutter apple$ flutter --version
Flutter 1.2.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 8661d8aecd (5 weeks ago) • 2019-02-14 19:19:53 -0800
Engine • revision 3757390fa4
Tools • Dart 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)

Golang errors (Optional)

x-MacBook-Pro:go-flutter apple$
# pub get
cd /Users/apple/workspace/go/src/github.com/go-flutter-desktop/go-flutter/example/simpleDemo/flutter_project/demo && flutter packages get
Running "flutter packages get" in demo...                           0.6s

# go into standard Flutter project and run special bundler
cd /Users/apple/workspace/go/src/github.com/go-flutter-desktop/go-flutter/example/simpleDemo/flutter_project/demo && flutter build bundle 

go get -u -v github.com/go-flutter-desktop/go-flutter
github.com/go-flutter-desktop/go-flutter (download)
github.com/go-gl/glfw (download)
github.com/pkg/errors (download)
runtime/cgo
# runtime/cgo
clang: error: no such file or directory: '"-F/Users/apple/workspace/go/src/github.com/go-flutter-desktop/go-flutter/example/simpleDemo'
make: *** [flu-desk-run] Error 2
x-MacBook-Pro:go-flutter apple$ 

Steps to Reproduce

ghost commented 5 years ago

The directory IS there. Must be something else i am doing wrong ? Rerun the downloader already.


x-MacBook-Pro:simpleDemo apple$ ls -al /Users/apple/workspace/go/src/github.com/go-flutter-desktop/go-flutter/example/simpleDemo
total 1768
drwxr-xr-x  10 apple  staff     320 Mar 20 08:49 .
drwxr-xr-x   4 apple  staff     128 Mar 20 08:49 ..
drwxr-xr-x   7 apple  staff     224 Mar 20 08:49 .build
-rw-r--r--   1 apple  staff      16 Mar 20 08:49 .gitignore
drwxr-xr-x   7 apple  staff     224 Mar 20 08:49 FlutterEmbedder.framework
drwxr-xr-x   3 apple  staff      96 Mar 20 08:49 assets
-rw-r--r--   1 apple  staff    8638 Mar 20 08:49 engineDownloader.go
drwxr-xr-x   3 apple  staff      96 Mar 20 08:49 flutter_project
-rw-r--r--   1 apple  staff  883280 Mar 20 08:49 icudtl.dat
-rw-r--r--   1 apple  staff    3197 Mar 20 08:49 main.go
pchampio commented 5 years ago

Can you try export CGO_LDFLAGS="-F. -Wl,-rpath,@executable_path" instead of export CGO_LDFLAGS="-F${PWD} -Wl,-rpath,@executable_path"

(In the /Users/apple/workspace/go/src/github.com/go-flutter-desktop/go-flutter/example/simpleDemo dir)

ghost commented 5 years ago

@Drakirus thanks for your help.

I got the same result using export CGO_LDFLAGS="-F. -Wl,-rpath,@executable_path"

clang: error: no such file or directory: '"-F.'

I am trying to automate this to finally build a standard magefile we can all use. Using Makefile for now to workout the flow.

a usr only need to run:

  1. make dep
  2. make flu-dep
  3. Make flu-desk-run
    • flu-desk-run is where it errors

my current Makefile

# github.com/go-flutter-desktop/go-flutter

NAME=go-flutter
BRANCH=master
LIB=github.com/go-flutter-desktop/$(NAME)
LIB_FSPATH=$(GOPATH)/src/$(LIB)

FLU_EX=example/simpleDemo
FLU_EX_FSPATH=$(LIB_FSPATH)/$(FLU_EX)

print:
    @echo 
    @echo NAME : $(NAME)
    @echo BRANCH : $(BRANCH)
    @echo LIB : $(LIB)
    @echo LIB_FSPATH  : $(LIB_FSPATH)

    @echo 
    @echo FLU_EX :$(FLU_EX)
    @echo FLU_EX_FSPATH  : $(FLU_EX_FSPATH)
    @echo

dep-all: dep-os dep dep-modules
    # get all deps

dep-os:

    # dev tools
    go get github.com/cortesi/devd/cmd/devd

dep:
    ## install on gopath
    mkdir -p $(LIB_FSPATH)
    cd $(LIB_FSPATH) && cd .. && rm -rf $(NAME) && git clone https://$(LIB).git

    # THIS IS WHERE THE CODE IS.
    cd $(LIB_FSPATH) && git checkout $(BRANCH)

dep-status:
    cd $(LIB_FSPATH) && git status

dep-modules:
    # nil

code:
    cd $(LIB_FSPATH) && code .

clean:
    # gopath
    rm -rf $(LIB_FSPATH)

### Build

qlog:
    # for debugging...
    tail -f $(TMPDIR)/q

flu-dep:
    # grab the go flutter embedder
    # Its in the simpleDemo folder ( dumb, but anyway)
    cd $(FLU_EX_FSPATH) && go run engineDownloader.go

flu-mob-run: flu-dep
    flutter emulators --launch apple_ios_simulator
    cd $(FLU_EX_FSPATH) && flutter run

#export CGO_LDFLAGS="-F${FLU_EX_FSPATH} -Wl,-rpath,@executable_path"
export CGO_LDFLAGS="-F. -Wl,-rpath,@executable_path"
flu-desk-run:
    # pub get
    cd $(FLU_EX_FSPATH)/flutter_project/demo && flutter packages get

    # go into standad Flutter project and run special bundler
    cd $(FLU_EX_FSPATH)/flutter_project/demo && flutter build bundle 

    # Get the libraries
    # REQUIRED before every `go build`. The CGO compiler need to know where to look for the share library
    #export CGO_LDFLAGS="-F${PWD} -Wl,-rpath,@executable_path"

    # The share library must stay next to the generated binary.
    go get -u -v $(LIB)

    # Build the example project
    cd $(FLU_EX_FSPATH) && go build -v main.go
pchampio commented 5 years ago

Does it work when you aren't using Make?

ghost commented 5 years ago

ok let me try using a .sh down in the dir. will take a few minutes

ghost commented 5 years ago

Ok so i made a run.sh that i just copy into the Demo directory from the Makefile

Make file:

flu-desk-run:
    # pub get
    cd $(FLU_EX_FSPATH)/flutter_project/demo && flutter packages get

    # go into standard Flutter project and run special bundler
    cd $(FLU_EX_FSPATH)/flutter_project/demo && flutter build bundle    

    # The share library must stay next to the generated binary.
    go get -u -v $(LIB)

    # Build the example project
    cp run.sh $(FLU_EX_FSPATH) && chmod +x $(FLU_EX_FSPATH)/run.sh
    cd $(FLU_EX_FSPATH) && go build main.go

run.sh file:

export CGO_LDFLAGS="-F. -Wl,-rpath,@executable_path"
go build main.go

shell log:


x-MacBook-Pro:simpleDemo apple$ ./run.sh
# github.com/go-flutter-desktop/go-flutter/embedder
ld: framework not found FlutterEmbedder
clang: error: linker command failed with exit code 1 (use -v to see invocation)

x-MacBook-Pro:simpleDemo apple$ pwd
/Users/apple/workspace/go/src/github.com/go-flutter-desktop/go-flutter/example/simpleDemo

x-MacBook-Pro:simpleDemo apple$ ls -al
total 1776
drwxr-xr-x  11 apple  staff     352 20 Mar 10:47 .
drwxr-xr-x   4 apple  staff     128 20 Mar 08:49 ..
drwxr-xr-x   7 apple  staff     224 20 Mar 08:49 .build
-rw-r--r--   1 apple  staff      16 20 Mar 08:49 .gitignore
drwxr-xr-x   7 apple  staff     224 20 Mar 08:49 FlutterEmbedder.framework
drwxr-xr-x   3 apple  staff      96 20 Mar 08:49 assets
-rw-r--r--   1 apple  staff    8638 20 Mar 08:49 engineDownloader.go
drwxr-xr-x   3 apple  staff      96 20 Mar 08:49 flutter_project
-rw-r--r--   1 apple  staff  883280 20 Mar 08:49 icudtl.dat
-rw-r--r--   1 apple  staff    3197 20 Mar 08:49 main.go
-rwxr-xr-x   1 apple  staff      72 20 Mar 10:47 run.sh
pchampio commented 5 years ago

Clang's framework search paths seems to ignore CGO_LDFLAGS="-F${PWD}". Just like #34 (Windows case).

A quick and dirty solution would be to throw FlutterEmbedder.framework file into /usr/local/lib. (Since we use -rpath,@executable_path, /usr/local/lib/FlutterEmbedder.framework will not be use at runtime)

Edit: The clang: error: no such file or directory: '"-F.' error is related to Make.

ghost commented 5 years ago

thanks !

SO i got it working with CGO_LDFLAGS="-F${PWD}". on mac after all.

Now i can make the Magefile :)

But i like your idea of making CGO use the /usr/local/lib How will this affect deployment ? This will mean that when we package an a Mac OS package it will rely on FlutterEmbedder.framework existing in /usr/local/lib ?

pchampio commented 5 years ago

SO i got it working with CGO_LDFLAGS="-F${PWD}". on mac after all.

Please share with us how you managed to fix the issue!!

How will this affect deployment ? This will mean that when we package an a Mac OS package it will rely on FlutterEmbedder.framework existing in /usr/local/lib ?

Again, Since we use -rpath,@executable_path, the FlutterEmbedder.framework located in /usr/local/lib will only be used at compiling-time (when linking to be more precise).

More info at https://wincent.com/wiki/%40executable_path%2C_%40load_path_and_%40rpath and https://github.com/go-flutter-desktop/go-flutter/issues/34#issuecomment-442375520

ghost commented 5 years ago

I will share :). Just gotta finish the Mage file so its cross platform.

But it would be good to do it right, so i need to know about packaging. If i use /usr/local/lib, then when packaged and distributed then that directory will need to be there with the FlutterEmbedder.framework there ?

pchampio commented 5 years ago

no

ghost commented 5 years ago

ok thanks. Will get back to you if i get everything working.

ghost commented 5 years ago

I got it all working.

@GeertJohan @Drakirus DO you want the Mage file ?

ghost commented 5 years ago

actually closing this because its relating to another issue. Will open a new one