[Daozy][区块链 EOS 课程]第2课 EOS编译和启动

椟夜学院– 区块链 EOS 课程

官方网站:http://www.duyeyun.top/college/

@(区块链 EOS 课程)

椟夜学院– 区块链 EOS 课程

官方网站:http://www.duyeyun.top/college/

开发环境

centos、ubuntu均可,可以在windows上安装虚拟机。

下载源码

一步到位,下载所有子模块, 参数–recursive表示下载所有子模块:
git clone --recursive https://github.com/tencupofkaiwater/eos.git
如果开始没有加–recursive,后续可以进入到eos目录,使用下面的进行更新:
git submodule update --init --recursive

编译源码

在源码根目录下:

# ./eosio_build.sh
````





<div class="se-preview-section-delimiter"></div>

##### 错误1:




<div class="se-preview-section-delimiter"></div>

Enabling Centos devtoolset-7.

Unable to enable Centos devtoolset-7 at this time.


解决这问题的思路就是安装一个高版本的gcc。那么在 CentOS7中,安装高版本gcc,一般有两个方法:

1. 使用源码。

2. 使用SCLo, 什么是SCLo,简单的说,就是比epel更丰富的软件包集合。https://www.softwarecollections.org/en/about/





<div class="se-preview-section-delimiter"></div>

##### 快速使用方法:https://www.softwarecollections.org/en/docs/
- 使用SCLo,顺序安装:




<div class="se-preview-section-delimiter"></div>

yum install centos-release-scl

好了,有了SCLo库之后,我们就可以安装GCC7了。





<div class="se-preview-section-delimiter"></div>

yum install devtoolset-7-gcc
yum install devtoolset-7-gcc-g++


再装GCC7的 libasan




<div class="se-preview-section-delimiter"></div>

yum install devtoolset-7-libasan-devel


他们是devtoolset,和常规的软件还不太一样




<div class="se-preview-section-delimiter"></div>

devtoolset-7 - Developer Toolset is designed for developers working on CentOS or Red Hat Enterprise Linux platform. It provides current versions of the GNU Compiler Collection,
GNU Debugger, and other development, debugging, and performance monitoring tools.


因为他们都是装在opt下面的,




<div class="se-preview-section-delimiter"></div>

[[email protected] chimpanzee]# rpm -ql devtoolset-7-libasan-devel
/opt/rh/devtoolset-7/root/usr/lib/gcc
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/libasan.a
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/libasan.so
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/libasan_preinit.o
/opt/rh/devtoolset-7/root/usr/share/doc/devtoolset-7-libasan-devel-7.2.1
/opt/rh/devtoolset-7/root/usr/share/doc/devtoolset-7-libasan-devel-7.2.1/ChangeLog.bz2
/opt/rh/devtoolset-7/root/usr/share/doc/devtoolset-7-libasan-devel-7.2.1/LICENSE.TXT
[[email protected] chimpanzee]#


配置一下,就可以用了




<div class="se-preview-section-delimiter"></div>

[[email protected] chimpanzee]# source /opt/rh/devtoolset-7/enable
[[email protected] chimpanzee]# gcc -v
… …
gcc version 7.2.1 20170829 (Red Hat 7.2.1-1) (GCC)
这个 enable 属于软件 devtoolset-7-runtime

[[email protected] chimpanzee]# rpm -qf /opt/rh/devtoolset-7/enable
devtoolset-7-runtime-7.0-8.el7.sc1.x86_64

这个时候,再去使用sanitizer编译程序,之后就能够看见调试信息了,也能够成功的断到libasan的断点了。

继续build




<div class="se-preview-section-delimiter"></div>

./eosio_build.sh


开始会下载依赖包,然后是更新包同时也会安装一些依赖包,出现如下部分包安装失败,暂时不知会不会影响后期编译。





<div class="se-preview-section-delimiter"></div>

##### 错误2




<div class="se-preview-section-delimiter"></div>

正在安装 : python-urllib3-1.10.2-5.el7.noarch 295/2018
error: unpacking of archive failed on file /usr/lib/python2.7/site-packages/urllib3/packages/ssl_match_hostname: cpio: rename
正在安装 : python-requests-2.6.0-1.el7_1.noarch 296/2018
error: python-urllib3-1.10.2-5.el7.noarch: install failed
正在安装 : python2-pyasn1-modules-0.1.9-7.el7.noarch

