WebAssembly002 emcc install + 解决 Error: Downloading URL ‘https://storage.googleapis.com/…‘ error

本文主要是介绍WebAssembly002 emcc install + 解决 Error: Downloading URL ‘https://storage.googleapis.com/…‘ error,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

安装教程

// https://developer.mozilla.org/zh-CN/docs/WebAssembly/C_to_Wasm
git clone https://github.com/juj/emsdk.git
cd emsdk# 在 Linux 或者 Mac macOS 上
./emsdk install --build=Release sdk-incoming-64bit binaryen-master-64bit
./emsdk activate --global --build=Release sdk-incoming-64bit binaryen-master-64bit
# 如果在你的 macos 上获得以下错误
Error: No tool or SDK found by name 'sdk-incoming-64bit'
# 请执行
./emsdk install latest
# 按照提示配置环境变量即可
./emsdk activate latest# 在 Windows 上
emsdk install --build=Release sdk-incoming-64bit binaryen-master-64bit
emsdk activate --global --build=Release sdk-incoming-64bit binaryen-master-64bit# 注意:Windows 版本的 Visual Studio 2017 已经被支持,但需要在 emsdk install 需要追加 --vs2017 参数。

Error: Downloading URL ‘https://storage.googleapis.com/webassembly/emscripten-releases-builds/deps/node-v16.20.0-linux-x64.tar.xz’: <urlopen error [Errno 104] Connection reset by peer> error: installation failed!

$:~/Downloads$ git clone https://github.com/juj/emsdk.git
正克隆到 'emsdk'...
remote: Enumerating objects: 3754, done.
remote: Counting objects: 100% (644/644), done.
remote: Compressing objects: 100% (106/106), done.
remote: Total 3754 (delta 560), reused 595 (delta 533), pack-reused 3110
接收对象中: 100% (3754/3754), 2.18 MiB | 690.00 KiB/s, 完成.
处理 delta 中: 100% (2475/2475), 完成.
$:~/Downloads$ cd emsdk
$:~/Downloads/emsdk$ ./emsdk install --build=Release sdk-incoming-64bit binaryen-master-64bit
error: tool or SDK not found: 'sdk-incoming-64bit'
$:~/Downloads/emsdk$ ./emsdk install latest
Resolving SDK alias 'latest' to '3.1.44'
Resolving SDK version '3.1.44' to 'sdk-releases-b90507fcf011da61bacfca613569d882f7749552-64bit'
Installing SDK 'sdk-releases-b90507fcf011da61bacfca613569d882f7749552-64bit'..
Installing tool 'node-16.20.0-64bit'..
Error: Downloading URL 'https://storage.googleapis.com/webassembly/emscripten-releases-builds/deps/node-v16.20.0-linux-x64.tar.xz': <urlopen error [Errno 104] Connection reset by peer>
error: installation failed!
  • 只能查看emsdk.py,查找文件下载调用的流程,在浏览器下载后放置在安装目录
    在这里插入图片描述
------------------------------------------------------------------------------------------------------------------------------------------------
https://storage.googleapis.com/webassembly/emscripten-releases-builds/deps/node-v16.20.0-linux-x64.tar.xz
downloads/------------------------------------------------------------------------------------------------------------------------------------------------
  • 发现直接放入不起作用,每次运行时会清空文件夹
> /home/pdd/Downloads/emsdk/emsdk.py(679)download_file()
-> print("="*300)
(Pdb) p download_even_if_exists
True
  • 最终修改代码如下:
def download_and_extract(archive, dest_dir, filename_prefix='', clobber=True):debug_print('download_and_extract(archive=' + archive + ', dest_dir=' + dest_dir + ')')url = urljoin(emsdk_packages_url, archive)download_target = get_download_target(url, download_dir, filename_prefix)print("-"*300)print(url)print(download_dir)print(KEEP_DOWNLOADS)print(filename_prefix)print("-"*300)# received_download_target = download_file(url, download_dir, not KEEP_DOWNLOADS, filename_prefix)received_download_target = download_file(url, download_dir, False, filename_prefix)if not received_download_target:return Falseassert received_download_target == download_target# Remove the old directory, since we have some SDKs that install into the# same directory.  If we didn't do this contents of the previous install# could remain.if clobber:remove_tree(dest_dir)if archive.endswith('.zip'):return unzip(download_target, dest_dir)else:return untargz(download_target, dest_dir)
  • 注:下载需要依赖个各个文件时,有可能浏览器下载得到的和需要的文件名称有所差别,按照要求修改即可
