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

CC BY-SA 4.0
2019-01-08T11:14:12.783Z
One last guess: renaming the `rainforest.c` to `rainforest.cpp` might work.
MCCCS
CC BY-SA 4.0
2019-01-08T02:18:18.453Z
2019-01-08T02:18:18.453Z
EndlessLoop
<p>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?</p>

<p>My fork is based of Bitcoin Core 0.12.1
I am compiling on Ubuntu 16.04</p>

<p>Here is the compilation error:</p>

<pre><code>  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
</code></pre>

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

<pre><code># crypto primitives library
crypto_libbitcoin_crypto_a_CPPFLAGS = $(AM_CPPFLAGS) 
$(BITCOIN_CONFIG_INCLUDES)
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 \
   crypto/rainforest/rainforest.h
</code></pre>

<p>The files are rainforest.c and rainforest.h</p>

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

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

<pre><code>extern "C"{ 
#include "crypto/rainforest/rainforest.h"
}
</code></pre>

CC BY-SA 4.0
2019-01-07T09:55:26.317Z
What/of which type is rf_crc32_tabl?
MCCCS
CC BY-SA 4.0
2019-01-07T15:01:31.497Z
@MCCCS It is declared as `const uint32_t rf_crc32_table[256]`
EndlessLoop
CC BY-SA 4.0
2019-01-07T15:09:04.537Z
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
CC BY-SA 4.0
2019-01-07T20:05:57.600Z
@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
<altcoin-development><compiling><c>
Adding C library to Makefile
EndlessLoop
# Adding C library to Makefile

(Asked by: username_0 on 2019-01-06)

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) 
$(BITCOIN_CONFIG_INCLUDES)
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 \
   crypto/rainforest/rainforest.h

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"
}

**Tags:** altcoin-development, compiling, c

> **Comments:**
> **username_1**: What/of which type is rf_crc32_tabl?  
> **username_0**: @username_1 It is declared as `const uint32_t rf_crc32_table[256]`  
> **username_1**: 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.  
> **username_0**: @username_1 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  

---

## 1 answers

### Answer by username_0 on 2019-01-08. Score: 0 | Accepted answer

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.

> **Comments:**
> **username_1**: One last guess: renaming the `rainforest.c` to `rainforest.cpp` might work.  

---

