monero icon indicating copy to clipboard operation
monero copied to clipboard

Fix static builds for Ubuntu 22.04

Open LocalMonero opened this issue 1 year ago • 12 comments

Link libbsd, libmd, libprotokit in CMakeLists.txt for ZMQ to fix static builds for Ubuntu 22.04

LocalMonero avatar Sep 12 '22 15:09 LocalMonero

How were you linking before so that it didn't work? I'm using Ubuntu 22.04 and it works fine for me on master.

jeffro256 avatar Sep 12 '22 20:09 jeffro256

@jeffro256 We did it exactly as described in the README.md, apart from also building and installing unbound and its dependency expat from source, which is now an (undocumented) standard procedure on Ubuntu after the project decided to stop vendoring unbound. You were running make release-static and it worked on your clean Ubuntu 22.04 install? For us, we got

[ 98%] Linking CXX executable ../../bin/monerod
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libzmq.a(libzmq_la-ws_engine.o): in function `zmq::ws_engine_t::server_handshake()':
(.text+0x1a6b): undefined reference to `strlcpy'
/usr/bin/ld: (.text+0x1ab9): undefined reference to `strlcpy'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libzmq.a(libzmq_la-ws_engine.o): in function `zmq::ws_engine_t::client_handshake()':
(.text+0x24a5): undefined reference to `strlcpy'
/usr/bin/ld: (.text+0x24cc): undefined reference to `strlcpy'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libnorm.a(normApi.cpp.o): in function `NormInstance::SetCacheDirectory(char const*)':
(.text+0xe0): undefined reference to `ProtoDispatcher::SuspendThread()'
/usr/bin/ld: (.text+0x153): undefined reference to `ProtoDispatcher::ResumeThread()'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libnorm.a(normApi.cpp.o): in function `NormInstance::PurgeObjectNotifications(void const*)':
(.text+0x1b9): undefined reference to `ProtoList::Iterator::Iterator(ProtoList&, bool)'
/usr/bin/ld: (.text+0x1da): undefined reference to `ProtoList::Iterator::GetNextItem()'
/usr/bin/ld: (.text+0x201): undefined reference to `ProtoList::Iterator::~Iterator()'
/usr/bin/ld: (.text+0x237): undefined reference to `ProtoList::Remove(ProtoList::Item&)'
/usr/bin/ld: (.text+0x244): undefined reference to `ProtoList::Append(ProtoList::Item&)'
/usr/bin/ld: (.text+0x261): undefined reference to `ProtoList::Append(ProtoList::Item&)'
...

Running make works. It's just make release-static that fails without the CMakeLists.txt modifications.

LocalMonero avatar Sep 13 '22 06:09 LocalMonero

Hi @LocalMonero, sorry it took so long to get back to you. I was trying out a bunch of Ubuntu installations trying to reproduce the linking errors that you were getting but I was not able to. From a clean installation of Ubuntu Server 22.04 on a VM, I 1) did sudo apt update && sudo apt upgrade && sudo apt install <all monero dependencies> 2) cloned the unbound repo and built and installed from source 3) cloned the monero repo and ran make release-static. I was able to build release-static without any errors. Is there anything else you can think of that you might have done to your install of Ubuntu 22 that would cause this error?

jeffro256 avatar Sep 18 '22 15:09 jeffro256

@jeffro256 we didn't clone and build MiniUPnP, only libunbound.

LocalMonero avatar Sep 18 '22 16:09 LocalMonero

Sorry, that's what I meant to say: I built and installed libunbound from source. Do you have the package libunbound-dev installed? If you do, what happens when you sudo apt remove that package, then do a make clean and rebuild monero?

Edit: I would do this on an installation which can be wiped if needed. You can sudo apt install libunbound-dev after you do the above commands to (probably) fix any missing dependencies.

jeffro256 avatar Sep 19 '22 17:09 jeffro256

I needed this patch to compile release-static on a fresh Ubuntu 22.04 machine.

selsta avatar Sep 19 '22 20:09 selsta

Does this work without removing the libunbound-dev package?

jeffro256 avatar Sep 19 '22 22:09 jeffro256

I assume it depends where you install the custom compiled unbound and which path you tell CMake.

selsta avatar Sep 19 '22 22:09 selsta

Shouldn't all these checks be wrapped in if(STATIC) so they only apply to static builds?

jtgrassie avatar Sep 20 '22 02:09 jtgrassie

@jeffro256 building with sudo apt install libunbound-dev doesn't work, static or not. Only self-compiled libunbound works. No libunbound-dev installed.

LocalMonero avatar Sep 20 '22 05:09 LocalMonero

@LocalMonero Right. I was saying that when the libunbound-dev package is installed, our CMake rules for finding libunbound might have linked against the wrong library (I don't know if they did or not). For those who are linking Monero statically, it is probably best to remove that package, as long as you don't have other packages which depend on it.

jeffro256 avatar Sep 20 '22 16:09 jeffro256

Shouldn't all these checks be wrapped in if(STATIC) so they only apply to static builds?

Probably? It probably shouldn't negatively affect non-static builds, but it would be likely be the better option, at least so the code is self-documenting in that this is a patch for static builds.

jeffro256 avatar Sep 24 '22 02:09 jeffro256

This fixes builds for me too (also ubuntu 22.04). Would be nice if we could get this merged so master would build out-of-the-box again.

busyboredom avatar Oct 20 '22 03:10 busyboredom

@busyboredom it's in the merge queue already

selsta avatar Oct 20 '22 03:10 selsta

@selsta what do you think of @jtgrassie 's comment?

jeffro256 avatar Oct 20 '22 04:10 jeffro256

@jeffro256

Probably? It probably shouldn't negatively affect non-static builds, but it would be likely be the better option, at least so the code is self-documenting in that this is a patch for static builds.

My general stance is this: If it's not needed (based on make options), don't link it.

jtgrassie avatar Oct 20 '22 04:10 jtgrassie

We already link to libraries that are only needed for static, so it's fine to change it but I would do it in a separate PR later.

selsta avatar Oct 20 '22 16:10 selsta