In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use Visual Studio Code and CLion for EOS development". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use Visual Studio Code and CLion for EOS development".
Set up Visual Studio Code
First, if you don't already have these VS Code extensions, install them. For EOS Dapp development, they will be very helpful:
IntelliSense, debugging, and code browsing of Candlestick +-VS Code
CMake language support for CMake-Visual Studio Code
CMake Tools-Visual Studio Code extended CMake support
WebAssembly-syntax highlighting for WebAssembly text representation
When we develop EOSIO dApps, we need to write code in .hpp and .cpp files. However, this is a small part of the whole process. Most of the time, we need to generate other files that will be used to deploy contracts on the blockchain, unit tests, and so on. This is where CMake is useful.
CMake is a command-line tool used to control the software compilation process. Once it is set up correctly in your IDE, it will make the whole development process easier.
Since we are going to use the CMake tool, we should make some changes to our project structure. We will reuse the architecture of the EOSIO project because it has everything we need. Of course, we have some small changes.
We have a picture showing the new project structure. Let's have a look.
First, we have the build folder. This is where all the build content is placed. Every build file you use is there. Next is CMakeModules, which contains some useful Cmake modules that are customized for the compilation process.
Contracts is our core folder. This is where we put the smart contract. Currently, eosiolib, libc++, and musl are stored here by default for compilation. Then came externals and libraries. Both folders contain libraries that make the entire compilation process easier.
The last important thing in the project structure is the configuration file CMakeLists.txt. Each directory has its own CMakeLists.txt file with commands.
You can find the new project structure for all the folders and scripts in our repo.
CMakeLists
Let's look at some configuration files because you need to know how to use them.
1.CMakeLists.txt (4)
This is the main configuration file that sets up the compilation process. You should know that when you develop Dapp, you need to set the project name. Version and language are optional.
# Set the minimum required version of cmake for a projectcmake_minimum_required (VERSION 3.5) # Set a name, version, and enable languages for the entire project.project (ProjectName) list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} / libraries/fc/CMakeModules") list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} / CMakeModules") # Load and run CMake code from a file or module.include (GNUInstallDirs) include (SetupTargetMacros) # Set a normal, cache Or environment variable to a given valueset (CMAKE_CXX_STANDARD 14) set (CMAKE_CXX_EXTENSIONS ON) set (CXX_STANDARD_REQUIRED ON) set (CLI_CLIENT_EXECUTABLE_NAME cleos) set (GUI_CLIENT_EXECUTABLE_NAME eosio) set (CMAKE_EXPORT_COMPILE_COMMANDS "ON") # add defaults for opensslif ("${OPENSSL_ROOT_DIR}" STREQUAL "") if (NOT "$ENV {OPENSSL_ROOT_DIR}" STREQUAL "") set (OPENSSL_ROOT_DIR $ENV {OPENSSL_ ROOT_DIR}) set (OPENSSL_INCLUDE_DIR ${OPENSSL_ROOT_DIR} / include) elseif (APPLE) set (OPENSSL_ROOT_DIR "/ usr/local/opt/openssl") set (OPENSSL_INCLUDE_DIR "/ usr/local/opt/openssl/include") elseif (UNIX AND NOT APPLE) set (OPENSSL_ROOT_DIR "/ usr/include/openssl") set (OPENSSL_INCLUDE_DIR "/ usr/include/openssl/ Include ") else () message (FATAL_ERROR" openssl not found and don't know where to look Please specify OPENSSL_ROOT_DIR ") endif () endif () if (UNIX) if (APPLE) set (whole_archive_flag"-force_load ") set (no_whole_archive_flag") else () set (whole_archive_flag"-whole-archive ") set (no_whole_archive_flag"-no-whole-archive ") endif () else () set (whole_archive_flag"-whole-archive ") Set (no_whole_archive_flag "--no-whole-archive") endif () SET (Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF") IF (WIN32) SET (BOOST_ROOT $ENV {BOOST_ROOT}) set (Boost_USE_MULTITHREADED ON) set (BOOST_ALL_DYN_LINK OFF) # force dynamic linking for all librariesENDIF (WIN32) FIND_PACKAGE Chrono unit_test_framework context locale iostreams) # Add a subdirectory to the build.add_subdirectory (externals) include (wasm) add_subdirectory (libraries) add_subdirectory (contracts)
2.CMakeLists.txt (3)
The second configuration file is in the contracts folder. Each new smart contract should be added as a subdirectory in this configuration. It is important not to forget that the contract will not be compiled. CMake doesn't know.
Set (DEFAULT_SYSTEM_INCLUDE_FOLDERS ${CMAKE_SOURCE_DIR} / contracts/libc++/upstream/include ${CMAKE_SOURCE_DIR} / contracts/musl/upstream/include ${Boost_INCLUDE_DIR}) set (STANDARD_INCLUDE_FOLDERS ${CMAKE_SOURCE_DIR} / contracts ${CMAKE_SOURCE_DIR} / externals/magic_get/include) add_subdirectory (eosiolib) add_subdirectory (musl) add_subdirectory (libc++) # Your contracts (add the name of the folder which contains you smart contract) add_subdirectory (Players)
3.CMakeLists.txt (2)
Each smart contract has its own profile. It is important to note that each contract has a different TARGET, which in most cases is the name of the folder.
File (GLOB ABI_FILES "* .abi") configure_file ("${ABI_FILES}"${CMAKE_CURRENT_BINARY_DIR}" COPYONLY) # Change "Players" with the name of the folder containing your smart contractsadd_wast_executable (TARGET Players INCLUDE_FOLDERS "${STANDARD_INCLUDE_FOLDERS}" LIBRARIES libc libc++ eosiolib DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR})
Now, when we have a new project structure, we have to customize the commands to compile and build everything we do. But how do we start? Fortunately, VS Code has some cool things called Tasks. It helps us automate each command with just a few clicks.
Tasks of VS Code
First, we must generate a tasks.json file that contains our custom commands. Press ⇧ + ⌘ + P to open command palette in the VS code, then type "Tasks" and select "Configure Task".
Then select Create tasks.json file from template in the next step, and then Others:
VS code will create a folder called ".vscode" where you can find tasks.json. Now we need to add commands. Copy and paste the following code to tasks.json:
{"version": "2.0.0", "reveal": "always", "options": {"cwd": "${workspaceRoot}"}, "tasks": [{"label": "CMake", "type": "shell", "command": "sh ${workspaceRoot} / .vscode / scripts/compile.sh"} {"label": "Build", "type": "shell", "command": "sh ${workspaceRoot} / .vscode / scripts/build.sh"}, {"label": "Generate ABI", "type": "shell" "command": "sh ${workspaceRoot} / .vscode/scripts/generate.sh ${fileDirname} ${fileBasenameNoExtension}",}]}
We have created three custom commands named CMake, Build, and Generate ABI. They execute three shell scripts, compile.sh,build.sh and generate.sh. The first two scripts are basically the same, except that build.sh is also compiled. Maybe you use the second one most of the time.
Compile.sh
# Create a build folder if it doesn't existmkdir-p build# Change the current directory to "build" cd build# Create all the build files neededcmake-G 'Unix Makefiles'-DCMAKE_BUILD_TYPE=Debug.
Build.sh
# Create a build folder if it doesn't existmkdir-p build# Change the current directory to "build" cd build# Create all the build files neededcmake-G 'Unix Makefiles'-DCMAKE_BUILD_TYPE=Debug. # Buildmake
On the other hand, use the third script, generate.sh (to generate the smart contract ABI). Some files need to be generated during the build process. The order must be executed in the contract folder. Select a .cpp file and run it.
Generate.sh
Echo "Current working directory -" $1cd $1eosiocpp-g $2.abi $2.cpp
Amazing! We're ready, VS Code. To make the whole development easier, we will create shortcuts for our commands. While you are still in the VS code, click Preferences-Keyboard Shortcuts. The shortcut window finds and opens keybindings.json (which is at the top):
Once keybindings.json is open, we will create a shortcut. For our commands, we chose cmd+e, cmd+r, and cmd+i, but you can choose others. This is the json you must add:
Once you have completed all the settings, you are now ready to develop EOS DApps on VS Code.
CLion Settin
Compared with VS Code, setting up CLion is very simple. When you load a schema in CLion, IDE automatically creates all generated files in the cmake-build-debug folder. Once you are ready, you can use the "⌘ + F9" shortcut to perform the actual build. That's all you need to do, isn't it too easy?
However, if you want to set additional items for CMake, you can choose from Preferences-Build, Execution, Deployment.
Thank you for reading, the above is the content of "how to use Visual Studio Code and CLion for EOS development". After the study of this article, I believe you have a deeper understanding of how to use Visual Studio Code and CLion for EOS development, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.