$:~/Downloads/emsdk$ ./emsdk install latest
Resolving SDK alias 'latest' to '3.1.44'
Resolving SDK version '3.1.44' to 'sdk-releases-b90507fcf011da61bacfca613569d882f7749552-64bit'
Installing SDK 'sdk-releases-b90507fcf011da61bacfca613569d882f7749552-64bit'..
Skipped installing node-16.20.0-64bit, already installed.
Skipped installing releases-b90507fcf011da61bacfca613569d882f7749552-64bit, already installed.
All SDK components already installed: 'sdk-releases-b90507fcf011da61bacfca613569d882f7749552-64bit'.
$:~/Downloads/emsdk$ ./emsdk activate latest
Resolving SDK alias 'latest' to '3.1.44'
Resolving SDK version '3.1.44' to 'sdk-releases-b90507fcf011da61bacfca613569d882f7749552-64bit'
Setting the following tools as active:node-16.20.0-64bitreleases-b90507fcf011da61bacfca613569d882f7749552-64bitNext steps:
- To conveniently access emsdk tools from the command line,consider adding the following directories to your PATH:/home/pdd/Downloads/emsdk/home/pdd/Downloads/emsdk/upstream/emscripten
- This can be done for the current shell by running:source "/home/pdd/Downloads/emsdk/emsdk_env.sh"
- Configure emsdk in your shell startup scripts by running:echo 'source "/home/pdd/Downloads/emsdk/emsdk_env.sh"' >> $HOME/.bash_profile
(base) pdd@pdd-Dell-G15-5511:~/Downloads/emsdk$ source ./emsdk_env.sh
Setting up EMSDK environment (suppress these messages with EMSDK_QUIET=1)
Adding directories to PATH:
PATH += /home/pdd/Downloads/emsdk
PATH += /home/pdd/Downloads/emsdk/upstream/emscriptenSetting environment variables:
PATH = /home/pdd/Downloads/emsdk:/home/pdd/Downloads/emsdk/upstream/emscripten:/home/pdd/Downloads/video_rtsp/ffmpeg-master-latest-linux64-lgpl/bin:/usr/local/mpich-4.1/bin:/usr/local/cuda-11.4/bin:/home/pdd/anaconda3/bin:/home/pdd/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/pdd/Documents/node-v20.5.0-linux-x64/bin
EMSDK = /home/pdd/Downloads/emsdk
EMSDK_NODE = /home/pdd/Downloads/emsdk/node/16.20.0_64bit/bin/node

测试

$:~/Downloads/emsdk$ emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.44 (bec42dac7873903d09d713963e34020c22a8bd2d)
clang version 17.0.0 (https://github.com/llvm/llvm-project a8cbd27d1f238e104a5d5ca345d93bc1f4d4ab1f)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/pdd/Downloads/emsdk/upstream/bin
#include <iostream>
using namespace std;bool IsBigEndian()  
{  int a = 0x1234;  char b =  *(char *)&a;  //通过将int强制类型转换成char单字节,即等于 取b等于a的低地址部分  if( b == 0x12)  {  cout<< "big end"; return true; }  cout<< "small end"; return false;  
}int main(){cout<<  IsBigEndian();return 0;
}
  • emcc test.cpp -s WASM=1 -o hello.html
$:/home/user$ emcc test.cpp -s WASM=1 -o hello.html
shared:INFO: (Emscripten: Running sanity checks)
cache:INFO: generating system asset: symbol_lists/7a974f7065b03f039b58c3afd6b04fb646712f63.json... (this will be cached in "/home/pdd/Downloads/emsdk/upstream/emscripten/cache/symbol_lists/7a974f7065b03f039b58c3afd6b04fb646712f63.json" for subsequent builds)
cache:INFO:  - ok
$:/home/user$ ls
hello.html  hello.js  hello.wasm  test.cpp
  • 上边的代码不能正常展示,先简单测试一下
// test.c
#include <stdio.h>int main() {printf("hello\n");return 0;
}
$:/home/user$ python -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

在这里插入图片描述

