herumi / bls

288 stars 132 forks source link

Undefined symbol when try to use in Xcode(iOS) #91

Closed zsoltpete closed 1 year ago

zsoltpete commented 1 year ago

Hello

I am trying to use the BLS in my iOS project but when building got Undefined symbol error. These my steps:

git clone --recursive https://github.com/herumi/bls-go-binary cd bls-go-binary make CXX=clang++ cd src/bls/mcl make -j4 make install cd .. sudo make install cd ../.. make ios_simulator

I guess the mcl doesn't link to the bls. Have you got any tip what I am missed?

herumi commented 1 year ago

Type on M1 mac

git clone --recursive https://github.com/herumi/bls-go-binary
cd bls-go-binary
make ios_simulator

then,

iossimulator/arm64/libbls384_256.a iossimulator/x86_64/libbls384_256.a iossimulator/i386/libbls384_256.a
lipo iossimulator/arm64/libbls384_256.a iossimulator/x86_64/libbls384_256.a iossimulator/i386/libbls384_256.a -create  -output /Users/shigeo/Program/bls-go-binary/bls/lib/iossimulator/libbls384_256.a
zsoltpete commented 1 year ago

Thanks for your advice, but I have got the same errors. Attach an image from it Screenshot 2022-08-24 at 9 18 18

herumi commented 1 year ago

I tried make ios_simulator on Intel Mac, and it runs well. What command did you run?

make -j4
make install
cd ..
sudo make install

