MySQL Forums
Forum List  »  Connector/C++

Link error
Posted by: Chuck Benedict
Date: June 21, 2022 07:52PM

I am using the C++ connector, version 8.0.23 on Windows 10 Pro, under WSL Ubuntu 20.04.1. When I try to build my application, I get the following link error:

/usr/bin/ld: ../bin/lib/linux/Ubuntu20.04/x86_64-linux-gnu/libmysqlcppconn8-static.a(libcdk_foundation_socket_detail.cc.o): in function `cdk::foundation::connection::detail::srv_list(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
(.text+0x9b2): undefined reference to `__res_nsearch'
/usr/bin/ld: (.text+0x9fa): undefined reference to `ns_initparse'
/usr/bin/ld: (.text+0xa5a): undefined reference to `ns_parserr'
/usr/bin/ld: (.text+0xac8): undefined reference to `__dn_expand'
collect2: error: ld returned 1 exit status

The compiler is:
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Note that I am statically linking mysqlcpp, and I have -lresolv included in my command with a -L switch pointing to the dir with all the lib* files, and further, libresolv.a and .so are in that directory. My assumption is that this is a dynamic link to libresolv.so.

Further note that if I change to statically linking to libresolv by taking out -lresolv and instead using /usr/lib/x86_64-linux-gnu/libresolv.a in the linker, I do not get the error and my program works.

Finally, what is most puzzling, is that if I specify -lresolv AFTER my static link reference to mysqlcpp (in the error above, the switch was BEFORE the static link reference), then I do not get the error.

Note that I do not see this behavior using CLANG on osx.

Any ideas? Bug in g++? Does switch order matter? Should it?

Options: ReplyQuote


Subject
Views
Written By
Posted
Link error
151
June 21, 2022 07:52PM
79
June 22, 2022 08:01AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.