emcc( 替代gcc)

  • https://emscripten.org/docs/tools_reference/emcc.html
示例解释
-o <target>[链接] 链接可执行文件时,target文件扩展名定义要生成的输出类型
-Iinclude头文件
-L链接放在/lib和/usr/lib和/usr/local/lib里的库
-l链接具体的静态库、动态库
-c[compile] 告诉emcc生成一个目标文件,然后该目标文件可以与其他目标文件链接以生成可执行文件。
--preload-file <name>[链接] 指定在异步运行编译代码之前预加载的文件。该路径是相对于编译时当前目录的。如果在此处传递目录,则其全部内容将被嵌入。预加载的文件存储在filename.data中,其中filename.html是您要编译到的主文件。要运行代码,您将需要.html和.data。
-sOPTION[=VALUE][不同的选项影响不同的阶段,大多数在链接时] Emscripten 构建选项。有关可用选项,请参阅src/settings.js
-sASSERTIONSUncaught RuntimeError: Aborted(Assertion failed: false, at: /home/pdd/***/76/ggml.c,4542,ggml_new_object). Build with -sASSERTIONS for more info.
-sALLOW_MEMORY_GROWTHAborted(Cannot enlarge memory arrays to size 106745856 bytes (OOM). Either (1) compile with -sINITIAL_MEMORY=X with X higher than the current value 16777216, (2) compile with -sALLOW_MEMORY_GROWTH which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -sABORTING_MALLOC=0)
  • emcc -I../../include -I../../include/ggml -I../../examples ../../src/ggml.c main.cpp -o web/mnist.js -s EXPORTED_FUNCTIONS='["_wasm_eval","_wasm_random_digit","_malloc","_free"]' -s EXPORTED_RUNTIME_METHODS='["ccall"]' -s ALLOW_MEMORY_GROWTH=1 --preload-file models/mnist

  • Emscripten教程之emcc编译命令

  • 注: 优化指令对效果的影响较大,如下为同一个矩阵乘法的速度对比
    在这里插入图片描述

emmake( 替代cmake)

  • https://emscripten.org/docs/compiling/Building-Projects.html
  • https://www.infoq.cn/article/F6aI8wuLYiJ4B3CO7Lvf
  • 首先我们从 Github 中找到 cJSON 的主页,然后下载相关的源码放置在我们项目的 vendor 文件夹中。接着我们在当前项目的根目录下创建一个CMakeList.txt文件,并填入如下内容:
cmake_minimum_required(VERSION 3.15) # 根据你的需求进行修改
project(sample C)set(CMAKE_C_STANDARD 11) # 根据你的C编译器支持情况进行修改
set(CMAKE_EXECUTABLE_SUFFIX ".html") # 编译生成.htmlinclude_directories(vendor) # 使得我们能引用第三方库的头文件
add_subdirectory(vendor/cJSON)add_executable(sample main.c)# 设置Emscripten的编译链接参数,我们等等会讲到一些常用参数set_target_properties(sample PROPERTIES LINK_FLAGS "-s EXIT_RUNTIME=1")
target_link_libraries(sample cjson) # 将第三方库与主程序进行链接
  • 在让我们在代码中引入 cJSON 然后并使用它进行 JSON 的解析操作,代码如下:
#include <stdio.h>
#include "cJSON/cJSON.h"int main() {const char jsonstr[] = "{\"data\":\"Hello World!\"}";cJSON *json = cJSON_Parse(jsonstr);const cJSON *data = cJSON_GetObjectItem(json, "data");printf("%s\n", cJSON_GetStringValue(data));cJSON_Delete(json);return 0;
}
> mkdir build
> cd build
> emcmake cmake ..
> emmake make

这篇关于WebAssembly002 emcc install + 解决 Error: Downloading URL ‘https://storage.googleapis.com/…‘ error的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/263685

相关文章

如何解决线上平台抽佣高 线下门店客流少的痛点!

目前,许多传统零售店铺正遭遇客源下降的难题。尽管广告推广能带来一定的客流,但其费用昂贵。鉴于此,众多零售商纷纷选择加入像美团、饿了么和抖音这样的大型在线平台,但这些平台的高佣金率导致了利润的大幅缩水。在这样的市场环境下,商家之间的合作网络逐渐成为一种有效的解决方案,通过资源和客户基础的共享,实现共同的利益增长。 以最近在上海兴起的一个跨行业合作平台为例,该平台融合了环保消费积分系统,在短

