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

cmd/cgo: how to use third part framework? #32686

Closed
YUSHEN2015 opened this issue Jun 19, 2019 · 7 comments

Comments

@YUSHEN2015
Copy link

commented Jun 19, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.6 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/youchain-y/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/youchain-y/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.6/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.6/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/y5/zq0rjb2s7ggc_y4qk8k45k440000gn/T/go-build774485073=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

#cgo LDFLAGS: -framework third-part-framework

What did you expect to see?

third part framework can work

What did you see instead?

third part framework cannot be found

@agnivade

This comment has been minimized.

Copy link
Member

commented Jun 19, 2019

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jun 19, 2019

What is the exact command that you ran? What is the complete and exact output?

I don't know how the -framework option normally works. Does passing -framework third-part-framework to the linker work when linking a C program?

@ianlancetaylor ianlancetaylor changed the title how to use third part framework by cgo cmd/cgo: how to use third part framework? Jun 19, 2019

@YUSHEN2015

This comment has been minimized.

Copy link
Author

commented Jun 20, 2019

Sorry,
I know how to use the system framework of system in folder "/System/Library/Frameworks" like below,
/* #cgo LDFLAGS: -framework CoreFoundation #include <CoreFoundation/CoreFoundation.h> */
but I don't know how to use the framework created by myself.

@agnivade agnivade added the Question label Jun 20, 2019

@AlexRouSg

This comment has been minimized.

Copy link
Contributor

commented Jun 20, 2019

You need to install your framework to the expected location.
See: https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/InstallingFrameworks.html#//apple_ref/doc/uid/20002261-BBCCFBJA

If not you need to use the -F flag to specify a location to look for it.
See: https://clang.llvm.org/docs/ClangCommandLineReference.html#introduction

For proper help I suggest you ask around in the normal OSX developer places as this is not a Go specific thing. https://developer.apple.com/support/

@YUSHEN2015

This comment has been minimized.

Copy link
Author

commented Jun 20, 2019

Thank you,
I can use framework normally if the framework is build by xcode in the below way,
#cgo LDFLAGS: -F ${SRCDIR} -framework xxx.framework
but I have a framework that I build by go mobile, and I encountered some error in this way, as below:
duplicate symbol __cgo_panic in: $WORK/b001/_cgo_main.o ./framework/Mobile.framework/Mobile(go.o) duplicate symbol __cgo_topofstack in: $WORK/b001/_cgo_main.o ./framework/Mobile.framework/Mobile(go.o) duplicate symbol _crosscall2 in: $WORK/b001/_cgo_main.o ./framework/Mobile.framework/Mobile(go.o) duplicate symbol __cgo_wait_runtime_init_done in: $WORK/b001/_cgo_main.o ./framework/Mobile.framework/Mobile(000012.o) ld: 4 duplicate symbols for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

@AlexRouSg

This comment has been minimized.

Copy link
Contributor

commented Jun 20, 2019

If there are C/C++/etc... sources in the same folder as Go sources, they will automatically be compiled and included into the Go program without -framework. So by putting the -framework flag you are telling it to include them twice.

Also should mention, you should not compile with gomobile and trying to include that into another Go program/library.

@andybons

This comment has been minimized.

Copy link
Member

commented Aug 12, 2019

Hi there,
We have decided that our experiment to allow questions on the issue tracker has not had the outcome we desired, so I am closing this issue. I'm sorry that we can't continue to answer your question here.

There are many other methods to get help if you're still looking for answers:

Thanks

@andybons andybons closed this Aug 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.