Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux nanomsg static link error and warning #1004

Closed
363568233 opened this issue Nov 14, 2018 · 6 comments
Closed

Linux nanomsg static link error and warning #1004

363568233 opened this issue Nov 14, 2018 · 6 comments

Comments

@363568233
Copy link

[root@49 nanomsg_test]# g++ 1.c -static -lnanomsg -lpthread
//usr/local/lib64/libnanomsg.a(dns.c.o): In function nn_dns_start': dns.c:(.text+0x4e7): undefined reference to getaddrinfo_a'
//usr/local/lib64/libnanomsg.a(dns.c.o): In function nn_dns_notify': dns.c:(.text+0x5b3): undefined reference to gai_error'
//usr/local/lib64/libnanomsg.a(dns.c.o): In function nn_dns_shutdown': dns.c:(.text+0x76b): undefined reference to gai_cancel'

so g++ 1.c -static -lnanomsg -lpthread -lanl
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../lib64/libanl.a(gai_misc.o): In function `handle_requests':
(.text+0x3d): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

Is this warning negligible?? I don't know how to deal with it.

@363568233
Copy link
Author

I want to compile my exe link static library all. Because I would run it in different versions of GCC

@363568233
Copy link
Author

I find a explanation:
glibc uses libnss to support a number of different providers for address resolution services. Unfortunately, you cannot statically link libnss, as exactly what providers it loads depends on the local system's configuration.

@gdamore
Copy link
Contributor

gdamore commented Nov 14, 2018 via email

@gdamore
Copy link
Contributor

gdamore commented Nov 22, 2018

Try building with cmake -DNN_ENABLE_GETADDRINFO_A=OFF

That should fix it for you.

Note that NNG does not have this issue.

@gdamore
Copy link
Contributor

gdamore commented Nov 22, 2018

"Long term", a good fix would probably be to disable this function if NN_STATIC_LIB is set.

This can be done with just changes to the top-level CMakeLists.txt I think. Basically we can make enabling this capability conditional upon that. If you want to submit a PR for this I'd be happy to review it. It's not particularly high priority for me at this point (to do myself).

@gdamore
Copy link
Contributor

gdamore commented Jan 30, 2019

Actually, review this, the warning is correct. If you're building static, you need to be aware that you still have a dynamic dependency due to libnss. There's really nothing else I can do about it. You can ignore the warning if you're going to run your program on the target system.

Alternatively, if you want to be pure static without this dependency, use that cmake flag to disable the use of the asynchronous resolver. (It would be a mistake for me to automatically do this I think. You need to just pay attention to the warning.)

@gdamore gdamore closed this as completed Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants