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

Get error "Undefined reference to cap_xxx" when link libwebsockets built from master. #1975

Closed
RSATom opened this issue Jul 17, 2020 · 18 comments

Comments

@RSATom
Copy link
Contributor

RSATom commented Jul 17, 2020

Don't sure, but maybe it worth consider add libcap as dependency to libwebsockets.pc?

@lws-team
Copy link
Member

It should look and see if you have libcap headers, and add it automatically:

https://libwebsockets.org/git/libwebsockets/tree/CMakeLists.txt#n559
https://libwebsockets.org/git/libwebsockets/tree/lib/plat/unix/CMakeLists.txt#n93

Is your pkgconf for libcap installed somewhere unusual?

@RSATom
Copy link
Contributor Author

RSATom commented Jul 17, 2020

Ah... It's possible it my fault, and I just don't have libcap-dev installed... Sorry, closing.

@RSATom RSATom closed this as completed Jul 17, 2020
@RSATom
Copy link
Contributor Author

RSATom commented Jul 17, 2020

But on other side, why it sill uses cap_xxx functions? Maybe it miss ifdef guard? Let me check.

@lws-team
Copy link
Member

It should use them if it finds the header during cmake

@RSATom
Copy link
Contributor Author

RSATom commented Jul 17, 2020

Yes, it's something weird there... But please don't care - I'll try to find reason myself.

@lws-team
Copy link
Member

Let me know if something to fix :-)

@RSATom
Copy link
Contributor Author

RSATom commented Jul 17, 2020

It's something really strange. I've installed libcap-dev package (I'm on ubuntu 20.04) and rebuilt libwebsockets (from today's master). After that I've got following libwebsockets.pc

prefix="/usr/local"
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: libwebsockets
Description: Websockets server and client library
Version: 4.0.99-v4.0.0-225-g886e9326

Libs: -L${libdir} -lwebsockets
Cflags: -I${includedir}

i.e. there are no libcap reference there.

@RSATom RSATom reopened this Jul 17, 2020
@RSATom
Copy link
Contributor Author

RSATom commented Jul 17, 2020

I can investigate it myself, but maybe you will find issue much quicker...
Thanks in advance.

@lws-team
Copy link
Member

OK I will do the same test tomorrow and see what happens.

@RSATom
Copy link
Contributor Author

RSATom commented Jul 18, 2020

Some more info, I get LIB_LIST_AT_END=m;cap;dl on cmake run, but still nothing in .pc file...

@RSATom
Copy link
Contributor Author

RSATom commented Jul 18, 2020

I think I found the reason: https://github.com/warmcat/libwebsockets/blob/master/lib/CMakeLists.txt#L273
When libwebsockets.pc is generating, LIB_LIST_AT_END not used in any way...

@lws-team
Copy link
Member

Thanks for digging into it... IIUI it just needs this?

diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 6ed6b50e8..1ac0bc646 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -287,7 +287,7 @@ Name: libwebsockets_static
 Description: Websockets server and client static library
 Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}
 
-Libs: -L\${libdir} -lwebsockets_static
+Libs: -L\${libdir} -lwebsockets_static ${LIB_LIST_AT_END}
 Libs.private:
 Cflags: -I\${includedir}"
 )

@RSATom
Copy link
Contributor Author

RSATom commented Jul 18, 2020

It's not only about libwebsockets_static.pc but also about libwebsockets.pc.
Also, don't think ${LIB_LIST_AT_END} will work, just because it's semicolon separated list (i.e something like m;cap;dl), but it should be something like -lm -lcap -ldl.
And it's possible there are other problem exists (I don't sure 100% since I'm not an expert in creating .pc files) - besides -l<libname> arguments, it's possible it will require -L<libpath> arguments too.

@RSATom
Copy link
Contributor Author

RSATom commented Jul 18, 2020

Some new find: according to pkg-config docs there are better way add dependencies from extern libraries - use Requires line in .pc file.

@RSATom
Copy link
Contributor Author

RSATom commented Jul 18, 2020

Some more experimenting. It works fine if I edit libwebsockets.pc to something like this:

prefix="/usr/local"
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: libwebsockets
Description: Websockets server and client library
Version: 4.0.99-v4.0.0-225-g886e9326
Requires: libcap >= 2.0

Libs: -L${libdir} -lwebsockets
Cflags: -I${includedir}

@lws-team
Copy link
Member

I fiddled with it a bit but I was not smart enough to understand how to autogenerate the pkgconfig format from what cmake has. I settled from having that maintained separately for optional packages...

https://libwebsockets.org/git/libwebsockets/commit?id=c8baeccfd76d324c1454cb9b57bf01a95ad5b500

is this enough or more libs need to be taken care about?

@RSATom
Copy link
Contributor Author

RSATom commented Jul 18, 2020

@lws-team yes, it looks like it will work. The only question if libcap v2.0 is really minimal required version. I just never worked with libcap, so don't sure.

@lws-team
Copy link
Member

Well, version in Fedora 32 is 1.9... upstream is 2.38 I don't think it uses anything so new, I changed it to not specify a version relationship. That's legal https://dev.gentoo.org/~mgorny/pkg-config-spec.html#package-list

I'll close it for now then.

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