我可以容忍第一次构建。但即使我不改变任何源代码,每次编译都很慢。这就是我想要解决的问题。
这是我的编译选项。我使用visual studio代码。
{
"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"
}
我怀疑两件事:
我在make命令之前发现只能编译更新的文件。我现在正在调查它。
(*)
How to speed up g++ compile time (when using a lot of templates)
UPDATE1
您使用的构建系统是什么?通过xaxxon
在这里。我正在使用MacOS。似乎gcc和g ++是相同的。
$ 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
我刚刚开始阅读以下名为" Autotools"的书。我不熟悉make或configure等编译术语。似乎解决这个问题还有很长的路要走..但我会。
https://www.nostarch.com/autotools.htm
更新3
我也计划在这个周末阅读有关下载的内容。
https://www.gnu.org/software/make/manual/make.pdf http://www.oreilly.com/openbook/make3/book/index.csp
和cmake一样推荐xaxxon。
更新4
自己创建一个make文件比我想象的要困难。我看到了另一种方式。我使用带有c / c ++扩展的Visual Studio代码。正如我所提到的,每次编译都很好但很慢。但是,似乎vscode可以输出一个makefile。我正在看看这条路。
How do I set up VSCode to compile C++ code?
更新5
通过比较工具;纯制作,autotools和cmake,我决定使用cmake。我现在正在努力添加库。
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
)
错误消息
$ 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
更新6
问题解决了。 我仍然不确定CMake,但增量编译效果很好。谢谢大家。
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)