libnss mysql,在针对mysql-connector-c / libmysqlclient / mysql C API构建应用程序时链接程序警告...

I am trying to build mysql-connector-c from source(per instructions here) and statically link against the library in my application. However I am getting the following warnings and I was wondering if anyone has any ideas as to why this is:

/path/to/lib/libmysqlclient.a(mf_pack.c.o): In function `unpack_dirname':

mf_pack.c:(.text+0x90b): warning: Using 'getpwnam' in statically linked

applications requires at runtime the shared libraries from the glibc version

used for linking

/path/to/lib/libmysqlclient.a(libmysql.c.o): In function `read_user_name':

libmysql.c:(.text+0x2b06): warning: Using 'getpwuid' in statically linked

applications requires at runtime the shared libraries from the glibc version

used for linking

/path/to/lib/libmysqlclient.a(mf_pack.c.o): In function `unpack_dirname':

mf_pack.c:(.text+0x916): warning: Using 'endpwent' in statically linked

applications requires at runtime the shared libraries from the glibc version

used for linking

/path/to/lib/libmysqlclient.a(client.c.o): In function `mysql_real_connect':

client.c:(.text+0x305c): warning: Using 'getaddrinfo' in statically linked

applications requires at runtime the shared libraries from the glibc version

used for linking

/path/to/lib/libmysqlclient.a(libmysql.c.o): In function `mysql_server_init':

libmysql.c:(.text+0x2f9b): warning: Using 'getservbyname' in statically linked

applications requires at runtime the shared libraries from the glibc version

used for linking

Here are some of the relevant args/flags:

For building the library CMake is being passed in the following:

-G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/path/to/my/install/root -DCMAKE_C_FLAGS="-m64" -DCMAKE_CXX_FLAGS="-m64"

For building the application:

CFLAGS := $(CFLAGS) -Werror -Wall -ggdb -gdwarf-2

LDFLAGS := $(LDFLAGS) -static -ggdb -gdwarf-2

解决方案

These warnings occur because the GLibC functions in question use the GLibC Name Service Switch (NSS) mechanism internally:

The basic idea is to put the implementation of the different services offered to access

the databases in separate modules. This has some advantages:

Contributors can add new services without adding them to the GNU C Library.

The modules can be updated separately.

The C library image is smaller.

To fulfill the first goal above the ABI of the modules will be described below. For

getting the implementation of a new service right it is important to understand how the

functions in the modules get called. They are in no way designed to be used by the

programmer directly. Instead the programmer should only use the documented and

standardized functions to access the databases.

Since the NSS mechanism relies on dynamic linking to work, you need the appropriate NSS modules (most of which come with glibc) at runtime in order to be able to use these functions, irrespective of whether you have statically or dynamically linked to the C library itself. The warnings are there to alert you that you really will need those modules at runtime; trying to run the linked binary on a box with no NSS modules on it will fail at runtime with an error from ld.so complaining that it can't find 'libnss_files.so.2' or some other thing of that ilk.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值