I can tolerate the first build. But every compiling is slow even I don't change any source code. This is what I want to solve.
This is my compiling option. I use visual studio code.
{
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"args": ["-std=c++11", "-stdlib=libc++", "-O2", "-l", "ssl", "-l", "crypto", "-L", "/usr/local/opt/openssl/lib", "-L", "/usr/local/lib",
"-l", "secp256k1", "-l", "boost_filesystem", "-l", "boost_system", "-l", "boost_thread", "-l", "boost_program_options",
"-I", "/usr/local/opt/openssl/include", "-o", "cp-tx-parser", "-g", "-D", "COPYRIGHT_HOLDERS", "-D", "MAC_OSX",
"main.cpp", "rawtransaction.cpp", "univalue.cpp", "univalue_read.cpp", "amount.cpp", "utilstrencodings.cpp", "uint256.cpp", "ripemd160.cpp",
"sha256.cpp", "sha512.cpp", "hmac_sha512.cpp", "hash.cpp", "pubkey.cpp", "transaction.cpp", "script.cpp", "core_read.cpp", "core_write.cpp", "base58.cpp",
"standard.cpp", "interpreter.cpp", "script_error.cpp", "cleanse.cpp", "utilmoneystr.cpp", "sha1.cpp", "chainparams.cpp", "chainparamsbase.cpp",
"merkle.cpp", "protocol.cpp", "netbase.cpp", "sync.cpp", "key.cpp", "arith_uint256.cpp", "pagelocker.cpp", "random.cpp", "util.cpp",
"utiltime.cpp", "block.cpp"
],
"showOutput": "always"
}
I doubt two things:
- g++ command compiles all of code every time.
- Boost might be the cause. Precompiled library can be helpful. (*)
I found before the make command can compile only updated files. I'm looking into it now.
(*)
How to speed up g++ compile time (when using a lot of templates)
Update1
what build system are you using? by xaxxon
Here it is. I'm using MacOS. Seems that gcc and g++ are same.
$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Update2
I just started to read the following book named "Autotools". I'm not familiar with the compiling terms like make or configure. Seems it's very long way to solve this issue.. but I will.
https://www.nostarch.com/autotools.htm
Update 3
I'm also planing to read about make like folowings on this weekends.
https://www.gnu.org/software/make/manual/make.pdf http://www.oreilly.com/openbook/make3/book/index.csp
and cmake as xaxxon recommended.
Update 4
Making a make file by myself is more difficult than I expected. I'm seeing another way. I use Visual Studio Code with c/c++ extention. Compiling is fine but very slow every time as I mentioned. However, seems vscode can output a makefile. I'm taking a look at the way.
How do I set up VSCode to compile C++ code?
Update 5
As a result of comparing the tools; pure make, autotools and cmake, I decided to use cmake. And I'm now struggling with adding libraries.
CMakeList.txt
cmake_minimum_required(VERSION 2.8)
include_directories(/usr/include /usr/local/include /usr/local/opt/openssl/include)
link_directories(/usr/local/lib /usr/local/opt/openssl/lib)
add_library(ssl crypto secp256k1 boost_filesystem boost_system boost_thread boost_program_options)
add_definitions(-DCOPYRIGHT_HOLDERS -DMAC_OSX)
add_definitions("-std=c++11")
add_executable(cp-tx-parser
main.cpp
rawtransaction.cpp
univalue.cpp
.
.
.
utiltime.cpp
block.cpp
)
Error Message
$ cmake .
CMake Error at CMakeLists.txt:4 (add_library):
Cannot find source file:
crypto
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
Update 6
Problem solved. I'm still not sure about CMake but the incremental compile works well. Thank you all.
cmake_minimum_required(VERSION 2.8)
add_definitions("-std=c++11")
# BOOST
set(Boost_INCLUDE_DIR /usr/local/include)
set(Boost_LIBRARY_DIR /usr/local/lib)
find_package(Boost COMPONENTS system filesystem thread program_options REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
# OpenSSL
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)
set(OPENSSL_LIBRARY_DIR /usr/local/opt/openssl/lib)
set(OPENSSL_INCLUDE_DIR /usr/local/opt/openssl/include)
find_package(OPENSSL COMPONENTS crypto REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
link_directories(${OPENSSL_LIBRARY_DIR})
# secp256k1
set(Secp256k1_LIBRARY_DIR /usr/local/lib)
add_executable(cp-tx-parser
main.cpp
univalue.cpp
.
.
.
transaction.cpp
amount.cpp
univalue_write.cpp
)
target_link_libraries(cp-tx-parser ${OPENSSL_LIBRARIES})
target_link_libraries(cp-tx-parser ${Boost_LIBRARIES})
target_link_libraries(cp-tx-parser ${Secp256k1_LIBRARY_DIR}/libsecp256k1.a)