Skip to content

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

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

Closed
ghost opened this issue Mar 20, 2019 · 14 comments
Closed

Comments

@ghost
Copy link

ghost commented Mar 20, 2019

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
Copy link
Author

ghost commented Mar 20, 2019

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
Copy link
Member

pchampio commented Mar 20, 2019

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
Copy link
Author

ghost commented Mar 20, 2019

@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
Copy link
Member

pchampio commented Mar 20, 2019

Does it work when you aren't using Make?

@ghost
Copy link
Author

ghost commented Mar 20, 2019

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

@ghost
Copy link
Author

ghost commented Mar 20, 2019

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
Copy link
Member

pchampio commented Mar 20, 2019

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
Copy link
Author

ghost commented Mar 20, 2019

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
Copy link
Member

pchampio commented Mar 20, 2019

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 #34 (comment)

@ghost
Copy link
Author

ghost commented Mar 20, 2019

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
Copy link
Member

no

@ghost
Copy link
Author

ghost commented Mar 20, 2019

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

@ghost
Copy link
Author

ghost commented Mar 26, 2019

I got it all working.

@GeertJohan @Drakirus DO you want the Mage file ?

@ghost
Copy link
Author

ghost commented Mar 26, 2019

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

@ghost ghost closed this as completed Mar 26, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant