I need some help with adding files to the code base by adding them to the autotools build system. Other posts that try to answer the same question haven't helped me. I am experimenting with Bitcoin's codebase and I am trying to add new files to the codebase. I am trying to add a static library in the src/Makefile.am by adding these lines:
LIBGLYPH=libglyph.a
libglyph_a_SOURCES = \
glyph/glp.c \
glyph/glp_utils.c \
glyph/glp_rand.c \
glyph/glp_rand_openssl_aes.c \
glyph/FFT/FFT_1024_65537.c \
glyph/converter.c
libglyph_a_CPPFLAGS = $(AM_CPPFLAGS)
libglyph_a_CFLAGS =
libglyph_a_CXXFLAGS = $(AM_CXXFLAGS)
EXTRA_LIBRARIES += \
$(LIBBITCOIN_CRYPTO) \
$(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_COMMON) \
$(LIBGLYPH) \
$(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_CLI) \
$(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_ZMQ)
bitcoin_tx_LDADD = \
$(LIBUNIVALUE) \
$(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_CRYPTO) \
$(LIBGLYPH) \
$(LIBSECP256K1)
bitcoind_LDADD = \
$(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_COMMON) \
$(LIBUNIVALUE) \
$(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_ZMQ) \
$(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_CRYPTO) \
$(LIBLEVELDB) \
$(LIBLEVELDB_SSE42) \
$(LIBMEMENV) \
$(LIBGLYPH) \
$(LIBSECP256K1)
I have tried at least 30 different compilation attempts where I reordered the compilation and/or renamed the library.
Error:
make[3]: Entering directory '/home/joe/glyph/glyphCodebase/BitcoinUnlimited/src/secp256k1'
make[3]: Leaving directory '/home/joe/glyph/glyphCodebase/BitcoinUnlimited/src/secp256k1'
CXXLD bitcoind
libbitcoin_common.a(libbitcoin_common_a-key.o): In function `CKey::MakeNewKey()':
/home/joe/glyph/glyphCodebase/BitcoinUnlimited/src/key.cpp:25: undefined reference to `glp_gen_sk(glp_signing_key_st*)'
libbitcoin_common.a(libbitcoin_common_a-key.o): In function `CKey::GetPubKey() const':
/home/joe/glyph/glyphCodebase/BitcoinUnlimited/src/key.cpp:48: undefined reference to `glp_gen_pk(glp_public_key_st*, glp_signing_key_st)'
collect2: error: ld returned 1 exit status
Makefile:3556: recipe for target 'bitcoind' failed
make[2]: *** [bitcoind] Error 1
make[2]: Leaving directory '/home/joe/glyph/glyphCodebase/BitcoinUnlimited/src'
Makefile:9207: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/joe/glyph/glyphCodebase/BitcoinUnlimited/src'
Makefile:670: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1
This error occurs despite libglyph.a being made and containing the functions. I have tried to add the library header and C files to common library with no luck either. I have rearranged the EXTRA_LIBRARIES section of the Makefile.am with no luck.
In order to simplify the problem, here is a really simple example that spits out the same error:
Adding 1 .h and 1 .cpp file to 1 already made library: libbitcoin_common
new files: src/testFile.cpp src/testFile.h
testFile.h:
void testFunction();
testFile.cpp
#include "testFile.h"
#include <stdio.h>
void testFunction() {
printf("I am a test function");
}
added following lines to key.cpp:
#include "testFile.h"
void CKey::MakeNewKey()
{
testFunction();
...
...
...
}
Then in src/Makefile.am
BITCOIN_CORE_H = \
testFile.h \
...
...
and the testFile to the common library, where key.cpp is, as mentioned by Pieter Wuille here
# common: shared between bitcoind, and bitcoin-qt and non-server tools
libbitcoin_common_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_common_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_common_a_SOURCES = \
amount.cpp \
base58.cpp \
chainparams.cpp \
coins.cpp \
compressor.cpp \
core_read.cpp \
core_write.cpp \
keystore.cpp \
netaddress.cpp \
netbase.cpp \
protocol.cpp \
scheduler.cpp \
script/sign.cpp \
script/standard.cpp \
key.cpp \
testFile.cpp \
$(BITCOIN_CORE_H)
The error:
libbitcoin_common.a(libbitcoin_common_a-key.o): In function
`CKey::MakeNewKey()':
/home/joe/glyph/glyphCodebase/BitcoinUnlimited/src/key.cpp:23: undefined reference to `testFunction()
Please help me out with this. Thanks a lot