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

Fix backport of bitcoin-core/secp256k1#925 (drop 'include/' prefix from -I) #208

Closed
mattiaferrari02 opened this issue Dec 6, 2022 · 12 comments · Fixed by #227
Closed

Fix backport of bitcoin-core/secp256k1#925 (drop 'include/' prefix from -I) #208

mattiaferrari02 opened this issue Dec 6, 2022 · 12 comments · Fixed by #227

Comments

@mattiaferrari02
Copy link

I have a few questions about the compilation of the project...

After running autogen and configure with the custom flags, at that point is it possible to compile the project without using the newly generated makefile (aka use directly the gcc command) or something like that.

I'm trying also to compile the project from xcode because I have the need to use this code in a swift library... the main problems encountered with the compilation from xcode are wrong includes in the files. I'm not an expert on AutoMake, but from what I have understood, all the includes are managed by automake, is there a way to do it manually?

@mattiaferrari02
Copy link
Author

mattiaferrari02 commented Dec 7, 2022

In particular I'm referring to
https://github.com/ElementsProject/secp256k1-zkp/blob/d22774e248c703a191049b78f8d04f37d6fcfa05/src/secp256k1.c#L9

why the include is defined this way in this line?, but then
https://github.com/ElementsProject/secp256k1-zkp/blob/d22774e248c703a191049b78f8d04f37d6fcfa05/src/secp256k1.c#L36

why this line doesn't use the ../ (I need to use the module generator)

I tried also passing the -I flag to gcc with the include dir but nothing changes

@mattiaferrari02
Copy link
Author

changing some import paths seems to make it compile (using gcc -c src/secp256k1.c -DHAVE_CONFIG_H=1 ) and produce a secp256k1.o but then I tried creating something like this

// test.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "secp256k1.h"
#include "secp256k1_ecdh.h"
#include "secp256k1_generator.h"
#include "secp256k1_rangeproof.h"
#include "secp256k1_preallocated.h"
#include "secp256k1_surjectionproof.h"

int main() {

    return 0;
}

And then calling

gcc -Iinclude secp256k1.o test.c  

This produces

Undefined symbols for architecture arm64:
  "_secp256k1_ecmult_gen_prec_table", referenced from:
      _secp256k1_ecmult_gen in secp256k1.o
  "_secp256k1_pre_g", referenced from:
      _secp256k1_ecmult_strauss_wnaf in secp256k1.o
  "_secp256k1_pre_g_128", referenced from:
      _secp256k1_ecmult_strauss_wnaf in secp256k1.o
ld: symbol(s) not found for architecture arm64

@delta1
Copy link

delta1 commented Dec 7, 2022

I'm trying also to compile the project from xcode because I have the need to use this code in a swift library

What about compiling it "normally" with automake, and then dynamically linking it in your xcode project?

@mattiaferrari02
Copy link
Author

mattiaferrari02 commented Dec 7, 2022

I can't do that because if i compile it normally the compilation works for my pc architecture only, the expected behaviour is for it to work on the ios processor both simulator and real device (they use different archs and depends on the host machine), so it has to be compiled by the person that is using the lib in thier project.

I also tried shipping the automake inside a swift library / pod, but they don't support that type of build, xcode expects to call the xcodebuild command and from what I found that behaviour isn't customizable.

changing some import paths seems to make it compile (using gcc -c src/secp256k1.c -DHAVE_CONFIG_H=1 ) and produce a secp256k1.o but then I tried creating something like this

// test.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "secp256k1.h"
#include "secp256k1_ecdh.h"
#include "secp256k1_generator.h"
#include "secp256k1_rangeproof.h"
#include "secp256k1_preallocated.h"
#include "secp256k1_surjectionproof.h"

int main() {

    return 0;
}

And then calling

gcc -Iinclude secp256k1.o test.c  

This produces

Undefined symbols for architecture arm64:
  "_secp256k1_ecmult_gen_prec_table", referenced from:
      _secp256k1_ecmult_gen in secp256k1.o
  "_secp256k1_pre_g", referenced from:
      _secp256k1_ecmult_strauss_wnaf in secp256k1.o
  "_secp256k1_pre_g_128", referenced from:
      _secp256k1_ecmult_strauss_wnaf in secp256k1.o
ld: symbol(s) not found for architecture arm64

it would be great if you can help me understand this

@real-or-random
Copy link
Collaborator

In particular I'm referring to
https://github.com/ElementsProject/secp256k1-zkp/blob/d22774e248c703a191049b78f8d04f37d6fcfa05/src/secp256k1.c#L9

why the include is defined this way in this line?, but then
https://github.com/ElementsProject/secp256k1-zkp/blob/d22774e248c703a191049b78f8d04f37d6fcfa05/src/secp256k1.c#L36

why this line doesn't use the ../ (I need to use the module generator)

This is because there have been changes in the upstream version of this library that apparently haven't properly been implemented in the modules that this fork contains... bitcoin-core/secp256k1#925, bitcoin-core/secp256k1#1126

And then calling
gcc -Iinclude secp256k1.o test.c

This should help you: bitcoin-core/secp256k1#929 (comment)

@csjones
Copy link

csjones commented Dec 9, 2022

I also tried shipping the automake inside a swift library / pod, but they don't support that type of build, xcode expects to call the xcodebuild command and from what I found that behaviour isn't customizable.

Hey @mattiaferrari02 have you looked at the existing swift packages that wrap this project into spm?

@mattiaferrari02

This comment was marked as resolved.

@mattiaferrari02
Copy link
Author

I also tried shipping the automake inside a swift library / pod, but they don't support that type of build, xcode expects to call the xcodebuild command and from what I found that behaviour isn't customizable.

Hey @mattiaferrari02 have you looked at the existing swift packages that wrap this project into spm?

Your package wraps bitcoin-core/secp256k1, not this one, the thing that i need is the module generator that isn't present in the bitcoin-core/secp256k1 lib

@apoelstra
Copy link
Contributor

I would consider our incorrect backport of bitcoin-core/secp256k1#925 to be a bug that we should fix -- that PR was specifically to make cases like this easier to handle.

@real-or-random

This comment was marked as resolved.

@mattiaferrari02

This comment was marked as resolved.

@real-or-random
Copy link
Collaborator

I would consider our incorrect backport of bitcoin-core/secp256k1#925 to be a bug that we should fix -- that PR was specifically to make cases like this easier to handle.

Let me reopen and repurpose this issue to track that bug.

@real-or-random real-or-random changed the title Questions about compilation Fix backport of bitcoin-core/secp256k1#925 (drop 'include/' prefix from -I) Dec 19, 2022
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

Successfully merging a pull request may close this issue.

5 participants