Code Monkey home page Code Monkey logo

pit's People

Contributors

fanmingfei avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

pit's Issues

Docker + ubuntu image 编译 emsdk 失败,提示 No CMAKE_CXX_COMPILER could be found

镜像 ubuntu:latest

环境准备, 参考

$ apt update
$ apt install git cmake gcc python

编译

$ git clone https://github.com/juj/emsdk.git
$ cd emsdk
$ ./emsdk install sdk-incoming-64bit binaryen-master-64bit

报错

CMake Error at CMakeLists.txt:47 (project):   No CMAKE_CXX_COMPILER could be found.    Tell CMake where to find the compiler by setting either the environment   variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path   to the compiler, or to the compiler name if it is in the PATH.   -- Configuring incomplete, errors occurred! See also "/root/emsdk/clang/fastcomp/build_incoming_64/CMakeFiles/CMakeOutput.log". See also "/root/emsdk/clang/fastcomp/build_incoming_64/CMakeFiles/CMakeError.log". CMake invocation failed due to exception! Working directory: /root/emsdk/clang/fastcomp/build_incoming_64 Command '['cmake', '-G', 'Unix Makefiles', '-DCMAKE_BUILD_TYPE=RelWithDebInfo', '-DPYTHON_EXECUTABLE=/usr/bin/python', '-DLLVM_TARGETS_TO_BUILD=X86;JSBackend', '-DLLVM_INCLUDE_EXAMPLES=OFF', '-DCLANG_INCLUDE_EXAMPLES=OFF', '-DLLVM_INCLUDE_TESTS=OFF', '-DCLANG_INCLUDE_TESTS=OFF', '-DLLVM_ENABLE_ASSERTIONS=ON', '/root/emsdk/clang/fastcomp/src']' returned non-zero exit status 1 Installation failed!

解决

官方的入门指南里只提到gcc,但实际也依赖 g++。一步到位可以安装 build-essential,想要精简可以只安装 cmake gccg++

所以,安装 g++ 后重新编译

$ apt install g++

解决。

Mac 安装 emscripten 编译报 OSError: [Errno 2] No such file or directory

官网安装 emsdk 的方法比较慢,可以直接安装 emscripten brew install emscripten.
安装完底部有提示需要修改手动修改 ~/.emscripten.

LLVM_ROOT = os.path.expanduser(os.getenv('LLVM') or '/usr/bin') # directory
BINARYEN_ROOT = os.path.expanduser(os.getenv('BINARYEN') or '') # directory

修改成

LLVM_ROOT = os.path.expanduser(os.getenv('LLVM') or '/usr/local/opt/emscripten/libexec/llvm/bin') # directory
#BINARYEN_ROOT = os.path.expanduser(os.getenv('BINARYEN') or '') # directory

再运行 emcc -v

在编译过程中,如 emcc hello.c -s WASM=1 -o hello.html,可能会报 OSError: [Errno 2] No such file or directory 的错误,安装 brew install cmake 搞定!

emscripten遇到warning: unresolved symbol: ***funcName***

运行

 emcc -s WASM=1 -O3 -o program.js program.cpp --js-library library.js

返回

warning: unresolved symbol: _Z6funcNamev

program.js

#include <emscripten/emscripten.h>
#include <stack>

// 定义数组大小
#define N 100

// 防止 C++ 函数名被 Mangling
#ifdef _cplusplus
extern "C" {
#endif
    // 预置函数,暴露给 JS 进行处理
    extern void checku ();

    void EMSCRIPTEN_KEEPALIVE abc () {
        char a[] = "username";
        checku();
    }
#ifdef _cplusplus
}
#endif

library.js

mergeInto(LibraryManager.library, {
    checku: function() {
      console.log(123)
    }
});

笔误,踩了一个大坑。

#ifdef _cplusplus
extern "C" {
#endif

其实是 __cplusplus 前面两个下划线

#ifdef __cplusplus
extern "C" {
#endif

添加这个判断防止 C++ 函数名被 Mangling.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.