I am developing an altcoin using a new PoW algorithm which is written in C to test the algorithm. I get compilation errors related to compiling the C code when trying to compile. How can I properly add the C code to the Makefile?

My fork is based of Bitcoin Core 0.12.1 I am compiling on Ubuntu 16.04

Here is the compilation error:

  CXXLD    bitcoind
  /usr/bin/ld: crypto/libbitcoin_crypto.a(crypto_libbitcoin_crypto_a- 
  rainforest.o): relocation R_X86_64_32S against `rf_crc32_table' can not be 
  used when making a shared object; recompile with -fPIC
  crypto/libbitcoin_crypto.a: error adding symbols: Bad value

Here is how I added the files to src/Makefile.am:

# crypto primitives library
crypto_libbitcoin_crypto_a_CPPFLAGS = $(AM_CPPFLAGS) 
crypto_libbitcoin_crypto_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
crypto_libbitcoin_crypto_a_SOURCES = \
   crypto/common.h \
   crypto/hmac_sha256.cpp \
   crypto/hmac_sha256.h \
   crypto/hmac_sha512.cpp \
   crypto/hmac_sha512.h \
   crypto/ripemd160.cpp \
   crypto/ripemd160.h \
   crypto/sha1.cpp \
   crypto/sha1.h \
   crypto/sha256.cpp \
   crypto/sha256.h \
   crypto/sha512.cpp \
   crypto/sha512.h \
   crypto/rainforest/rainforest.c \

The files are rainforest.c and rainforest.h

Sorry for this question, I am a newbie in C and C++ developing, I come from Java and Python

EDIT: I didn't mention before that I linked rainforest.h by doing this:

extern "C"{ 
#include "crypto/rainforest/rainforest.h"
  • What/of which type is rf_crc32_tabl? – MCCCS Jan 7 at 9:55
  • @MCCCS It is declared as const uint32_t rf_crc32_table[256] – EndlessLoop Jan 7 at 15:01
  • If you include the functions with extern "C", then you should also declare them with extern "C" in the source file. Although your file is a c file, keep in mind that it'll be compiled by the cpp compiler. – MCCCS Jan 7 at 15:09
  • @MCCCS Tried that, got the same error, not sure what to do but I think there may be a way to change the makefile so the compiler properly compiles – EndlessLoop Jan 7 at 20:05

I was able to solve this by compiling using make -j2 CFLAGS="-fPIC" That solution isn't that convenient, I would rather modify the configure.ac or Makefile but it works.

  • One last guess: renaming the rainforest.c to rainforest.cpp might work. – MCCCS Jan 8 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.