Closed knuxyl closed 3 months ago
If you want to build static binary, you need to follow the same steps as in CI builds: https://github.com/SChernykh/p2pool/blob/master/.github/workflows/c-cpp.yml#L13 for Alpine Linux https://github.com/SChernykh/p2pool/blob/master/.github/workflows/c-cpp.yml#L165 for Ubuntu
In short, you have to build dependencies (curl, libuv, libzmq) in external/src folder first, then build p2pool with -DSTATIC_LIBS=ON
For Ubuntu:
In external/src/curl
directory:
cmake . -DCMAKE_C_FLAGS="-Os -flto=auto -fuse-linker-plugin -ffunction-sections -Wno-error=inline" -DBUILD_CURL_EXE=OFF -DBUILD_SHARED_LIBS=OFF -DCURL_DISABLE_INSTALL=ON -DCURL_ENABLE_EXPORT_TARGET=OFF -DCURL_DISABLE_HEADERS_API=ON -DCURL_DISABLE_BINDLOCAL=ON -DBUILD_LIBCURL_DOCS=OFF -DCURL_ZLIB=OFF -DCURL_DISABLE_ALTSVC=ON -DCURL_DISABLE_COOKIES=ON -DCURL_DISABLE_DOH=ON -DCURL_DISABLE_GETOPTIONS=ON -DCURL_DISABLE_HSTS=ON -DCURL_DISABLE_LIBCURL_OPTION=ON -DCURL_DISABLE_MIME=ON -DCURL_DISABLE_NETRC=ON -DCURL_DISABLE_NTLM=ON -DCURL_DISABLE_PARSEDATE=ON -DCURL_DISABLE_PROGRESS_METER=ON -DCURL_DISABLE_SHUFFLE_DNS=ON -DCURL_DISABLE_SOCKETPAIR=ON -DCURL_DISABLE_VERBOSE_STRINGS=ON -DHTTP_ONLY=ON -DCURL_ENABLE_SSL=OFF -DUSE_LIBIDN2=OFF -DCURL_USE_LIBPSL=OFF -DCURL_USE_LIBSSH2=OFF -DENABLE_UNIX_SOCKETS=OFF
make -j$(nproc)
cd lib && mkdir .libs && cp libcurl.a .libs
In external/src/libuv
directory:
mkdir build
cd build
cmake .. -DCMAKE_C_FLAGS='-Os -flto=auto -fuse-linker-plugin -ffunction-sections -Wno-error=inline' -DBUILD_TESTING=OFF -DLIBUV_BUILD_SHARED=OFF
make -j$(nproc)
In external/src/libzmq
directory:
mkdir build
cd build
cmake .. -DCMAKE_C_FLAGS='-Os -flto=auto -fuse-linker-plugin -ffunction-sections -Wno-error=inline' -DCMAKE_CXX_FLAGS='-Os -flto=auto -fuse-linker-plugin -ffunction-sections -Wno-error=inline' -DWITH_LIBSODIUM=OFF -DWITH_LIBBSD=OFF -DBUILD_TESTS=OFF -DWITH_DOCS=OFF -DENABLE_DRAFTS=OFF -DBUILD_SHARED=OFF
make -j$(nproc)
And finally in the main p2pool directory:
mkdir build
cd build
cmake .. -DCMAKE_C_FLAGS='-fuse-linker-plugin -ffunction-sections -Wno-error=inline -Wl,-s -Wl,--gc-sections' -DCMAKE_CXX_FLAGS='-fuse-linker-plugin -ffunction-sections -Wno-error=inline -Wl,-s -Wl,--gc-sections' -DSTATIC_LIBS=ON
make -j$(nproc) p2pool
Thank you. I had to manually move libcurl.a from src/curl/build/lib/
to src/curl/lib/.libs
and everything compiled smoothly.
I am building on aarch64, rock 3a rk3568 with GNU 13.2.0, kernel 6.7-arm64. I cloned repo with --recursive so I have all external dependencies available, and my system also have libzmq3-dev installed (debian sid).
Setting manual C and CXX flags to LTO and static gives this (somewhat expected)
I found the option in CMakeLists.txt for STATIC_BINARY and STATIC_LIBS so I then ran this
I don't think my flags are affecting anything because -Ofast and -flto are specified later in the build command, overwriting mine. The output of this gives
So my first attempt tried to static link a dynamic library, and then the second attempt tried to include the static library but there was no rule to make it.
My third attempt I removed "-static" from the flags but kept the CMake defines and I still get the same error
Also I should note that the C and CXX flags generated by CMake include fixes for cortex A53, but this cpu is a quad core A55. I'm not sure why these are being included, I'm guessing a GCC thing so not relevant here.
EDIT
Disabling LTO and Static will allow it to build, but no combination of lto and/or static will work. Either one of those options causes the build to fail.