exaexa / codecrypt

Post-quantum cryptography tool (THIS REPOSITORY IS ONLY A MIRROR OF THE MAIN ONE, PLEASE DO NOT FILE BUGS HERE)
https://gitea.blesmrt.net/exa/codecrypt
GNU Lesser General Public License v3.0
308 stars 40 forks source link

Compile issue on macOS #29

Closed jaccovanbuuren closed 6 years ago

jaccovanbuuren commented 6 years ago

When trying to compile codecrypt on macOs (Darwin Kernel Version 17.3.0), Xcode Version 8.2 (8C38), the last step in building ccr fails:

make distclean; ./configure CPPFLAGS="-I/usr/include -I/opt/local/include" LDFLAGS="-L/usr/lib -L/opt/local/lib" CRYPTOPP_CFLAGS="-I/opt/local/include" CRYPTOPP_LIBS="/opt/local/lib" && make

[...]

  CXX      src//ccr-actions.o
  CXXLD    ccr
ld: can't map file, errno=22 file '/opt/local/lib' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [ccr] Error 1

Adding -v to CPPFLAGS produces:

  CXX      src//ccr-actions.o
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin17.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name actions.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 274.2 -v -dwarf-column-info -debugger-tuning=lldb -coverage-file /Users/u0022o6/codecrypt-1.8/src//ccr-actions.o -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0 -dependency-file src/.deps/ccr-actions.Tpo -sys-header-deps -MP -MT src//ccr-actions.o -D "PACKAGE_NAME=\"codecrypt\"" -D "PACKAGE_TARNAME=\"codecrypt\"" -D "PACKAGE_VERSION=\"1.8\"" -D "PACKAGE_STRING=\"codecrypt 1.8\"" -D "PACKAGE_BUGREPORT=\"\"" -D "PACKAGE_URL=\"\"" -D "PACKAGE=\"codecrypt\"" -D "VERSION=\"1.8\"" -D STDC_HEADERS=1 -D HAVE_SYS_TYPES_H=1 -D HAVE_SYS_STAT_H=1 -D HAVE_STDLIB_H=1 -D HAVE_STRING_H=1 -D HAVE_MEMORY_H=1 -D HAVE_STRINGS_H=1 -D HAVE_INTTYPES_H=1 -D HAVE_STDINT_H=1 -D HAVE_UNISTD_H=1 -D HAVE_DLFCN_H=1 -D "LT_OBJDIR=\".libs/\"" -D HAVE_GMP_H=1 -D HAVE_LIBGMP=1 -D HAVE_FFTW3_H=1 -D HAVE_LIBFFTW3=1 -D CRYPTOPP_DIR_PLUS=0 -D HAVE_CRYPTOPP=1 -D HAVE_READPASSPHRASE=1 -D HAVE_MEMSET=1 -D HAVE_MKDIR=1 -D HAVE_FCNTL_H=1 -D HAVE_INTTYPES_H=1 -D HAVE_STDDEF_H=1 -D HAVE_STDLIB_H=1 -D HAVE_STRING_H=1 -D HAVE_SYS_FILE_H=1 -D HAVE_UNISTD_H=1 -D HAVE__BOOL=1 -I . -I .// -I /usr/local/include -I /usr/include -I /opt/local/include -stdlib=libc++ -Wall -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/u0022o6/codecrypt-1.8 -ferror-limit 19 -fmessage-length 166 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.13.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o src//ccr-actions.o -x c++ src//actions.cpp
clang -cc1 version 8.0.0 (clang-800.0.42.1) default target x86_64-apple-darwin17.3.0
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring duplicate directory "."
ignoring duplicate directory "/usr/local/include"
  as it is a non-system directory that duplicates a system directory
ignoring duplicate directory "/usr/include"
  as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
 .
 /opt/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
  CXXLD    ccr
ld: can't map file, errno=22 file '/opt/local/lib' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [ccr] Error 1

Any idea on how to solve this is much appreciated. libcrypto++, fftw3, etc were installed using macports.

exaexa commented 6 years ago