正在更新 : 1:java-1.8.0-openjdk-headless-1.8.0.171-8.b10.el7_5.x86_64 342/2018
warning: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/jre/lib/security/java.security created as /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/jre/lib/security/java.security.rpmnew
restored /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/jre/lib/security/java.security.rpmnew to /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/jre/lib/security/java.security

warning: /var/lib/logrotate.status saved as /var/lib/logrotate.status.rpmsave
清理 : plymouth-core-libs-0.8.9-0.24.20140113.el7.centos.x86_64






<div class="se-preview-section-delimiter"></div>

##### 解决上面依赖安装错误




<div class="se-preview-section-delimiter"></div>

###### 手动安装python-urllib3




<div class="se-preview-section-delimiter"></div>

yum install python-urllib3






<div class="se-preview-section-delimiter"></div>

##### 再次build




<div class="se-preview-section-delimiter"></div>

./eosio_build.sh

又提示安装依赖包,输入yes,继续安装。





<div class="se-preview-section-delimiter"></div>

##### 安装




<div class="se-preview-section-delimiter"></div>

cd build

make install


编译完成后,在系统环境下已经安装好eos
![image](http://upload-images.jianshu.io/upload_images/4046353-db771c8284501c2a?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

同时生成的这些目标文件也在当前目录下的./programs目录下。




<div class="se-preview-section-delimiter"></div>

cd programs/

ll

drwxrwxr-x 3 duye duye 119 5月 31 07:14 cleos
drwxrwxr-x 2 duye duye 65 5月 31 07:07 CMakeFiles
-rw-rw-r– 1 duye duye 1653 5月 31 07:07 cmake_install.cmake
-rw-rw-r– 1 duye duye 396 5月 31 00:58 CTestTestfile.cmake
drwxrwxr-x 3 duye duye 109 5月 31 07:13 eosio-abigen
drwxrwxr-x 3 duye duye 90 5月 31 07:07 eosio-applesedemo
drwxrwxr-x 4 duye duye 4096 6月 5 07:52 eosio-launcher
drwxrwxr-x 3 duye duye 102 5月 31 07:13 keosd
-rw-rw-r– 1 duye duye 7285 5月 31 00:58 Makefile
drwxrwxr-x 3 duye duye 120 6月 5 07:50 nodeos


我们需要关心三个主要的进程:
- cleos
    > 它是一个命令行程序,通过控制台命令给EOS下达指令。
- nodeos
    > 其实它就是挖矿客户端。在启动Nodeos之后,它自然就会产生区块。
- keosd
    > 它的目的主要是管理钱包,可以创建私钥。

为什么分成Nodeos和Keosd?

Keosd可以认为是个轻客户端,因为有时候只需要进行钱包操作,不需要挖矿,就可以启动Keosd





<div class="se-preview-section-delimiter"></div>

#### 启动节点




<div class="se-preview-section-delimiter"></div>

./nodeos

或者




<div class="se-preview-section-delimiter"></div>

./nodeos -e -p eosio –plugin eosio::wallet_api_plugin –plugin eosio::chain_api_plugin –plugin eosio::account_history_api_plugin
““

启动nodeos

第一次启动,肯定是不会成功的,不过没有关系,困难有多少办法就有多少。

坑001
[root@localhost nodeos]# ./nodeos 
538093ms thread-0   chain_plugin.cpp:130          plugin_initialize    ] initializing chain plugin
538095ms thread-0   main.cpp:112                  main                 ] /home/duye/eos/libraries/chainbase/src/chainbase.cpp(106): Throw in function chainbase::database::database(const boost::filesystem::path&, chainbase::database::open_flags, uint64_t)
Dynamic exception type: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::runtime_error> >
std::exception::what: database dirty flag set (likely due to unclean shutdown) replay or resync required

解决办法:

./nodeos --resync

或者加载插件运行,根据自己的需求加载。

./nodeos -e -p eosio --plugin eosio::wallet_api_plugin --plugin eosio::chain_api_plugin --resync

指定数据目录和配置目录运行, 如果配置文件放在当前目录

./nodeos -e -p eosio --data-dir . --config-dir . --contracts-console --resync

配置

默认配置路径:~/.local/share
配置文件:~/.local/share/eosio/nodeos/config

