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

How to get libsecp256k1 when running from source on Windows? #5976

Open
nc50lc opened this issue Feb 21, 2020 · 15 comments
Open

How to get libsecp256k1 when running from source on Windows? #5976

nc50lc opened this issue Feb 21, 2020 · 15 comments

Comments

@nc50lc
Copy link
Contributor

nc50lc commented Feb 21, 2020

Tested on Feb10 Build to the Latest Build.
OS: Windows10
Python versions: 3.6.1 and 3.8
All other dependencies are installed

When trying to run Electrum:
C:\Python\Python361>python electrum-master/run_electrum

E | ecc_fast | libsecp256k1 library failed to load
Error: Failed to load libsecp256k1.

libsecp256k1 was installed through:
C:\Python\Python361>python -m pip install libsecp256k1

Requirement already satisfied: libsecp256k1 in c:\python\python361\lib\site-packages (0.1)

In comparison, the dev build copy that I have downloaded last February 5 is working despite not having libsecp256k1.
It's just crashing when I'm trying to enable lightning due to obvious reasons.

This might be caused by this PR: #5947
"make libsecp256k1 a mandatory dependency"

@nc50lc nc50lc changed the title Lastest Electrum 4.0.0a0 build wont launch on Python Latest Electrum 4.0.0a0 build wont launch on Python Feb 21, 2020
@SomberNight SomberNight changed the title Latest Electrum 4.0.0a0 build wont launch on Python How to get libsecp256k1 when running from source on Windows? Feb 21, 2020
@SomberNight
Copy link
Member

Like the README says, libsecp256k1 is a non-python dependency; you should not install it via pip.

libsecp256k1 was installed through:
C:\Python\Python361>python -m pip install libsecp256k1
Requirement already satisfied: libsecp256k1 in c:\python\python361\lib\site-packages (0.1)

This package you installed is named libsecp256k1 but it is virtually empty. Someone is probably just namesquatting it.

What you will need is a dll, named libsecp256k1-0.dll, e.g. placed into the inner "electrum" folder.
As the README says, we provide a script to build this yourself when running from source, contrib/make_libsecp256k1.sh, however atm this script only works on Unix-like systems (Linux/Mac).

Our own build script for the Windows binaries is cross-compiling from Linux to Windows.
If you have access to a Linux machine (e.g. VM) or perhaps even using WSL (Windows Subsystem for Linux), you can cross-compile from there to Windows this dll.

Whether you need a 32 bit or a 64 bit binary depends on the Python interpreter you have installed.
To compile a 32 bit (x86) dll, run:

GCC_TRIPLET_HOST="i686-w64-mingw32" ./contrib/make_libsecp256k1.sh

To compile a 64 bit (x86_64, amd64) dll, run:

GCC_TRIPLET_HOST="x86_64-w64-mingw32" ./contrib/make_libsecp256k1.sh

I guess this should be made easier... We weren't/aren't sure how many people there are running from source on Windows.

@nc50lc
Copy link
Contributor Author

nc50lc commented Feb 21, 2020

Thanks! I'll try it later.
But I guess I can close this issue now.

@nc50lc nc50lc closed this as completed Feb 21, 2020
@HardCorePawn
Copy link

HardCorePawn commented Feb 21, 2020

I can't seem to get this to work either... I compiled libsecp256k1 using the .sh in the contrib folder as advised and then copied the .dll and the .so that it generated to my Windows box...

Still getting:

E | ecc_fast | libsecp256k1 library failed to load
Error: Failed to load libsecp256k1.

Untitled

After hacking in some debug into ecc_fast.py

E | ecc_fast | LibPath: E:\electrum-master\electrum\libsecp256k1-0.dll
WARNING: [WinError 193] %1 is not a valid Win32 application
E | ecc_fast | LibPath: libsecp256k1-0.dll
WARNING: [WinError 193] %1 is not a valid Win32 application

Seems the .dll being produced isn't correct? ???

@SomberNight
Copy link
Member

@HardCorePawn

[WinError 193] %1 is not a valid Win32 application

I get that exception if the dll is for the wrong architecture (32 vs 64 bit).


Let's keep this issue open, as the current workaround is not ideal.

@SomberNight SomberNight reopened this Feb 21, 2020
@HardCorePawn
Copy link

HardCorePawn commented Feb 21, 2020

Turns out that:
sudo apt-get install gcc-mingw-w64

Is a "good idea"™ if you're building this outside of the build-wine docker "fresh_clone" thing ;)

Not sure why it didn't complain and still produced a .dll file earlier? Anyway, it seems to have produced a "proper" x64 bit .dll file now