Can you show the exact invocation of clang? (using e.g. make V=1)

Also, what is the argument CRYPTOPP_LIBS="/opt/local/lib" supposed to do? (IIRC it should contain a compiler flag for linking with the library, not a directory)

jaccovanbuuren commented 6 years ago

Of course! Thank you! That did the trick. Anyway, without CRYPTOPP_LIBS, compiling fails:

configure: error: Package requirements (libcrypto++) were not met:

No package 'libcrypto++' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables CRYPTOPP_CFLAGS
and CRYPTOPP_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

...But this does seem to work:

make distclean; ./configure CPPFLAGS="-I/usr/include -I/opt/local/include -v" LDFLAGS="-L/usr/lib -L/opt/local/lib" CRYPTOPP_CFLAGS="-I/opt/local/include" CRYPTOPP_LIBS=" /opt/local/lib/libcryptopp.a" && make V=1

[...]

g++ -DPACKAGE_NAME=\"codecrypt\" -DPACKAGE_TARNAME=\"codecrypt\" -DPACKAGE_VERSION=\"1.8\" -DPACKAGE_STRING=\"codecrypt\ 1.8\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"codecrypt\" -DVERSION=\"1.8\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_GMP_H=1 -DHAVE_LIBGMP=1 -DHAVE_FFTW3_H=1 -DHAVE_LIBFFTW3=1 -DCRYPTOPP_DIR_PLUS=0 -DHAVE_CRYPTOPP=1 -DHAVE_READPASSPHRASE=1 -DHAVE_MEMSET=1 -DHAVE_MKDIR=1 -DHAVE_FCNTL_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDDEF_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_SYS_FILE_H=1 -DHAVE_UNISTD_H=1 -DHAVE__BOOL=1 -I.  -I.// -I/usr/local/include -I/usr/include -I/opt/local/include -v -Wall -std=c++11  -MT src//ccr-actions.o -MD -MP -MF src/.deps/ccr-actions.Tpo -c -o src//ccr-actions.o `test -f 'src//actions.cpp' || echo './'`src//actions.cpp
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin17.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name actions.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 274.2 -v -dwarf-column-info -debugger-tuning=lldb -coverage-file /Users/u0022o6/codecrypt-1.8/src//ccr-actions.o -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0 -dependency-file src/.deps/ccr-actions.Tpo -sys-header-deps -MP -MT src//ccr-actions.o -D "PACKAGE_NAME=\"codecrypt\"" -D "PACKAGE_TARNAME=\"codecrypt\"" -D "PACKAGE_VERSION=\"1.8\"" -D "PACKAGE_STRING=\"codecrypt 1.8\"" -D "PACKAGE_BUGREPORT=\"\"" -D "PACKAGE_URL=\"\"" -D "PACKAGE=\"codecrypt\"" -D "VERSION=\"1.8\"" -D STDC_HEADERS=1 -D HAVE_SYS_TYPES_H=1 -D HAVE_SYS_STAT_H=1 -D HAVE_STDLIB_H=1 -D HAVE_STRING_H=1 -D HAVE_MEMORY_H=1 -D HAVE_STRINGS_H=1 -D HAVE_INTTYPES_H=1 -D HAVE_STDINT_H=1 -D HAVE_UNISTD_H=1 -D HAVE_DLFCN_H=1 -D "LT_OBJDIR=\".libs/\"" -D HAVE_GMP_H=1 -D HAVE_LIBGMP=1 -D HAVE_FFTW3_H=1 -D HAVE_LIBFFTW3=1 -D CRYPTOPP_DIR_PLUS=0 -D HAVE_CRYPTOPP=1 -D HAVE_READPASSPHRASE=1 -D HAVE_MEMSET=1 -D HAVE_MKDIR=1 -D HAVE_FCNTL_H=1 -D HAVE_INTTYPES_H=1 -D HAVE_STDDEF_H=1 -D HAVE_STDLIB_H=1 -D HAVE_STRING_H=1 -D HAVE_SYS_FILE_H=1 -D HAVE_UNISTD_H=1 -D HAVE__BOOL=1 -I . -I .// -I /usr/local/include -I /usr/include -I /opt/local/include -stdlib=libc++ -Wall -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/u0022o6/codecrypt-1.8 -ferror-limit 19 -fmessage-length 166 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.13.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o src//ccr-actions.o -x c++ src//actions.cpp
clang -cc1 version 8.0.0 (clang-800.0.42.1) default target x86_64-apple-darwin17.3.0
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring duplicate directory "."
ignoring duplicate directory "/usr/local/include"
  as it is a non-system directory that duplicates a system directory
