Bitcoin Core Linking Error on Windows using WSL and Ubuntu 20.04
As a Bitcoin user, you are probably familiar with the importance of ensuring that your software is compatible with different operating systems and environments. However, when building and installing Bitcoin Core, especially from source, it can be a frustrating experience. In this article, we will investigate a linker error that you are experiencing on a Windows system using WSL (Windows Subsystem for Linux) running Ubuntu 20.04.
Problem:
When trying to build Bitcoin source code v24.2 for Windows using WSL, you may encounter the following linker errors:
/usr/bin/gcc
/usr/bin/g++: undefined symbol: __errno__
These error messages indicate that your compiler cannot find an equivalent function named __errno__
in the C standard library.
Solution:
To fix this issue, you will need to make some adjustments to your build process. Here is a step-by-step guide:
- Install the GNU Compiler Collection (GCC):
On Ubuntu 20.04, you can install GCC using the following command:
sudo apt update
sudo apt install gcc-9
This version of GCC is compatible with Bitcoin Core.
- Update
CXX
andCPP
tags:
After installing GCC, you will need to update the compiler flags for C++ and C code. The correct flags are:
gcc -std=c++11 -I/usr/include/gcc-9 -O2 -Wall -Wextra -pthread -I/usr/lib64/gcc/9/../../../glibc/aarch64-linux-gnu/libc.so -I/usr/local/include
The CXX
and CPP
flags are used to specify the compiler for C++ code. Replace gcc
with g++
if you are using G++.
- Configure and build
:
Now that you have the correct compiler flags, you can configure and build Bitcoin Core:
cd /path/to/bitcoin/src
./configure --enable-openssl=1 --prefix=/usr/local
make -j$(nproc)
The --enable-openssl=1
flag enables the OpenSSL library for building with cryptography.
- Run the installer:
After building Bitcoin Core, you will need to run the installer:
./installer --build --preinstall --no-synctool --config /usr/local/etc/bitcoin.conf
The --config
option specifies a configuration file that contains the settings for your build. The path is relative to the current directory.
- Confirm:
Once the installation is complete, verify that Bitcoin Core was successfully installed and linked correctly:
bitcoin --version
This should display version information indicating that Bitcoin Core was built with the correct tags.
By following these steps, you should be able to resolve the linker error and successfully build Bitcoin source code v24.2 for Windows using WSL running Ubuntu 20.04.