gpt4 book ai didi

mysql - 针对 mysql-connector-c/libmysqlclient/mysql C API 构建应用程序时的链接器警告

转载 作者:IT王子 更新时间:2023-10-28 23:50:31 24 4
gpt4 key购买 nike

我正在尝试从源代码构建 mysql-connector-c(根据指令 here )并静态链接到我的应用程序中的库。但是,我收到以下警告,我想知道是否有人对这是为什么有任何想法:

/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_INSTALL_PREFIX=/path/to/my/install/root -DCMAKE_C_FLAGS="-m64"-DCMAKE_CXX_FLAGS="-m64"

用于构建应用程序:

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

最佳答案

出现这些警告是因为有问题的 GLibC 函数使用了 GLibC Name Service Switch (NSS)内部机制:

The basic idea is to put the implementation of the different services offered to access the databases in separate modules. This has some advantages:

  1. Contributors can add new services without adding them to the GNU C Library.
  2. The modules can be updated separately.
  3. 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.

由于 NSS 机制依赖于动态链接来工作,因此无论您是静态链接还是动态链接,您都需要在运行时使用适当的 NSS 模块(其中大部分随 glibc 一起提供)才能使用这些功能C库本身。那里的警告是为了提醒您在运行时您确实需要这些模块;尝试在没有 NSS 模块的盒子上运行链接的二进制文件将在运行时失败,并出现来自 ld.so 的错误,提示它找不到“libnss_files.so.2”或类似的东西。

关于mysql - 针对 mysql-connector-c/libmysqlclient/mysql C API 构建应用程序时的链接器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5426420/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com