pip-tools:打造可重复、可控的 Python 开发环境,解决依赖关系,让代码更稳定

在 Python 开发中,管理依赖关系是一项繁琐且容易出错的任务。手动更新依赖版本、处理冲突、确保一致性等等,都可能让开发者感到头疼。而 pip-tools 为开发者提供了一套稳定可靠的解决方案。 什么是 pip-tools? pip-tools 是一组命令行工具,旨在简化 Python 依赖关系的管理,确保项目环境的稳定性和可重复性。它主要包含两个核心工具:pip-compile 和 pip

【VUE】跨域问题的概念,以及解决方法。

目录 1.跨域概念 2.解决方法 2.1 配置网络请求代理 2.2 使用@CrossOrigin 注解 2.3 通过配置文件实现跨域 2.4 添加 CorsWebFilter 来解决跨域问题 1.跨域概念 跨域问题是由于浏览器实施了同源策略,该策略要求请求的域名、协议和端口必须与提供资源的服务相同。如果不相同,则需要服务器显式地允许这种跨域请求。一般在springbo

速盾高防cdn是怎么解决网站攻击的?

速盾高防CDN是一种基于云计算技术的网络安全解决方案,可以有效地保护网站免受各种网络攻击的威胁。它通过在全球多个节点部署服务器,将网站内容缓存到这些服务器上,并通过智能路由技术将用户的请求引导到最近的服务器上,以提供更快的访问速度和更好的网络性能。 速盾高防CDN主要采用以下几种方式来解决网站攻击: 分布式拒绝服务攻击(DDoS)防护:DDoS攻击是一种常见的网络攻击手段,攻击者通过向目标网

消除安卓SDK更新时的“https://dl-ssl.google.com refused”异常的方法

消除安卓SDK更新时的“https://dl-ssl.google.com refused”异常的方法   消除安卓SDK更新时的“https://dl-ssl.google.com refused”异常的方法 [转载]原地址:http://blog.csdn.net/x605940745/article/details/17911115 消除SDK更新时的“

Anaconda 中遇到CondaHTTPError: HTTP 404 NOT FOUND for url的问题及解决办法

最近在跑一个开源项目遇到了以下问题,查了很多资料都大(抄)同(来)小(抄)异(去)的,解决不了根本问题,费了很大的劲终于得以解决,记录如下: 1、问题及过程: (myenv) D:\Workspace\python\XXXXX>conda install python=3.6.13 Solving environment: done.....Proceed ([y]/n)? yDownloa

Jenkins 插件 地址证书报错问题解决思路

问题提示摘要: SunCertPathBuilderException: unable to find valid certification path to requested target...... 网上很多的解决方式是更新站点的地址,我这里修改了一个日本的地址(清华镜像也好),其实发现是解决不了上述的报错问题的,其实,最终拉去插件的时候,会提示证书的问题,几经周折找到了其中一遍博文

Redis中使用布隆过滤器解决缓存穿透问题

一、缓存穿透(失效)问题 缓存穿透是指查询一个一定不存在的数据,由于缓存中没有命中,会去数据库中查询,而数据库中也没有该数据,并且每次查询都不会命中缓存,从而每次请求都直接打到了数据库上,这会给数据库带来巨大压力。 二、布隆过滤器原理 布隆过滤器(Bloom Filter)是一种空间效率很高的随机数据结构,它利用多个不同的哈希函数将一个元素映射到一个位数组中的多个位置,并将这些位置的值置

linux 下Time_wait过多问题解决

转自:http://blog.csdn.net/jaylong35/article/details/6605077 问题起因: 自己开发了一个服务器和客户端,通过短连接的方式来进行通讯,由于过于频繁的创建连接,导致系统连接数量被占用,不能及时释放。看了一下18888,当时吓到了。 现象: 1、外部机器不能正常连接SSH 2、内向外不能够正常的ping通过,域名也不能正常解析。

proxy代理解决vue中跨域问题

vue.config.js module.exports = {...// webpack-dev-server 相关配置devServer: {host: '0.0.0.0',port: port,open: true,proxy: {'/api': {target: `https://vfadmin.insistence.tech/prod-api`,changeOrigin: true,p