ignoring duplicate directory "/usr/include"
  as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
 .
 /opt/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
mv -f src/.deps/ccr-actions.Tpo src/.deps/ccr-actions.Po
/bin/sh ./libtool  --tag=CXX   --mode=link g++ -Wall -std=c++11  -L/usr/local/lib -I/opt/local/include  -L/usr/lib -L/opt/local/lib -o ccr src//ccr-generator.o src//ccr-base64.o src//ccr-message.o src//ccr-str_match.o src//ccr-xsynd.o src//ccr-algo_suite.o src//ccr-fft.o src//ccr-algos_sig.o src//ccr-sencode.o src//ccr-mce_qcmdpc.o src//ccr-ios.o src//ccr-iohelpers.o src//ccr-sc.o src//ccr-pwrng.o src//ccr-serialization.o src//ccr-seclock.o src//ccr-matrix.o src//ccr-keyring.o src//ccr-hashfile.o src//ccr-algos_enc.o src//ccr-bvector.o src//ccr-fmtseq.o src//ccr-hash.o src//ccr-gf2m.o src//ccr-privfile.o src//ccr-symkey.o src//ccr-chacha.o src//ccr-permutation.o src//ccr-main.o src//ccr-envelope.o src//ccr-polynomial.o src//ccr-actions.o -lgmp -lfftw3 -lm /opt/local/lib/libcryptopp.a    -lfftw3 -lgmp 
libtool: link: g++ -Wall -std=c++11 -I/opt/local/include -o ccr src//ccr-generator.o src//ccr-base64.o src//ccr-message.o src//ccr-str_match.o src//ccr-xsynd.o src//ccr-algo_suite.o src//ccr-fft.o src//ccr-algos_sig.o src//ccr-sencode.o src//ccr-mce_qcmdpc.o src//ccr-ios.o src//ccr-iohelpers.o src//ccr-sc.o src//ccr-pwrng.o src//ccr-serialization.o src//ccr-seclock.o src//ccr-matrix.o src//ccr-keyring.o src//ccr-hashfile.o src//ccr-algos_enc.o src//ccr-bvector.o src//ccr-fmtseq.o src//ccr-hash.o src//ccr-gf2m.o src//ccr-privfile.o src//ccr-symkey.o src//ccr-chacha.o src//ccr-permutation.o src//ccr-main.o src//ccr-envelope.o src//ccr-polynomial.o src//ccr-actions.o -Wl,-bind_at_load  -L/usr/local/lib -L/usr/lib -L/opt/local/lib -lm /opt/local/lib/libcryptopp.a -lfftw3 -lgmp

Results in:

$ file ccr
ccr: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|WEAK_DEFINES|BINDS_TO_WEAK|PIE>

$ ls -al ccr
-rwxrwxr-x  1 user  staff  4350260 20 jan 15:54 ccr

This should work! Thanks!

J

exaexa commented 6 years ago

In fact you want something like CRYPTOPP_LIBS="-lcrypto++" (or maybe CRYPTOPP_LIBS="-lcryptopp") because the way you use it now seems to force static linking with crypto++ (which may not be what you actually want).

Please let me know if that works.

jaccovanbuuren commented 6 years ago

Yes, that works too. That ends up a lot smaller: 1328660 vs 4350260.

exaexa commented 6 years ago

That's the preferred way. Thanks for confirm; considering this solved.

jaccovanbuuren commented 6 years ago

👍