针对mysql-connector-c/libmysqlclient/mysql c API构建应用程序时链接器警告
我正在尝试从源代码(按照指令)构建mysql-connector-c,并在应用程序中静态链接库。然而,我收到了以下警告,我想知道是否有人知道这是为什么:针对mysql-connector-c/libmysqlclient/mysql c API构建应用程序时链接器警告,mysql,gcc,linker,mysql-connector,linker-warning,Mysql,Gcc,Linker,Mysql Connector,Linker Warning,我正在尝试从源代码(按照指令)构建mysql-connector-c,并在应用程序中静态链接库。然而,我收到了以下警告,我想知道是否有人知道这是为什么: /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 r
/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
以下是一些相关参数/标志:
对于构建库,CMake将按以下方式传递:
-G“Unix Makefiles”-DCMAKE\u INSTALL\u PREFIX=/path/to/my/INSTALL/root-DCMAKE\u C\u FLAGS=“-m64”-DCMAKE\u CXX\u FLAGS=“-m64”
要构建应用程序,请执行以下操作:
CFLAGS := $(CFLAGS) -Werror -Wall -ggdb -gdwarf-2
LDFLAGS := $(LDFLAGS) -static -ggdb -gdwarf-2
也许您应该静态链接glibc:
-static libgcc
出现这些警告是因为所讨论的glibc函数在内部使用该机制:
其基本思想是将提供给访问的不同服务的实现
数据库在不同的模块中运行。这有一些好处:
由于NSS机制依赖于动态链接才能工作,因此在运行时需要适当的NSS模块(其中大多数模块随glibc提供),以便能够使用这些函数,而不管您是静态链接到C库还是动态链接到C库本身。警告提醒您在运行时确实需要这些模块;试图在一个没有NSS模块的盒子上运行链接的二进制文件将在运行时失败,因为ld会出错。因此,它会抱怨找不到“libnss_files.so.2”或其他类似的东西。这些警告仍然会出现,同时指定了所有三个
-static-static-libgcc-static libstdc++
。这根本无法回答OP的问题。看到我下面的答案。我想这应该是答案,因为我也遇到了同样的问题,并且知道这是由于解释的原因发生的。