配置:config.ini

# the endpoint upon which to listen for incoming connections (eosio::bnet_plugin)
bnet-endpoint = 0.0.0.0:4321

# the number of threads to use to process network messages (eosio::bnet_plugin)
# bnet-threads = 

# remote endpoint of other node to connect to; Use multiple bnet-connect options as needed to compose a network (eosio::bnet_plugin)
# bnet-connect = 

# this peer will request no pending transactions from other nodes (eosio::bnet_plugin)
bnet-no-trx = false

# the location of the blocks directory (absolute path or relative to application data dir) (eosio::chain_plugin)
blocks-dir = "blocks"

# Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints. (eosio::chain_plugin)
# checkpoint = 

# Override default WASM runtime (eosio::chain_plugin)
# wasm-runtime = 

# Maximum size (in MB) of the chain state database (eosio::chain_plugin)
chain-state-db-size-mb = 1024

# Maximum size (in MB) of the reversible blocks database (eosio::chain_plugin)
reversible-blocks-db-size-mb = 340

# print contract's output to console (eosio::chain_plugin)
contracts-console = false

# Account added to actor whitelist (may specify multiple times) (eosio::chain_plugin)
# actor-whitelist = 

# Account added to actor blacklist (may specify multiple times) (eosio::chain_plugin)
# actor-blacklist = 

# Contract account added to contract whitelist (may specify multiple times) (eosio::chain_plugin)
# contract-whitelist = 

# Contract account added to contract blacklist (may specify multiple times) (eosio::chain_plugin)
# contract-blacklist = 

# Track actions which match receiver:action:actor. Actor may be blank to include all. Receiver and Action may not be blank. (eosio::history_plugin)
# filter-on = 

# PEM encoded trusted root certificate (or path to file containing one) used to validate any TLS connections made.  (may specify multiple times)
#  (eosio::http_client_plugin)
# https-client-root-cert = 

# true: validate that the peer certificates are valid and trusted, false: ignore cert errors (eosio::http_client_plugin)
https-client-validate-peers = 1

# The local IP and port to listen for incoming http connections; set blank to disable. (eosio::http_plugin)
http-server-address = 127.0.0.1:8888

# The local IP and port to listen for incoming https connections; leave blank to disable. (eosio::http_plugin)
# https-server-address = 127.0.0.1:8888

# Filename with the certificate chain to present on https connections. PEM format. Required for https. (eosio::http_plugin)
# https-certificate-chain-file = 

# Filename with https private key in PEM format. Required for https (eosio::http_plugin)
# https-private-key-file = 

# Specify the Access-Control-Allow-Origin to be returned on each request. (eosio::http_plugin)
# access-control-allow-origin = 

# Specify the Access-Control-Allow-Headers to be returned on each request. (eosio::http_plugin)
# access-control-allow-headers = 

# Specify the Access-Control-Max-Age to be returned on each request. (eosio::http_plugin)
# access-control-max-age = 

# Specify if Access-Control-Allow-Credentials: true should be returned on each request. (eosio::http_plugin)
access-control-allow-credentials = false

# The actual host:port used to listen for incoming p2p connections. (eosio::net_plugin)
p2p-listen-endpoint = 0.0.0.0:9876

# An externally accessible host:port for identifying this node. Defaults to p2p-listen-endpoint. (eosio::net_plugin)
# p2p-server-address = 

# The public endpoint of a peer node to connect to. Use multiple p2p-peer-address options as needed to compose a network. (eosio::net_plugin)
# p2p-peer-address = 

# Maximum number of client0nodes from any single IP address (eosio::net_plugin)
p2p-max-nodes-per-host = 1

# The name supplied to identify this node amongst the peers. (eosio::net_plugin)
agent-name = "EOS Test Agent"

# Can be 'any' or 'producers' or 'specified' or 'none'. If 'specified', peer-key must be specified at least once. If only 'producers', peer-key is not required. 'producers' and 'specified' may be combined. (eosio::net_plugin)
allowed-connection = any

# Optional public key of peer allowed to connect.  May be used multiple times. (eosio::net_plugin)
# peer-key = 

# Tuple of [PublicKey, WIF private key] (may specify multiple times) (eosio::net_plugin)
# peer-private-key = 

# Maximum number of clients from which connections are accepted, use 0 for no limit (eosio::net_plugin)
max-clients = 25

# number of seconds to wait before cleaning up dead connections (eosio::net_plugin)
connection-cleanup-period = 30

# True to require exact match of peer network version. (eosio::net_plugin)
network-version-match = 0

# number of blocks to retrieve in a chunk from any individual peer during synchronization (eosio::net_plugin)
sync-fetch-span = 100

# maximum sizes of transaction or block messages that are sent without first sending a notice (eosio::net_plugin)
max-implicit-request = 1500

# Enable block production, even if the chain is stale. (eosio::producer_plugin)
enable-stale-production = true 

# Start this node in a state where production is paused (eosio::producer_plugin)
pause-on-startup = false

# Limits the maximum time (in milliseconds) that is allowed a pushed transaction's code to execute before being considered invalid (eosio::producer_plugin)
max-transaction-time = 30

# Limits the maximum age (in seconds) of the DPOS Irreversible Block for a chain this node will produce blocks on (use negative value to indicate unlimited) (eosio::producer_plugin)
max-irreversible-block-age = -1

# ID of producer controlled by this node (e.g. inita; may specify multiple times) (eosio::producer_plugin)
producer-name = eosio

# (DEPRECATED - Use signature-provider instead) Tuple of [public key, WIF private key] (may specify multiple times) (eosio::producer_plugin)
# private-key = 

# Key=Value pairs in the form <public-key>=<provider-spec>
# Where:
#    <public-key>       is a string form of a vaild EOSIO public key
# 
#    <provider-spec>    is a string in the form <provider-type>:<data>
# 
#    <provider-type>    is KEY, or KEOSD
# 
#    KEY:<data>         is a string form of a valid EOSIO private key which maps to the provided public key
# 
#    KEOSD:<data>       is the URL where keosd is available and the approptiate wallet(s) are unlocked (eosio::producer_plugin)
signature-provider = EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

# Limits the maximum time (in milliseconds) that is allowd for sending blocks to a keosd provider for signing (eosio::producer_plugin)
keosd-provider-timeout = 5

# Lag in number of blocks from the head block when selecting the reference block for transactions (-1 means Last Irreversible Block) (eosio::txn_test_gen_plugin)
txn-reference-block-lag = 0

# The path of the wallet files (absolute path or relative to application data dir) (eosio::wallet_plugin)
wallet-dir = "."

# Timeout for unlocked wallet in seconds (default 900 (15 minutes)). Wallets will automatically lock after specified number of seconds of inactivity. Activity is defined as any wallet command e.g. list-wallets. (eosio::wallet_plugin)
unlock-timeout = 900

# eosio key that will be imported automatically when a wallet is created. (eosio::wallet_plugin)
# eosio-key = 

# Plugin(s) to enable, may be specified multiple times
# plugin = 
plugin = eosio::producer_plugin
plugin = eosio::chain_api_plugin
plugin = eosio::wallet_api_plugin
plugin = eosio::http_plugin
#plugin = eosio::account_history_api_plugin
#plugin = eosio::mongo_db_plugin

配置:genesis.json

{
  "initial_timestamp": "2018-03-02T12:00:00.000",
  "initial_key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
  "initial_configuration": {
    "max_block_net_usage": 1048576,
    "target_block_net_usage_pct": 1000,
    "max_transaction_net_usage": 524288,
    "base_per_transaction_net_usage": 12,
    "net_usage_leeway": 500,
    "context_free_discount_net_usage_num": 20,
    "context_free_discount_net_usage_den": 100,
    "max_block_cpu_usage": 100000,
    "target_block_cpu_usage_pct": 500,
    "max_transaction_cpu_usage": 50000,
    "min_transaction_cpu_usage": 100,
    "max_transaction_lifetime": 3600,
    "deferred_trx_expiration_window": 600,
    "max_transaction_delay": 3888000,
    "max_inline_action_size": 4096,
    "max_inline_action_depth": 4,
    "max_authority_depth": 6,
    "max_generated_transaction_count": 16
  },
  "initial_chain_id": "0000000000000000000000000000000000000000000000000000000000000000"
}

数据目录

~/.local/share/eosio/nodeos/data

不带参数启动

./nodeos --resync

–resync: 重新加载配置

启动钱包

钱包配置,默认在 ~/eosio-wallet/config.ini

