Combining Native Client with external library (HElib library, NTL library)

92 views
Skip to first unread message

Lichang Wang

unread,
Nov 24, 2015, 2:08:08 PM11/24/15
to Native-Client-Discuss
Hello,

I was new to Native-Client, when I try Native-Client wihout HElib library(https://github.com/shaih/HElib), it works fine. But, when I introduced HElib library to my Native-Client application, the  pnacl-clang++ compiler always reports error.
It takes me a lot of time, but still can't be solved. The HElib also worked fine without Native_Client. I think its the problem of C++ library or NTL library path,,,but I can't figure out it.

Thank you in advance for any help !!

Here is the Makefile:
//////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

      FILE := temple
 17
 18 THIS_MAKEFILE := $(abspath $(lastword $(MAKEFILE_LIST)))
 19 NACL_SDK_ROOT ?= $(abspath $(dir $(THIS_MAKEFILE))../)
 20
 21 #all:
 22 #       @echo  $(MAKEFILE_LIST)
 23 #       @echo  $(THIS_MAKEFILE)
 24 #       @echo  $(NACL_SDK_ROOT)
 25
 26 # Project Build flags
 27 WARNINGS := -Wno-long-long -Wall -Wswitch-enum -pedantic -Werror
 28 CLANGFLAGS := --pnacl-allow-native -std=gnu++11 -stdlib=libc++  -arch x86_64 #-DBOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK=1 -DB    OOST_HAS_GETTIMEOFDAY=1  -pthread -std=gnu++11  $(WARNINGS)
 29
 30 #
 31 # Compute tool paths
 32 #
 33 GETOS := python $(NACL_SDK_ROOT)/tools/getos.py
 34 OSHELPERS = python $(NACL_SDK_ROOT)/tools/oshelpers.py
 35 OSNAME := $(shell $(GETOS))
 36 RM := $(OSHELPERS) rm
 37
 38 PNACL_TC_PATH := $(abspath $(NACL_SDK_ROOT)/toolchain/$(OSNAME)_pnacl)
 39 PNACL_CXX := $(PNACL_TC_PATH)/bin/pnacl-clang++
 40 PNACL_FINALIZE := $(PNACL_TC_PATH)/bin/pnacl-finalize

      HOMOMOR_ST_LIB := $(NACL_SDK_ROOT)/wlc_Homomorphic/HomomoLib/HElib-master/src/fhe.a
 43 HOMOMOR_FLAGS := -I/usr/local/include -I$(NACL_SDK_ROOT)/wlc_Homomorphic/HomomoLib/HElib-master/src
 44 HOMOMOR_LDFLAGS := -L/usr/local/lib  -lntl -lgmp -lm
 45
 46 CXXFLAGS := -I$(NACL_SDK_ROOT)/include
 47 LDFLAGS := -L$(NACL_SDK_ROOT)/lib/pnacl/Release -lppapi_cpp -lppapi
 48
 49 # Disable DOS PATH warning when using Cygwin based tools Windows
 50 #
 51 CYGWIN ?= nodosfilewarning
 52 export CYGWIN
 53
 54
 55 # Declare the ALL target first, to make the 'all' target the default build
 56 all: $(FILE).pexe
 57
 58 clean:
 59         $(RM) $(FILE).pexe $(FILE).bc
 60
 61 $(FILE).bc: $(FILE).cc
 62         $(PNACL_CXX) $(CLANGFLAGS)   -o $@ $< -O2 $(HOMOMOR_ST_LIB) $(HOMOMOR_FLAGS)  $(HOMOMOR_LDFLAGS)  $(CXXFLAGS) $(LDFLAG    S)
 63 $(FILE).pexe: $(FILE).bc
 64         $(PNACL_FINALIZE) -o $@ $<  
////////////////////////////////////////////////////////////////////////////////////////////////////////////

Below is trouble shot:

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

/home/lichang/NativeClient/nacl_sdk/pepper_46/toolchain/linux_pnacl/bin/pnacl-clang++ --pnacl-allow-native -std=gnu++11 -stdlib=libc++  -arch x86_64    -o homomoEncryption.bc homomoEncryption.cc -O2 /home/lichang/NativeClient/nacl_sdk/pepper_46/wlc_Homomorphic/HomomoLib/HElib-master/src/fhe.a -I/usr/local/include -I/home/lichang/NativeClient/nacl_sdk/pepper_46/wlc_Homomorphic/HomomoLib/HElib-master/src  -L/usr/local/lib  -lntl -lgmp -lm    -I/home/lichang/NativeClient/nacl_sdk/pepper_46/include   -L/home/lichang/NativeClient/nacl_sdk/pepper_46/lib/pnacl/Release -lppapi_cpp -lppapi


In file included from homomoEncryption.cc:11:
In file included from /usr/local/include/NTL/ZZ.h:19:
/usr/local/include/NTL/tools.h:234:32: warning: shift count >= width of type
      [-Wshift-count-overflow]
   { unsigned long y = a;  x = NTL_ULONG_TO_LONG(y); }
                               ^~~~~~~~~~~~~~~~~~~~
/usr/local/include/NTL/ctools.h:273:26: note: expanded from macro 'NTL_ULONG_TO_LONG'
   ((((unsigned long) a) >> (NTL_BITS_PER_LONG-1)) ? \
                         ^  ~~~~~~~~~~~~~~~~~~~~~
In file included from homomoEncryption.cc:11:
In file included from /usr/local/include/NTL/ZZ.h:19:
/usr/local/include/NTL/tools.h:237:10: warning: shift count >= width of type
      [-Wshift-count-overflow]
   { x = NTL_ULONG_TO_LONG(a); }
         ^~~~~~~~~~~~~~~~~~~~
/usr/local/include/NTL/ctools.h:273:26: note: expanded from macro 'NTL_ULONG_TO_LONG'
   ((((unsigned long) a) >> (NTL_BITS_PER_LONG-1)) ? \
                         ^  ~~~~~~~~~~~~~~~~~~~~~
In file included from homomoEncryption.cc:11:
In file included from /usr/local/include/NTL/ZZ.h:19:
/usr/local/include/NTL/tools.h:245:35: warning: shift count >= width of type
      [-Wshift-count-overflow]
   { unsigned long y = a;  return NTL_ULONG_TO_LONG(y); }
                                  ^~~~~~~~~~~~~~~~~~~~

/usr/local/include/NTL/sp_arith.h:748:41: warning: shift count >= width of type
      [-Wshift-count-overflow]
   unsigned long rr = (cast_unsigned(b) << NTL_SP_NBITS) - cast_unsigned(q)*cas...
                                        ^  ~~~~~~~~~~~~                            ^
In file included from homomoEncryption.cc:11:
In file included from /usr/local/include/NTL/ZZ.h:20:
/usr/local/include/NTL/vector.h:414:20: warning: overflow in expression; result is
      2147483632 with type 'long' [-Winteger-overflow]
/usr/local/include/NTL/ctools.h:251:5: note: expanded from macro 'NTL_SNS_REALLOC'
   (NTL_OVERFLOW1(n, a, b) ? ((void *) 0) : \
    ^
/usr/local/include/NTL/ctools.h:165:34: note: expanded from macro 'NTL_OVERFLOW1'
    (((long) (n)) >= (NTL_OVFBND1-((long)(b))+((long)(a))-1)/((long)(a))))))
                                 ^
26 warnings generated.
/usr/local/lib/libntl.a(thread.o): error: undefined reference to 'std::string::assign(char const*, unsigned long)'
/usr/local/lib/libntl.a(fileio.o): error: undefined reference to 'std::string::append(std::string const&)'
/usr/local/lib/libntl.a(fileio.o): error: undefined reference to 'std::basic_iostream<char, std::char_traits<char> >::~basic_iostream()'
/usr/local/lib/libntl.a(fileio.o): error: undefined reference to 'std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_stringstream()'
/usr/local/lib/libntl.a(fileio.o): error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'

/usr/local/lib/libntl.a(GF2EXFactoring.o): error: undefined reference to 'std::basic_ifstream<char, std::char_traits<char> >::~basic_ifstream()'
/usr/local/lib/libntl.a(GF2EXFactoring.o): error: undefined reference to 'std::basic_filebuf<char, std::char_traits<char> >::~basic_filebuf()'

/usr/local/lib/libntl.a(GF2EXFactoring.o): error: undefined reference to 'std::basic_ios<char, std::char_traits<char> >::init(std::basic_streambuf<char, std::char_traits<char> >*)'
/usr/local/lib/libntl.a(GF2EXFactoring.o): error: undefined reference to 'vtable for std::basic_ios<char, std::char_traits<char> >'

/home/lichang/NativeClient/nacl_sdk/pepper_46/wlc_Homomorphic/HomomoLib/HElib-master/src/fhe.a(NumbTh.o): error: undefined reference to 'std::cerr'
/home/lichang/NativeClient/nacl_sdk/pepper_46/wlc_Homomorphic/HomomoLib/HElib-master/src/fhe.a(NumbTh.o): error: undefined reference to 'std::istream::get()'
/home/lichang/NativeClient/nacl_sdk/pepper_46/wlc_Homomorphic/HomomoLib/HElib-master/src/fhe.a(NumbTh.o): error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'
/home/lichang/NativeClient/nacl_sdk/pepper_46/wlc_Homomorphic/HomomoLib/HElib-master/src/fhe.a(NumbTh.o): error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'
/home/lichang/NativeClient/nacl_sdk/pepper_46/wlc_Homomorphic/HomomoLib/HElib-master/src/fhe.a(NumbTh.o): error: undefined reference to 'std::string::assign(std::string const&)'
/home/lichang/NativeClient/nacl_sdk/pepper_46/wlc_Homomorphic/HomomoLib/HElib-master/src/fhe.a(NumbTh.o): error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/home/lichang/NativeClient/nacl_sdk/pepper_46/wlc_Homomorphic/HomomoLib/HElib-master/src/fhe.a(NumbTh.o): error: undefined reference to 'std::string::_Rep::_M_dispose(std::allocator<char> const&)'
/home/lichang/NativeClient/nacl_sdk/pepper_46/wlc_Homomorphic/HomomoLib/HElib-master/src/fhe.a(NumbTh.o): error: undefined reference to 'std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)'
.............
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Any suggestion is appreciated!

Thank you so much!

Best,

Lichang




Ben Smith

unread,
Nov 24, 2015, 2:35:12 PM11/24/15
to Native-Client-Discuss
There may be other problems, but one that jumps out at me is this:

 -L/usr/local/lib

You can't use your system libraries with the NaCl or PNaCl compilers, you'll have to port those libraries first.

Also, are you trying to build for NaCl or PNaCl? Because currently you are using

-arch x86_64

Which AFAIK will build a NaCl binary instead. There's a more convenient way to do this using nacl-clang rather than pnacl-clang. You can use x86_64-nacl-clang++ from the same directory as pnacl-clang++.

If you want to build a PNaCl binary, you can omit --pnacl-allow-native -arch x86_64

-Ben

Lichang Wang

unread,
Nov 24, 2015, 3:28:18 PM11/24/15
to Native-Client-Discuss
Thank you so much for your reply, Ben,

According to you instructions, I changed to x86_64-nacl-clang++ instead of pnacl-clang++, and remove --pnacl-allow-native -arch x86_64 options. there is one error left with 25 warnings as below.
I realised the approach of porting NTL library to NaCl but still can't find a complete document to reference. So how to port a library?
 
trouble shot:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/usr/local/include/NTL/ctools.h:251:5: note: expanded from macro 'NTL_SNS_REALLOC'
   (NTL_OVERFLOW1(n, a, b) ? ((void *) 0) : \
    ^
/usr/local/include/NTL/ctools.h:165:34: note: expanded from macro 'NTL_OVERFLOW1'
    (((long) (n)) >= (NTL_OVFBND1-((long)(b))+((long)(a))-1)/((long)(a))))))
                                 ^
25 warnings generated.
/home/lichang/NativeClient/nacl_sdk/pepper_46/lib/pnacl/Release/libppapi_cpp.a: error adding symbols: File format not recognized
x86_64-nacl-clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [homomoEncryption.bc] Error 1

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Thanks again!

Best,

Lichang

Dennis Kane

unread,
Nov 25, 2015, 8:59:23 AM11/25/15
to Native-Client-Discuss
You should probably install naclports and try building some packages. Then, look inside 
of the naclports/src/out/logs directory to see the verbose output that is emitted by 
the build system. Otherwise, you will spend your entire life trying to figure out 
how the linking phase works.

You might want to start out with smaller parts of a library, and get confident that you 
can get a working build. If you have to, start out with one function and continue from 
there.

Then, it is good to have your own little testing framework, with a local server and some html and javascript files.

Lichang Wang

unread,
Nov 25, 2015, 4:10:42 PM11/25/15
to Native-Client-Discuss
Thanks Dennis,

 I will try it.

Best,

Lichang
Reply all
Reply to author
Forward
Message has been deleted
0 new messages