22/02/2020 08:45 743,971 libsecp256k1-0.dll

And with that copied over to the Windows 10 box and put in the /electrum-master/electrum directory, Electrum is starting up OK when running from source

@boskowski
Copy link

Download the raw nupkg file from https://www.nuget.org/packages/Secp256k1.Net (use "Download package" link in "Info" section on the right), unzip the file, extract libsecp256k1.dll from runtimes\win-x86\native or runtimes\win-x64\native, place it as libsecp256k1-0.dll in the electrum project folder.

@brianddk
Copy link
Contributor

On my station from my MINGW64 shell on Windows 10

pacman -S git python-pip base-devel mingw-w64-x86_64-toolchain
pacman -S mingw-w64-x86_64-python-pyqt5 mingw-w64-x86_64-python-cryptography
git clone https://github.com/spesmilo/electrum.git
cd electrum
git checkout tags/4.0.0b0 -b 4.0.0.tmp
GCC_TRIPLET_HOST="x86_64-w64-mingw32" ./contrib/make_libsecp256k1.sh
cp /mingw64/bin/libgmp-10.dll electrum
python -m venv --system-site-packages .venv
source .venv/bin/activate
.venv/bin/python -m pip install --upgrade setuptools
.venv/bin/python -m pip install --upgrade pip
.venv/bin/python -m pip install -e .[full]
.venv/bin/python run_electrum

Everything worked fine. Verified with a Trezor-1

@SomberNight
Copy link
Member

I've built a 64-bit DLL for people - that trust me - to use.
libsecp256k1-0.zip

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

I've built this libsecp256k1-0.dll now, for 64-bit python.
The build should be reproducible.

$ sha256sum electrum/libsecp256k1-0.dll 
9e719c3ccaa946f08983f148b5880527ed6fcab718b1502cb916b52a9380a1e9  electrum/libsecp256k1-0.dll

Details:

$ GCC_STRIP_BINARIES="1" GCC_TRIPLET_HOST="x86_64-w64-mingw32" ./contrib/make_libsecp256k1.sh

$ git log -n 1
commit b7cc5f329c7d85f416cc35af00d11fe93c74ec09 (HEAD -> master, spesmilo/master, spesmilo/HEAD)

https://github.com/spesmilo/electrum/blob/b7cc5f329c7d85f416cc35af00d11fe93c74ec09/contrib/make_libsecp256k1.sh

LIBSECP_VERSION="dbd41db16a0e91b2566820898a3ab2d7dad4fe00"


ghost43
2021-07-12
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEbXohFtqQngCsIRCLsztfIyxicekFAmDsUwMACgkQsztfIyxi
cekCMA//clofhfhKZ4d0eWcAVm8ESe4VJApn5SshcmAcpnofFRKqHN47UxFqfyX+
18N6RVXm6Pk5ivPlAduVGqESWRCQfz5THNok8vYhJyAcFnbTJw7m4A5qn0+f19U/
zQ1qQFiEAhjottnQEfjc6Dk+ffcl6HgFtyqkDczm5xuiV9e2mdLeRUeC1OCUtHLr
lMUCil/O0BFEYJmkrZ0tW0pEdm8Qgk3cWlOox+kTq7HAcLp7jimwIPippTnRPGzn
cMg7eVrMAuB1fv8AVhNp/Sq+PStuSxisfTtZuSR9lVnMFqLqZsxHAFasvuYDup2v
C5jaLo6jCRjlzWblqfOB1v5g+wR0iruwVpwsTZyFg7am7jw/XwBQkWVmz86tUq0l
z4wYK8m2tmc977KWTXJ5bzCoUwKCyQ9xHkD4ohGLp72y+PUKJUN6PtuuzHwanHQD
MgxBiOR1j2bqzm5lgar13JVFIQKssEBuyCiR6CVpfiYzBBiXZiig2alrryIjOkTP
mgzNK+XNEM4rthyHGMT/qaLk1+8UyPuHqhEEnIAOJo7K1R4QtE8efOaot13f1JD4
tOMsQLuiX08plvzbV6gQFQLIoxyi75GPzpJrlTjI97MVzw4DvRq+/kp/ELYQkOoL
KG+w9PzSPFWV8arTr1futQOaLf6nSdgNLwVscuoB447yBwUzDgk=
=8aWU
-----END PGP SIGNATURE-----

@Stanislav-Povolotsky
Copy link

Thank you, guys!

I was able to build libsecp256k1-0.dll following your advices.

