herumi / mcl

a portable and fast pairing-based cryptography library
BSD 3-Clause "New" or "Revised" License
450 stars 151 forks source link

Unable to compile cpp file in the sample folder #188

Closed anujamodi0107 closed 9 months ago

anujamodi0107 commented 9 months ago

I am trying to compile pairing.cpp file in the sample folder, but I am getting the following compilation error (attached). I have installed MCL using the exact information available in the readme document. Can anyone please help me resolve this issue?

error2 error1

herumi commented 9 months ago

Could you try

% cd mcl
% make bin/pairing.exe -j && bin/pairing.exe

If you still get any errors, please let me know your CPU, OS and compiler version.

anujamodi0107 commented 9 months ago

Could you try

% cd mcl
% make bin/pairing.exe -j && bin/pairing.exe

If you still get any errors, please let me know your CPU, OS and compiler version.

Thank you for your quick response. I am still getting those errors. Here are the details of the CPU, OS, and compiler versions: Dell Inc. OptiPlex 3050, Memory 4.0 GiB, Intel® Core™ i3-7100 CPU @ 3.90GHz × 4, 64 bit Ubuntu 22.04.3 LTS and g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0.

herumi commented 9 months ago

Did you make clean first? Please append the text of errors, not images.

anujamodi0107 commented 9 months ago

Did you make clean first? Please append the text of errors, not images.

Yes, I gave the command "make clean" first. The errors in text format are in this document.

herumi commented 9 months ago

Please update a log contains a line make bin/pairing.exe.

My env. is Ubuntu 23.0 + gcc 12.3.0.

mcl% make bin/pairing.exe -j
cc -c src/asm/x86-64.S -o obj/base64.o  -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef -m64 -I include -I test -fomit-frame-pointer -DNDEBUG -fno-stack-protector -O3  -fpic -DMCL_USE_LLVM=1 -DMCL_BINT_ASM=1
cc  -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef -m64 -I include -I test -fomit-frame-pointer -DNDEBUG -fno-stack-protector -O3  -fpic -DMCL_USE_LLVM=1 -DMCL_BINT_ASM=1 -c src/asm/bint-x64-amd64.S -o obj/bint64.o
g++  -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef -m64 -I include -I test -fomit-frame-pointer -DNDEBUG -fno-stack-protector -O3  -fpic -DMCL_USE_LLVM=1 -DMCL_BINT_ASM=1 -c src/fp.cpp -o obj/fp.o -MMD -MP -MF obj/fp.d
g++  -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef -m64 -I include -I test -fomit-frame-pointer -DNDEBUG -fno-stack-protector -O3  -fpic -DMCL_USE_LLVM=1 -DMCL_BINT_ASM=1 -c sample/pairing.cpp -o obj/pairing.o -MMD -MP -MF obj/pairing.d
ar rv lib/libmcl.a obj/fp.o obj/base64.o obj/bint64.o
ar: creating lib/libmcl.a
a - obj/fp.o
a - obj/base64.o
a - obj/bint64.o
g++ obj/pairing.o -o bin/pairing.exe lib/libmcl.a -lrt  -lgmp -lgmpxx -m64
anujamodi0107 commented 9 months ago

Please update a log contains a line make bin/pairing.exe.

My env. is Ubuntu 23.0 + gcc 12.3.0.

mcl% make bin/pairing.exe -j
cc -c src/asm/x86-64.S -o obj/base64.o  -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef -m64 -I include -I test -fomit-frame-pointer -DNDEBUG -fno-stack-protector -O3  -fpic -DMCL_USE_LLVM=1 -DMCL_BINT_ASM=1
cc  -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef -m64 -I include -I test -fomit-frame-pointer -DNDEBUG -fno-stack-protector -O3  -fpic -DMCL_USE_LLVM=1 -DMCL_BINT_ASM=1 -c src/asm/bint-x64-amd64.S -o obj/bint64.o
g++  -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef -m64 -I include -I test -fomit-frame-pointer -DNDEBUG -fno-stack-protector -O3  -fpic -DMCL_USE_LLVM=1 -DMCL_BINT_ASM=1 -c src/fp.cpp -o obj/fp.o -MMD -MP -MF obj/fp.d
g++  -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef -m64 -I include -I test -fomit-frame-pointer -DNDEBUG -fno-stack-protector -O3  -fpic -DMCL_USE_LLVM=1 -DMCL_BINT_ASM=1 -c sample/pairing.cpp -o obj/pairing.o -MMD -MP -MF obj/pairing.d
ar rv lib/libmcl.a obj/fp.o obj/base64.o obj/bint64.o
ar: creating lib/libmcl.a
a - obj/fp.o
a - obj/base64.o
a - obj/bint64.o
g++ obj/pairing.o -o bin/pairing.exe lib/libmcl.a -lrt  -lgmp -lgmpxx -m64

