Emscripten installation and configuration environment variables

Preface

Emscripten official website

There is an installation tutorial on the official website, but some details are not clearly explained. This article will explain each step in detail.

1. Download the emsdk package

emsdk – github address

You can use gitto pull, but the pull may fail due to timeout.

git clone https://github.com/emscripten-core/emsdk.git

So you can githubdownload zipthe package from . After decompression emsdk-main, you can change the package name manually emsdk. After decompression, you can put the package in the root directory of drive D. You can also place it anywhere else. There is no requirement. This article will introduce how to put it in the root directory of drive D. .

Insert image description here

2. Installation

1. Enter the command in the terminal to enter the emsdk folder

Open the terminal, you can use windows + REnter cmdto open, enter D:Enter, and then enter cd emsdkthe emsdk folder.

Insert image description here
Insert image description here

2. Install Python

Python must be installed first. Emscripten operation depends on the Python environment, and the Python version must be greater than 3.6.

Python official website download address

Insert image description here
After the download is complete, double-click to install and follow the steps below.

  1. Choose to add environment variables automatically and then install
    Insert image description here

  2. Next step

  3. Select these 5, usually the first 5
    Insert image description here

  4. No path length limit set
    Insert image description here

  5. Enter in the terminal to confirm whether Python is installed successfully. If the version number is displayed, it means the installation is successful.
    Insert image description here

3. Enter the command to complete the configuration.

first step

Enter ./emsdk install latestthe command, if it is a windows system, enter emsdk install latestthe command. If the installation fails, reinstall it. The network may fail if the network is not good.

Insert image description here

Step 2

Enter ./emsdk activate latestthe command, if it is a windows system, enter emsdk activate latestthe command. The error message here indicates that you need to install the Python-3.9-2-nuget-64bit version, so don't worry about it.

Insert image description here

The third step
is to enter source ./emsdk_env.shthe command. If it is a windows system, enter emsdk_env.batthe command. After entering this command, you will be prompted to configure the corresponding environment variables. Remember that these environment variables must be consistent with the configuration prompted.

Insert image description here

3. Configure environment variables

Setting up EMSDK environment (suppress these messages with EMSDK_QUIET=1)
Adding directories to PATH:
PATH += D:\emsdk

Setting environment variables:
PATH = D:\emsdk;C:\Program Files\Python311\Scripts\;C:\Program Files\Python311\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\nodejs\;C:\Program Files (x86)\Tencent\微信web开发者工具\dll;;C:\Pr;gram Files\Git\cmd;C:\Program Files\Git\cmd;C:\Users\mr_zx\AppData\Local\Microsoft\WindowsApps;C:\Users\mr_zx\AppData\Roaming\npm;C:\Users\mr_zx\AppData\Local\Programs\Microsoft VS Code\bin
EMSDK = D:/emsdk
Clearing existing environment variable: EMSDK_PY

Because the version and system are inconsistent, if you enter the same command, the environment variables to be configured may not be exactly the same. You need to configure them according to the prompts after entering the command. The following pictures are for reference only.

pathThe variable already exists, you just need to add it to it.
Insert image description here
Insert image description here

Insert image description here
Insert image description here

After the configuration is completed, enter emcc to test whether the configuration is successful. If "'emcc' is not an internal or external command, nor is it an operable program" is displayed, the configuration is successful.

Insert image description here

at last

At this point Emscripten, the installation has been successfully completed. After configuring PATH, you can call this command globally. Next, you can compile the C code into JS and wasm files.

This article only explains the installation process of Emscripten. Regarding the compilation process and how to use JS files after compilation, due to space limitations, another blog will be updated later to describe in detail.

END

Guess you like

Origin blog.csdn.net/m0_53808238/article/details/132702461