Now you can easily build your own libsecp256k1-0.dll (x86 and x64) using docker and
https://github.com/Stanislav-Povolotsky/electrum-libsecp256k1-0.dll-builder

@developeroka
Copy link

Like the README says, libsecp256k1 is a non-python dependency; you should not install it via pip.

libsecp256k1 was installed through:
C:\Python\Python361>python -m pip install libsecp256k1
Requirement already satisfied: libsecp256k1 in c:\python\python361\lib\site-packages (0.1)

This package you installed is named libsecp256k1 but it is virtually empty. Someone is probably just namesquatting it.

What you will need is a dll, named libsecp256k1-0.dll, e.g. placed into the inner "electrum" folder.
As the README says, we provide a script to build this yourself when running from source, contrib/make_libsecp256k1.sh, however atm this script only works on Unix-like systems (Linux/Mac).

Our own build script for the Windows binaries is cross-compiling from Linux to Windows.
If you have access to a Linux machine (e.g. VM) or perhaps even using WSL (Windows Subsystem for Linux), you can cross-compile from there to Windows this dll.

Whether you need a 32 bit or a 64 bit binary depends on the Python interpreter you have installed.
To compile a 32 bit (x86) dll, run:

GCC_TRIPLET_HOST="i686-w64-mingw32" ./contrib/make_libsecp256k1.sh

To compile a 64 bit (x86_64, amd64) dll, run:

GCC_TRIPLET_HOST="x86_64-w64-mingw32" ./contrib/make_libsecp256k1.sh

I guess this should be made easier... We weren't/aren't sure how many people there are running from source on Windows.

after doing this command through WSL I get the error "collect2: error: ld returned 1 exit status
make: *** [Makefile:910: libsecp256k1.la] Error 1
🗯 ERROR: Could not build secp256k1"

@developeroka
Copy link

Like the README says, libsecp256k1 is a non-python dependency; you should not install it via pip.

libsecp256k1 was installed through:
C:\Python\Python361>python -m pip install libsecp256k1
Requirement already satisfied: libsecp256k1 in c:\python\python361\lib\site-packages (0.1)

This package you installed is named libsecp256k1 but it is virtually empty. Someone is probably just namesquatting it.
What you will need is a dll, named libsecp256k1-0.dll, e.g. placed into the inner "electrum" folder.
As the README says, we provide a script to build this yourself when running from source, contrib/make_libsecp256k1.sh, however atm this script only works on Unix-like systems (Linux/Mac).
Our own build script for the Windows binaries is cross-compiling from Linux to Windows.
If you have access to a Linux machine (e.g. VM) or perhaps even using WSL (Windows Subsystem for Linux), you can cross-compile from there to Windows this dll.
Whether you need a 32 bit or a 64 bit binary depends on the Python interpreter you have installed.
To compile a 32 bit (x86) dll, run:

GCC_TRIPLET_HOST="i686-w64-mingw32" ./contrib/make_libsecp256k1.sh

To compile a 64 bit (x86_64, amd64) dll, run:

GCC_TRIPLET_HOST="x86_64-w64-mingw32" ./contrib/make_libsecp256k1.sh

I guess this should be made easier... We weren't/aren't sure how many people there are running from source on Windows.

after doing this command through WSL I get the error "collect2: error: ld returned 1 exit status
make: *** [Makefile:910: libsecp256k1.la] Error 1
🗯 ERROR: Could not build secp256k1"

I made it work
thank you all

@SomberNight
Copy link
Member

Note: I've added a "Running Electrum from source on Windows" guide now in 941db42.
It is building on brianddk's comment (#5976 (comment)) using MSYS2.

@GiverofMemory
Copy link

GiverofMemory commented Sep 19, 2022

Note: I've added a "Running Electrum from source on Windows" guide now in 941db42. It is building on brianddk's comment (#5976 (comment)) using MSYS2.

I followed this the MSYS2 method and the .dll was made no problem but when I get to the final step I get this error:

python3 ./run_electrum
Error: No module named 'dns'. Try 'sudo python3 -m pip install '

@accumulator
Copy link
Member

try python3 -m pip install dnspython

@SomberNight
Copy link
Member

I followed this the MSYS2 method and the .dll was made no problem but when I get to the final step I get this error:

python3 ./run_electrum Error: No module named 'dns'. Try 'sudo python3 -m pip install '

The dependencies should have been installed as part of step 1:

Run install (this should install most dependencies):
> python3 -m pip install --user -e ".[gui,crypto]"

Try running electrum in the original shell you used for those steps, e.g. powershell/cmd/"windows terminal", instead of msys2 (which is used solely for building libsecp).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants