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

Shared library broken on MinGW #430

Closed
mmgen opened this issue Dec 1, 2016 · 9 comments
Closed

Shared library broken on MinGW #430

mmgen opened this issue Dec 1, 2016 · 9 comments

Comments

@mmgen
Copy link

mmgen commented Dec 1, 2016

This stub compiles, links and runs on Linux

    #include <stdio.h>
    #include <secp256k1.h>
    
    int main()
    {
    	static secp256k1_context *ctx = NULL;
    	ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN);
    	return 1;
    }

but produces the following linking error under MinGW:

    $ gcc my.c -lsecp256k1 -I/usr/local/include -L/usr/local/lib
    C:/msys/local/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): In function `secp256k1_num_set_bin':
    c:\build\secp256k1/src/num_gmp_impl.h:49: undefined reference to `_imp____gmpn_set_str'
    C:/msys/local/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): In function `secp256k1_num_mod_inverse':
    c:\build\secp256k1/src/num_gmp_impl.h:128: undefined reference to `_imp____gmpn_gcdext'
    C:/msys/local/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): In function `secp256k1_num_get_bin':
    c:\build\secp256k1/src/num_gmp_impl.h:34: undefined reference to `_imp____gmpn_get_str'
    C:/msys/local/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): In function `_gmpn_sub':
    c:/mingw/include/gmp.h:2097: undefined reference to `_imp____gmpn_sub_n'
    collect2.exe: error: ld returned 1 exit status

The undefined symbols:

    $ objdump.exe -t /usr/local/lib/libsecp256k1.a | grep imp_
    [116](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __imp___iob
    [117](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __imp____gmpn_set_str
    [118](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __imp____gmpn_gcdext
    [119](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __imp____gmpn_get_str
    [120](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __imp____gmpn_sub_n
@sipa
Copy link
Contributor

sipa commented Dec 1, 2016

Does it work when you add -lgmp to the command line? I'm surprised it works in Linux without that.

@mmgen
Copy link
Author

mmgen commented Dec 1, 2016

That did the trick! Thanks, Pieter! It does work in Linux without that, by the way.

@mmgen mmgen closed this as completed Dec 1, 2016
@sipa
Copy link
Contributor

sipa commented Dec 1, 2016

Maybe you just compiled in linux without gmp dependency? (--without-bignum, or just no libgmp developer files available?)

@mmgen
Copy link
Author

mmgen commented Dec 1, 2016

No extra options at all, just ./configure and make, and libgmp-dev is installed. But it compiles fine with just

    gcc my.c -lsecp256k1

@sipa
Copy link
Contributor

sipa commented Dec 1, 2016 via email

@mmgen
Copy link
Author

mmgen commented Dec 2, 2016

I rebuilt and reinstalled the library; configure enables libgmp. Stub still compiles OK without -lgmp though. I think this is because Linux allows unresolved symbols in shared libraries.

    $ objdump -t /usr/local/lib/libsecp256k1.a | grep gmp
    0000000000000000         *UND*  0000000000000000 __gmpn_set_str
    0000000000000000         *UND*  0000000000000000 __gmpn_gcdext
    0000000000000000         *UND*  0000000000000000 __gmpn_get_str
    0000000000000000         *UND*  0000000000000000 __gmpn_sub_n

@thinkKundera
Copy link

@mmgen @sipa how to solve this in Mac OS X? thanks

@thinkKundera
Copy link

@mmgen @sipa and the using compiler is clang

@mmgen
Copy link
Author

mmgen commented May 31, 2017

@Aparesse no idea, sorry

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

3 participants