By typing make install, there may be old files in /usr/local/include or /usr/local/lib. Could you please remove them (Don't remove the other files except for mcl/bls)?

And please attach not graphics but text. I can't read all.

zsoltpete commented 1 year ago
git clone --recursive https://github.com/herumi/bls-go-binary
cd bls-go-binary
make ios_simulator /usr/local/include
lipo iossimulator/arm64/libbls384_256.a iossimulator/x86_64/libbls384_256.a iossimulator/i386/libbls384_256.a -create  -output /Users/shigeo/Program/bls-go-binary/bls/lib/iossimulator/libbls384_256.a

Deleted /usr/local/lib and /usr/local/include These commands, after that the created libbls384_256.a added to the Xcode and after a build got these errors:

Undefined symbols for architecture x86_64:
  "_mclb_mulUnitAdd_fast9", referenced from:
      _mclb_mulUnitAdd9 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_fast8", referenced from:
      _mclb_mulUnitAdd8 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_fast7", referenced from:
      _mclb_mulUnitAdd7 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_fast6", referenced from:
      _mclb_mulUnitAdd6 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_fast5", referenced from:
      _mclb_mulUnitAdd5 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_fast4", referenced from:
      _mclb_mulUnitAdd4 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_fast3", referenced from:
      _mclb_mulUnitAdd3 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_fast2", referenced from:
      _mclb_mulUnitAdd2 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_fast1", referenced from:
      _mclb_mulUnitAdd1 in libbls384_256.a(fp.o)
  "_mclb_mulUnit_slow1", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_fast4", referenced from:
      _mclb_mulUnit4 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_slow1", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_slow2", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_fast5", referenced from:
      _mclb_mulUnit5 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_slow2", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_slow3", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_fast1", referenced from:
      _mclb_mulUnit1 in libbls384_256.a(fp.o)
  "_mclb_mulUnit_fast6", referenced from:
      _mclb_mulUnit6 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_slow3", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_slow4", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_fast2", referenced from:
      _mclb_mulUnit2 in libbls384_256.a(fp.o)
  "_mclb_mulUnit_fast7", referenced from:
      _mclb_mulUnit7 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_slow4", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_fast3", referenced from:
      _mclb_mulUnit3 in libbls384_256.a(fp.o)
  "_mclb_mulUnit_fast8", referenced from:
      _mclb_mulUnit8 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_slow5", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_fast9", referenced from:
      _mclb_mulUnit9 in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_slow6", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_slow7", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_slow7", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_slow8", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_slow5", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_slow8", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_slow9", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnit_slow6", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
  "_mclb_mulUnitAdd_slow9", referenced from:
      mcl::bint::initBint() in libbls384_256.a(fp.o)
      _mclb_disable_fast in libbls384_256.a(fp.o)
      mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer> const&, unsigned long, int, mcl::fp::Mode, unsigned long) in libbls384_256.a(fp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
herumi commented 1 year ago

These commands, after that the created libbls384_256.a added to the Xcode and after a build got >these errors:

Could you see the code which you build libbls384_256.a? I would like to check the error.

herumi commented 1 year ago

How about using the latest mcl/bls? That is, could you try to type the following commands?

git clone --recursive https://github.com/herumi/bls-go-binary
cd bls-go-binary
cd src/bls
git fetch --all --prune
git reset --hard origin/master
% git branch -v
 (HEAD detached from 4a99be9) 2995c67 [android] add targets
cd mcl
git reset --hard origin/master
% git branch -v
(HEAD detached from 0489e76c) 754c45e3 v1.71
cd ../..
make ios_simulator
zsoltpete commented 1 year ago

Archive.zip Upload the .a file and a txt file. That file created with nm libbls384_256.a | less > output.txt

I tried that command below but got the same errors

zsoltpete commented 1 year ago

I checked out to the v1.26 tagged commit and is okey with xour commands below. Maybe something big changes was in the v1.28 version?

zsoltpete commented 1 year ago

I am working with the v1.26 version, but I've got -246046 error when try to init, I guess the same problem in #86, have you get any idea how to resolve it?

herumi commented 1 year ago

Thank you for the report. Could you try to modify src/bls/Makefile.online by the following patch?

diff --git a/Makefile.onelib b/Makefile.onelib
index 31975e8..7904761 100644
--- a/Makefile.onelib
+++ b/Makefile.onelib
@@ -161,15 +161,15 @@ each_ios: $(BASE_LL)
        $(IOS_CLANG) $(IOS_COMMON) $(IOS_CFLAGS) -c $(MCL_DIR)/src/fp.cpp -o $(IOS_OUTDIR)/fp.o
        $(IOS_CLANG) $(IOS_COMMON) $(IOS_CFLAGS) -c $(MCL_DIR)/src/base$(BIT).ll -o $(IOS_OUTDIR)/base$(BIT).o
        $(IOS_CLANG) $(IOS_COMMON) $(IOS_CFLAGS) -c $(BLS_DIR)/src/bls_c$(CURVE_BIT).cpp -o $(IOS_OUTDIR)/bls_c$(CURVE_BIT).o
-#ifeq ($(ARCH),x86_64)
-#  @echo compile bint-x64-amd64.s
-#  as -o $(IOS_OUTDIR)/bint-x64-amd64.o -c $(MCL_DIR)/src/asm/bint-x64-amd64.s
-#  ar cru $(IOS_OUTDIR)/$(IOS_LIB) $(IOS_OUTDIR)/fp.o $(IOS_OUTDIR)/base$(BIT).o $(IOS_OUTDIR)/bls_c$(CURVE_BIT).o $(IOS_OUTDIR)/bint-x64-amd64.o
-#else
+ifeq ($(ARCH),x86_64)
+ @echo compile bint-x64-amd64.s
+ $(IOS_CLANG) $(IOS_COMMON) $(IOS_CFLAGS) -c $(MCL_DIR)/src/asm/bint-x64-amd64.s -o $(IOS_OUTDIR)/bint-x64-amd64.o
+ ar cru $(IOS_OUTDIR)/$(IOS_LIB) $(IOS_OUTDIR)/fp.o $(IOS_OUTDIR)/base$(BIT).o $(IOS_OUTDIR)/bls_c$(CURVE_BIT).o $(IOS_OUTDIR)/bint-x64-amd64.o
+else
        @echo compile bint$(BIT).ll
        $(IOS_CLANG) $(IOS_COMMON) $(IOS_CFLAGS) -c $(MCL_DIR)/src/bint$(BIT).ll -o $(IOS_OUTDIR)/bint$(BIT).o
        ar cru $(IOS_OUTDIR)/$(IOS_LIB) $(IOS_OUTDIR)/fp.o $(IOS_OUTDIR)/base$(BIT).o $(IOS_OUTDIR)/bls_c$(CURVE_BIT).o $(IOS_OUTDIR)/bint$(BIT).o
-#endif
+endif
        ranlib $(IOS_OUTDIR)/$(IOS_LIB)

 clean:
zsoltpete commented 1 year ago

Thanks for the patch now the v1.28 is okey, but got the same blsInit err -246046 error. Have you got any idea how to resolve it?

herumi commented 1 year ago

Thank you for the check. Could you tell me the small (only call blsInt() function) project? I'm not familiar with iOS, so I can't verify it.

zsoltpete commented 1 year ago

I tried on another mac and works on it so i guess you can close the issue. Thanks for your help

herumi commented 1 year ago

Okay.