I am also getting the same as mentioned above (attached), still not able to compile sample/pairing.cpp file.

cc -c src/asm/x86-64.S -o obj/base64.o  -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wun
def -m64 -I include -I test -fomit-frame-pointer -DNDEBUG -fno-stack-protector -O3  -fpic -DMCL_USE_LLVM=1 -DMCL_BINT_ASM=1 
cc  -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef -m64 -I include -I test -fomit-f
rame-pointer -DNDEBUG -fno-stack-protector -O3  -fpic -DMCL_USE_LLVM=1 -DMCL_BINT_ASM=1 -c src/asm/bint-x64-amd64.S -o obj/bint64.o
g++  -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef -m64 -I include -I test -fomit-
frame-pointer -DNDEBUG -fno-stack-protector -O3  -fpic -DMCL_USE_LLVM=1 -DMCL_BINT_ASM=1 -c src/fp.cpp -o obj/fp.o -MMD -MP -MF obj/fp.d
g++  -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef -m64 -I include -I test -fomit-
frame-pointer -DNDEBUG -fno-stack-protector -O3  -fpic -DMCL_USE_LLVM=1 -DMCL_BINT_ASM=1 -c sample/pairing.cpp -o obj/pairing.o -MMD -MP -MF obj
/pairing.d
ar rv lib/libmcl.a obj/fp.o obj/base64.o obj/bint64.o
ar: creating lib/libmcl.a
a - obj/fp.o
a - obj/base64.o
a - obj/bint64.o
g++ obj/pairing.o -o bin/pairing.exe lib/libmcl.a -lrt  -lgmp -lgmpxx -m64 
herumi commented 9 months ago

In my environment,

g++ obj/pairing.o -o bin/pairing.exe lib/libmcl.a -lrt  -lgmp -lgmpxx -m64

successes and bin/pairing.exe is made.

Does the command print the attached log in your environment, which starts the following?

/usr/bin/ld: /tmp/ccgoZyfS.o: warning: relocation against `mclb_mulUnit7' in read-only section `.text._ZN3mcl4bint11get_mulUnitEm[_ZN3mcl4bint11get_mulUnitEm]'
/usr/bin/ld: /tmp/ccgoZyfS.o: in function `mcl::bint::impl::Init::Init()':
pairing.cpp:(.text._ZN3mcl4bint4impl4InitC2Ev[_ZN3mcl4bint4impl4InitC5Ev]+0x11): undefined reference to `mcl::bint::initBint()'
/usr/bin/ld: /tmp/ccgoZyfS.o: in function `mcl::bint::get_add(unsigned long)':
...
anujamodi0107 commented 9 months ago

In my environment,

g++ obj/pairing.o -o bin/pairing.exe lib/libmcl.a -lrt  -lgmp -lgmpxx -m64

successes and bin/pairing.exe is made.

Does the command print the attached log in your environment, which starts the following?

/usr/bin/ld: /tmp/ccgoZyfS.o: warning: relocation against `mclb_mulUnit7' in read-only section `.text._ZN3mcl4bint11get_mulUnitEm[_ZN3mcl4bint11get_mulUnitEm]'
/usr/bin/ld: /tmp/ccgoZyfS.o: in function `mcl::bint::impl::Init::Init()':
pairing.cpp:(.text._ZN3mcl4bint4impl4InitC2Ev[_ZN3mcl4bint4impl4InitC5Ev]+0x11): undefined reference to `mcl::bint::initBint()'
/usr/bin/ld: /tmp/ccgoZyfS.o: in function `mcl::bint::get_add(unsigned long)':
...

Yes, in my case also, the command succeeds. When I give the command g++ pairing.cpp, the above log is printed along with multiple linking errors.

herumi commented 9 months ago

Yes, in my case also, the command succeeds. When I give the command g++ pairing.cpp, the above log is printed along with multiple linking errors.

That's not surprising if you don't link lib/libmcl.a, you'll get that kind of error.

anujamodi0107 commented 9 months ago

I understand this. Is there any other command that can link libmcl.a?

herumi commented 9 months ago

What do you want?

To link libmcl.a, type either of the following commands:

g++ sample/pairing.cpp -I include/ lib/libmcl.a
g++ sample/pairing.cpp -I include/ -lmcl -L lib
anujamodi0107 commented 9 months ago

What do you want?

To link libmcl.a, type either of the following commands:

g++ sample/pairing.cpp -I include/ lib/libmcl.a
g++ sample/pairing.cpp -I include/ -lmcl -L lib

Great. Thank you so much for your help. I can compile and run the code. Thanx again.

anujamodi0107 commented 9 months ago

The issue is resolved.