问题描述
我正在尝试从源代码构建mysql-connector-c(每条指令),并在我的应用程序中静态链接库。不过,我收到以下警告,并且想知道是否有人对此有何看法:
/ path / to /lib/libmysqlclient.a(mf_pack.co):函数`unpack_dirname':
mf_pack.c :(。text + 0x90b):warning:在静态链接的
应用程序中使用'getpwnam'需要在运行时glibc版本
用于链接
/path/to/lib/libmysqlclient.a(libmysql.co)的共享库:函数`read_user_name':
libmysql.c :(。 text + 0x2b06):警告:在静态链接的
应用程序中使用'getpwuid'需要在运行时从glibc版本获得共享库
用于链接
/path/to/lib/libmysqlclient.a (mf_pack.co):函数`unpack_dirname':
mf_pack.c :(。text + 0x916):warning:在静态链接的
应用程序中使用'endpwent'需要在运行时从glibc版本
用于链接
/path/to/lib/libmysqlclient.a(client.co):在函数`mys ql_real_connect':
client.c :(。text + 0x305c):warning:在静态链接的
应用程序中使用'getaddrinfo'需要在运行时从glibc版本
的共享库中链接
/path/to/lib/libmysqlclient.a(libmysql.co):函数`mysql_server_init':
libmysql.c :(。text + 0x2f9b):warning:在静态链接$中使用'getservbyname' b $ b应用程序在运行时需要glibc版本的共享库
用于链接
下面是一些相关的参数/标记:
为了构建库,CMake被传递给以下代码:
-GUnix Makefiles-DCMAKE_INSTALL_PREFIX = / path / to / my / install / root -DCMAKE_C_FLAGS = - m64-DCMAKE_CXX_FLAGS = - m64
用于构建应用程序: Werror -Wall -ggdb -gdwarf-2
LDFLAGS:= $(LDFLAGS)-static -ggdb -gdwarf-2
内部GLibC名称服务切换(NSS)机制: b
$ b
由于NSS机制依赖动态链接到工作时,您需要在运行时使用适当的NSS模块(其中大部分都带有glibc),以便能够使用这些函数,而不管您是否静态或动态链接到C库本身。警告在那里提醒你,你真的会在运行时需要这些模块;试图在一个没有NSS模块的盒子上运行链接的二进制文件将会在运行时失败,从ld.so的错误抱怨说它找不到'libnss_files.so.2'或其他类似的东西。
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:
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.
这篇关于在针对mysql-connector-c / libmysqlclient / mysql C API构建应用程序时链接程序警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!