gl_locale_name

本文介绍了解决在构建gettext时遇到的“gl_locale_name”未定义错误的方法。通过使用gnulib工具导入相应的头文件和源代码,成功解决了跨编译时的链接错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

When making libgettext, I got an error: undefined reference to gl_locale_name.
By google, I got to know one guy said in http://stackoverflow.com/questions/2753996/is-there-a-way-to-access-the-locale-used-by-gettext-under-windows:
Turns out the "gl_locale_name" function was not part of gettext directly, but rather part of gnulib - http://www.gnu.org/software/gnulib. I just discovered the package today.

So getting the infamous localename.h header in my project was a matter of

gnulib-tool --import localename
Then the gl_locale_name function works just fine when cross-compiling.

Thanks to everyone for the answers !

So I tried to find out how to use gnulib, and got the following from http://www.gnu.org/software/gnulib/manual/html_node/index.html#Top:

Invoking ‘gnulib-tool --import’ will copy source files, create a Makefile.am to build them, generate a file gnulib-comp.m4 with Autoconf M4 macro declarations used by configure.ac, and generate a file gnulib-cache.m4 containing the cached specification of how Gnulib is used.

Our example will be a library that uses Autoconf, Automake and Libtool. It calls strdup, and you wish to use gnulib to make the package portable to C89 and C99 (which don't have strdup).

~/src/libfoo$ gnulib-tool --import strdup
Module list with included dependencies:
absolute-header
extensions
strdup
string
File list:
lib/dummy.c
lib/strdup.c
lib/string.in.h
m4/absolute-header.m4
m4/extensions.m4
m4/gnulib-common.m4
m4/strdup.m4
m4/string_h.m4
Creating directory ./lib
Creating directory ./m4
Copying file lib/dummy.c
Copying file lib/strdup.c
Copying file lib/string.in.h
Copying file m4/absolute-header.m4
Copying file m4/extensions.m4
Copying file m4/gnulib-common.m4
Copying file m4/gnulib-tool.m4
Copying file m4/strdup.m4
Copying file m4/string_h.m4
Creating lib/Makefile.am
Creating m4/gnulib-cache.m4
Creating m4/gnulib-comp.m4
Finished.

You may need to add #include directives for the following .h files.
#include <string.h>

Don't forget to
- add "lib/Makefile" to AC_CONFIG_FILES in ./configure.ac,
- mention "lib" in SUBDIRS in Makefile.am,
- mention "-I m4" in ACLOCAL_AMFLAGS in Makefile.am,
- invoke gl_EARLY in ./configure.ac, right after AC_PROG_CC,
- invoke gl_INIT in ./configure.ac.
~/src/libfoo$

and then I happened search gl_locale_name in the gettext folder, and got several gl_locale_name.o, and the gnulib-lib/localename.o is ok.
Then I added the file to the link:
am_msginit_OBJECTS = ../gnulib-lib/localename.o msginit-msginit.$(OBJEXT) \
msginit-lang-table.$(OBJEXT) msginit-plural-count.$(OBJEXT) \
msginit-localealias.$(OBJEXT) msginit-lock.$(OBJEXT)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值