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

Fails to Build: `undefined reference to `libintl_bind_textdomain_codeset'` #1

Open
systmkor opened this Issue May 10, 2015 · 3 comments

Comments

Projects
None yet
4 participants
@systmkor
Copy link

systmkor commented May 10, 2015

Environment

  • Alpine Linux 3.2.0 RC2
  • musl-1.1.8 (libc)
  • gettext-0.19.4 (gnu)
  • go-1.4.2
  • gettext commit 98b7b91

Error

After running make or trying to just run go get github.com/lxc/lxd . The gettext errors are produced as shown below.

go build
# _/home/admin/src/port2port/lxc/gettext
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_bind_textdomain_codeset':
./gettext.go:64: undefined reference to `libintl_bind_textdomain_codeset'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_bindtextdomain':
./gettext.go:78: undefined reference to `libintl_bindtextdomain'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_dcgettext':
./gettext.go:94: undefined reference to `libintl_dcgettext'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_dcngettext':
./gettext.go:112: undefined reference to `libintl_dcngettext'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_dgettext':
./gettext.go:126: undefined reference to `libintl_dgettext'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_dngettext':
./gettext.go:142: undefined reference to `libintl_dngettext'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_gettext':
./gettext.go:164: undefined reference to `libintl_gettext'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_ngettext':
./gettext.go:179: undefined reference to `libintl_ngettext'
/tmp/go-build148138563/_/home/admin/src/port2port/lxc/gettext/_obj/gettext.cgo2.o: In function `_cgo_b28bc486a664_Cfunc_textdomain':
./gettext.go:207: undefined reference to `libintl_textdomain'
collect2: error: ld returned 1 exit status

Fix

Tell cgo to link libintl by changing line 26 of gettext.go from /* to

// #cgo LDFLAGS: -lintl

and then insert /* into line 27 of the same file.

Go Test

go build
go test
¡Hola mundo!
Una manzana
3 manzanas
Buenos días
¡Hasta luego!
Hallo, Welt!
Ein Apfel
3 Äpfel
Guten morgen
Aufwiedersehen!
PASS
ok      _/home/admin/src/port2port/lxc/gettext  0.002s

xiam added a commit that referenced this issue Feb 20, 2016

@xiam

This comment has been minimized.

Copy link
Contributor

xiam commented Feb 20, 2016

I have not experimented this until very recently on a mac, and your line solved the problem. However it does not compile on Fedora, I still don't know the reason but I added a comment with your solution. I'm gonna keep this open because this is not really fixed. Thanks!

@xiam xiam changed the title Fails to Build Fails to Build: `undefined reference to `libintl_bind_textdomain_codeset'` Feb 20, 2016

@chr4

This comment has been minimized.

Copy link

chr4 commented Feb 28, 2016

To fix a similar issue on osx, use this instead:

The error:

./gettext.go:29:10: fatal error: 'libintl.h' file not found

The fix:

Install gettext with homebrew brew install gettext

Update gettext.go

// Package gettext provides bindings for GNU Gettext.
package gettext

/*
#cgo LDFLAGS: -L/usr/local/opt/gettext/lib -lintl
#cgo CPPFLAGS: -I/usr/local/opt/gettext/include

#include <libintl.h>

#include <locale.h>
#include <stdlib.h>
*/
import "C" 

import (
    "fmt"
    "strings"
    "unsafe"
)

[...]
@Slach

This comment has been minimized.

Copy link

Slach commented Jan 26, 2018

for cygwin install gettext, gettext-devel and libintl-devel packages
and add following lines

#cgo LDFLAGS: -L/cygdrive/c/cygwin/lib
#cgo LDFLAGS: -lintl
#cgo CPPFLAGS: -I/cygdrive/c/cygwin/usr/include
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment