Open sachin-walia opened 8 years ago
There are some articles about building go apps with statically linked libraries:
I tried with both of them without success.
musl-gcc
$ CC=$(which musl-gcc) go build --ldflags '-w -linkmode external -extldflags "-static"'
# github.com/h2non/imaginary
/usr/lib/go-1.6/pkg/tool/linux_amd64/link: running /usr/bin/musl-gcc failed: exit status 1
/usr/bin/ld: cannot find -lgobject-2.0
/usr/bin/ld: cannot find -lglib-2.0
collect2: error: ld returned 1 exit status
gccgo
$ go build -compiler gccgo --gccgoflags "-static"
# github.com/h2non/imaginary
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/metadata.go:35: error: undefined reference to 'g_object_unref'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/metadata.go:41: error: undefined reference to 'vips_thread_shutdown'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:142: error: undefined reference to 'vips_type_find'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:121: error: undefined reference to 'vips_type_find'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:124: error: undefined reference to 'vips_type_find'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:127: error: undefined reference to 'vips_type_find'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:183: error: undefined reference to 'vips_image_get_typeof'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:184: error: undefined reference to 'vips_image_get_string'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:193: error: undefined reference to 'vips_interpolate_new'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:194: error: undefined reference to 'vips_interpolate_get_window_size'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:195: error: undefined reference to 'g_object_unref'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:201: error: undefined reference to 'vips_interpretation_get_type'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:216: error: undefined reference to 'vips_embed'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:213: error: undefined reference to 'vips_array_double_new'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:214: error: undefined reference to 'vips_embed'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:221: error: undefined reference to 'vips_extract_area'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:226: error: undefined reference to 'vips_colourspace_issupported'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:241: error: undefined reference to 'vips_jpegsave_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:253: error: undefined reference to 'vips_pngsave_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:272: error: undefined reference to 'vips_webpsave_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:293: error: undefined reference to 'vips_array_double_new'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:295: error: undefined reference to 'vips_flatten'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:333: error: undefined reference to 'vips_image_new'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:336: error: undefined reference to 'vips_replicate'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:339: error: undefined reference to 'vips_crop'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:341: error: undefined reference to 'g_object_unref'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:345: error: undefined reference to 'g_object_unref'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:353: error: undefined reference to 'vips_image_new'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:354: error: undefined reference to 'vips_object_get_type'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:354: error: undefined reference to 'g_type_check_instance_cast'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:354: error: undefined reference to 'vips_object_local_array'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:359: error: undefined reference to 'vips_text'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:364: error: undefined reference to 'vips_linear1'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:365: error: undefined reference to 'vips_cast'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:366: error: undefined reference to 'vips_embed'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:374: error: undefined reference to 'vips_image_new'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:386: error: undefined reference to 'vips_black'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:387: error: undefined reference to 'vips_linear'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:388: error: undefined reference to 'vips_cast'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:389: error: undefined reference to 'vips_copy'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:390: error: undefined reference to 'vips_embed'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:397: error: undefined reference to 'vips_ifthenelse'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:420: error: undefined reference to 'vips_sharpen'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:95: error: undefined reference to 'vips_cache_set_trace'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:100: error: undefined reference to 'vips_affine'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:105: error: undefined reference to 'vips_jpegload_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:110: error: undefined reference to 'vips_flip'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:115: error: undefined reference to 'vips_shrink'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:174: error: undefined reference to 'vips_rot'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:172: error: undefined reference to 'vips_rot45'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:174: error: undefined reference to 'vips_rot'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:174: error: undefined reference to 'vips_rot'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:201: error: undefined reference to 'vips_enum_nick'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:206: error: undefined reference to 'vips_zoom'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:231: error: undefined reference to 'vips_image_guess_interpretation'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:236: error: undefined reference to 'vips_colourspace'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:324: error: undefined reference to 'vips_magickload_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:307: error: undefined reference to 'vips_jpegload_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:309: error: undefined reference to 'vips_pngload_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:311: error: undefined reference to 'vips_webpload_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:313: error: undefined reference to 'vips_tiffload_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:317: error: undefined reference to 'vips_gifload_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:319: error: undefined reference to 'vips_pdfload_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:321: error: undefined reference to 'vips_svgload_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:411: error: undefined reference to 'vips_gaussblur'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:41: error: undefined reference to 'g_free'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:50: error: undefined reference to 'vips_image_get_typeof'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:59: error: undefined reference to 'vips_object_print_all'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.h:55: error: undefined reference to 'vips_image_remove'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:83: error: undefined reference to 'vips_cache_set_max'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:89: error: undefined reference to 'vips_cache_set_max_mem'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:107: error: undefined reference to 'vips_concurrency_set'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:131: error: undefined reference to 'vips_error_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:137: error: undefined reference to 'vips_error_clear'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:167: error: undefined reference to 'vips_foreign_find_load_buffer'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:185: error: undefined reference to 'vips_init'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:197: error: undefined reference to 'vips_interpolate_new'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:239: error: undefined reference to 'vips_shutdown'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:245: error: undefined reference to 'vips_tracked_get_allocs'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:251: error: undefined reference to 'vips_tracked_get_mem'
/home/peter/gopath/src/gopkg.in/h2non/bimg.v1/vips.go:257: error: undefined reference to 'vips_tracked_get_mem_highwater'
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgo.a(net.o):function net.lookupPort: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgo.a(net.o):function net.cgoLookupIPCNAME: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
I'm not sure if it's even possible due to the licenses of the various linked libraries. If you want an easily distributable "package" I recommend using the Docker image.
it's possible, just distribute 3rd-party licenses with (or in) your package
I don't have lot of understanding of go packaging so please don't mind if question sounds too basic.
Is it possible to package the binary in such a way that all the required dependencies (libpng, libvips, pango and others) are included in a single executable file?