Open dpanic opened 3 years ago
I tried with this:
// #cgo android,amd64 LDFLAGS: -L${SRCDIR}/../dependencies/libs/x86_64 -lopencv_calib3d -lopencv_core -lopencv_dnn -lopencv_features2d -lopencv_flann -lopencv_gapi -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_video -lopencv_videoio
But it doesn't work, as this is project which is external dependency, I can't change their files. Changing in my files which imports packages from that project doesn't work.
I would be happy to do a PR. My idea is the following:
Implement CGOLDFLAGS%GOOS_%ARCH with fallback to CGO_LDFLAGS.
Examples:
/cc @hyangah
you can use LDFLAGS
#cgo CFLAGS: -I${SRCDIR}/vendor/headers
#cgo CPPFLAGS: -I${SRCDIR}/vendor/headers
#cgo !windows,!ios,!android pkg-config: opencv4
#cgo CXXFLAGS: --std=c++11
#cgo darwin,amd64,ios LDFLAGS: -F${SRCDIR}/vendor/libs/ios -framework Foundation -framework CoreVideo -framework CoreMedia -framework AVFoundation -framework CoreGraphics -framework opencv2 -miphoneos-version-min=9.0
#cgo darwin,arm64,ios CFLAGS: -I${SRCDIR}/vendor/headers
#cgo darwin,arm64,ios LDFLAGS: -F${SRCDIR}/vendor/libs/ios -framework Foundation -framework CoreVideo -framework CoreMedia -framework AVFoundation -framework CoreGraphics -framework opencv2 -miphoneos-version-min=9.0
#cgo android LDFLAGS: -lopencv_core -lopencv_imgproc -lz -llog
#cgo android,arm64 LDFLAGS: -L${SRCDIR}/vendor/libs/android/sdk/native/staticlibs/arm64-v8a
#cgo android,arm LDFLAGS: -L${SRCDIR}/vendor/libs/android/sdk/native/staticlibs/armeabi-v7a
#cgo android,amd64 LDFLAGS: -L${SRCDIR}/vendor/libs/android/sdk/native/staticlibs/x86_64
#cgo android,386 LDFLAGS: -L${SRCDIR}/vendor/libs/android/sdk/native/staticlibs/x86
and if you use go mod add this line in go.mod
replace github.com/hybridgroup/go-cv => ../../hybridgroup/go-cv
you can use LDFLAGS
#cgo CFLAGS: -I${SRCDIR}/vendor/headers #cgo CPPFLAGS: -I${SRCDIR}/vendor/headers #cgo !windows,!ios,!android pkg-config: opencv4 #cgo CXXFLAGS: --std=c++11 #cgo darwin,amd64,ios LDFLAGS: -F${SRCDIR}/vendor/libs/ios -framework Foundation -framework CoreVideo -framework CoreMedia -framework AVFoundation -framework CoreGraphics -framework opencv2 -miphoneos-version-min=9.0 #cgo darwin,arm64,ios CFLAGS: -I${SRCDIR}/vendor/headers #cgo darwin,arm64,ios LDFLAGS: -F${SRCDIR}/vendor/libs/ios -framework Foundation -framework CoreVideo -framework CoreMedia -framework AVFoundation -framework CoreGraphics -framework opencv2 -miphoneos-version-min=9.0 #cgo android LDFLAGS: -lopencv_core -lopencv_imgproc -lz -llog #cgo android,arm64 LDFLAGS: -L${SRCDIR}/vendor/libs/android/sdk/native/staticlibs/arm64-v8a #cgo android,arm LDFLAGS: -L${SRCDIR}/vendor/libs/android/sdk/native/staticlibs/armeabi-v7a #cgo android,amd64 LDFLAGS: -L${SRCDIR}/vendor/libs/android/sdk/native/staticlibs/x86_64 #cgo android,386 LDFLAGS: -L${SRCDIR}/vendor/libs/android/sdk/native/staticlibs/x86
and if you use go mod add this line in go.mod
replace github.com/hybridgroup/go-cv => ../../hybridgroup/go-cv
Hey, thank you for the efforts. That would work if I make that imported lib in vendor folder... But that is exactly what I don't want to do, to change other peoples code.
I am perfectly aware of compiler directives such as #cgo ...
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am trying to build .aar archive with gomobile bind but with CGO_LDFLAGS and CGO_CPPFLAGS which are TARGET dependant.
I can build for loop, to create 4 .aar files and to manually combine them at the end, but I think there should be smarter way.
What did you expect to see?
AAR file with compiled .so libraries without issues.
What did you see instead?