# The local IP and port to listen for incoming http connections; set blank to disable. (eosio::http_plugin)
http-server-address = 0.0.0.0:80

# The local IP and port to listen for incoming https connections; leave blank to disable. (eosio::http_plugin)
https-server-address = 0.0.0.0:443

# Filename with the certificate chain to present on https connections. PEM format. Required for https. (eosio::http_plugin)
https-certificate-chain-file = ./key/server-cert.pem

# Filename with https private key in PEM format. Required for https (eosio::http_plugin)
https-private-key-file = ./key/server-key.pem

# Specify the Access-Control-Allow-Origin to be returned on each request. (eosio::http_plugin)
# access-control-allow-origin = 

# Specify the Access-Control-Allow-Headers to be returned on each request. (eosio::http_plugin)
# access-control-allow-headers = 

# Specify if Access-Control-Allow-Credentials: true should be returned on each request. (eosio::http_plugin)
access-control-allow-credentials = false

# The path of the wallet files (absolute path or relative to application data dir) (eosio::wallet_plugin)
wallet-dir = "."

# Timeout for unlocked wallet in seconds (default 900 (15 minutes)). Wallets will automatically lock after specified number of seconds of inactivity. Activity is defined as any wallet command e.g. list-wallets. (eosio::wallet_plugin)
unlock-timeout = 900

# eosio key that will be imported automatically when a wallet is created. (eosio::wallet_plugin)
# eosio-key = 

# Plugin(s) to enable, may be specified multiple times
# plugin = 

启动:

# ./keosd
1241613ms thread-0   wallet_plugin.cpp:41          plugin_initialize    ] initializing wallet plugin
1241613ms thread-0   http_plugin.cpp:264           plugin_initialize    ] configured http to listen on 0.0.0.0:80
1241613ms thread-0   http_plugin.cpp:286           plugin_initialize    ] configured https to listen on 0.0.0.0:443 (TLS configuration will be validated momentarily)
1241613ms thread-0   wallet_api_plugin.cpp:112     plugin_initialize    ] 
*************************************
*                                   *
*  --   Wallet NOT on localhost  -- *
*  - Password and/or Private Keys - *
*  - are transferred unencrypted. - *
*                                   *
*************************************

1241613ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/keosd/stop
1241613ms thread-0   http_plugin.cpp:302           plugin_startup       ] start listening for http requests
1241613ms thread-0   http_plugin.cpp:321           plugin_startup       ] start listening for https requests
1241617ms thread-0   wallet_api_plugin.cpp:68      plugin_startup       ] starting wallet_api_plugin
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/create
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/create_key
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/get_public_keys
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/import_key
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/list_keys
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/list_wallets
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/lock
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/lock_all
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/open
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/set_timeout
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/sign_transaction
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/unlock

有兴趣的朋友,请关注微信公众号,有机会获取平台代币:
Daozy社区公众号

进入社区贡献者微信群,有机会获取平台代币:
Daozy社区贡献者群

# ./keosd
1241613ms thread-0   wallet_plugin.cpp:41          plugin_initialize    ] initializing wallet plugin
1241613ms thread-0   http_plugin.cpp:264           plugin_initialize    ] configured http to listen on 0.0.0.0:80
1241613ms thread-0   http_plugin.cpp:286           plugin_initialize    ] configured https to listen on 0.0.0.0:443 (TLS configuration will be validated momentarily)
1241613ms thread-0   wallet_api_plugin.cpp:112     plugin_initialize    ] 
*************************************
*                                   *
*  --   Wallet NOT on localhost  -- *
*  - Password and/or Private Keys - *
*  - are transferred unencrypted. - *
*                                   *
*************************************

1241613ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/keosd/stop
1241613ms thread-0   http_plugin.cpp:302           plugin_startup       ] start listening for http requests
1241613ms thread-0   http_plugin.cpp:321           plugin_startup       ] start listening for https requests
1241617ms thread-0   wallet_api_plugin.cpp:68      plugin_startup       ] starting wallet_api_plugin
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/create
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/create_key
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/get_public_keys
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/import_key
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/list_keys
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/list_wallets
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/lock
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/lock_all
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/open
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/set_timeout
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/sign_transaction
1241617ms thread-0   http_plugin.cpp:342           add_handler          ] add api url: /v1/wallet/unlock

有兴趣的朋友,请关注微信公众号,有机会获取平台代币:
Daozy社区公众号

进入社区开发者群微信群,有机会获取平台代币:
Daozy开发者群

进入社区贡献者微信群,有机会获取平台代币:
Daozy社区贡献者群

版权声明:本文为tencupofkaiwater原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/tencupofkaiwater/article/details/80757817

智能推荐

SpringBoot 使用freemarker 处理文档,找不到文件位置(报错:basePackagePath=““ /* relatively to resourceLoaderClass pkg)

在Spring Boot中加载word的文档的时候,加载ftl文档的位置应该是从 target目录下面去加载的(不太确定),不是像大多数情况这样根据类的路径去加载。SpringBoot加载的位置应该是从 “resources”文件下面开始,如果放到“resources”的根目录下面需要加一道“/”斜线。 类似于: config...

剑指offer 合并两个排序的链表

题目 链接:https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/ 思路 我想的是,与合并两个有序数组一样的思维,新建一个链表,然后判断谁的值大,进而在新的链表上面进行插入。 看书思路 合并链表是一个递归问题:合并一个节点后可以转化为一个子问题。终止条件是其中一个链表为空 代码 链表反转也可以用递归解决...

Java编程思想 第三章:操作符

Java中的操作符和c/c++中的操作符基本一致,因为我之前学习过C语言和C++,所以本章的内容大部分都已熟知,下面只做简单的介绍。 Java操作符及优先级 Java中的操作符包括算术操作符,关系操作符,逻辑操作符,位运算符、自操作运算符、移位运算符、赋值运算符和其他运算符。 算术操作符:包括加减乘除和取余(%),优先级乘除取余高于加减,都是双元运算符,其中加法(+)可以用来连接两个字符串,比如:...

JetBrains 系列开发工具,如何配置 `SCSS` `File Watcher` ,相关输出配置参数详解:webStorm phpStorm IDEA

JetBrains 系列开发工具,如何配置 SCSS File Watcher ,相关输出配置参数详解:webStorm phpStorm IDEA 前言 你目前已经了解了如何使用 SCSS 进行开发,了解了该文章的内容:『 SCSS 日常用法 』 在 JetBrains 系列开发工具中通过 FileWatcher 进行编译的 SCSS 文件都是通过 sass 这个程序进行的。『 如何添加 Fil...

C语言小函数—二进制与十六进制

测试如下 “` int main() { long int num = 15; } “`...

猜你喜欢

仿微博或微信的文章多图显示(自定义MultiImageView)

按照一般的规矩,先上张图来供大伙看看 如果大致是大伙们需要实现的功能,不烦一观 自定义MultiImageView 工具类 具体使用 app.gradle中添加依赖 implementation 'com.github.bumptech.glide:glide:4.8.0' AndroidManifest.xml中配置联网权限 <uses-permission android:name=&q...

经典进程同步和互斥问题

经典进程同步与互斥问题 前言 一、生产者-消费者问题 1.问题描述 2.问题分析 3.代码 二、读者-写者问题 1.问题描述&&分析 2.代码 三、哲学家进餐问题 1.问题描述&&分析 2.代码 四、理发师问题 1.问题描述&&分析 2.代码 前言 在多道程序设计环境中,进程同步是一个非常重要的问题,下面讨论几个经典的进程同步问题。 一、生产者-消费...

java设计模式——ThreadLocal线程单例

1、定义一个ThreadLocal线程单例,代码如下: 2、定义一个多线程类,代码如下: 3、定义一个测试类,代码如下: 4、输出结果,如下图:...

【tensorflow】线性模型实战

线性模型:y = 1.477 * x + 0.089   1. 采样数据 采样噪声eps在均值0,方差0.01的高斯分布中,而后在均匀分布U(0,1)中,区间[-10,10]进行n=100次随机采样:   2. 计算误差 循环计算每个点的预测值与真是值之间差的平方并累加,从而获得训练集上的均芳误差损失值。   3. 计算梯度   4. 梯度更新 对权重w和偏...

常见损失函数和评价指标总结(附公式&代码)

网上看到一篇很实用的帖子关于常见损失函数和评价指标,收藏下来 本文转载于https://zhuanlan.zhihu.com/p/91511706 ------------------------------------------------------------------------------------------------------------------------------...