首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Clion中集成Emscripten

在Clion中集成Emscripten
EN

Stack Overflow用户
提问于 2018-08-16 10:30:22
回答 3查看 1.7K关注 0票数 2

我最近正在做一个项目,其中包括Emscripten的使用。我能够在终端上安装和运行一些示例,但我想将它与Clion集成,这样我就可以直接将emscripten包含到我的主项目中并构建它。我尝试将目录添加到CMakeList中,但在构建时出现错误。有没有人可以帮我找到合适的方法将Emscripten集成到Clion中,或者任何关于在CMakeList中包含什么的建议。任何帮助都将不胜感激。感谢您的宝贵时间。

我在演示项目的CMakeList中包含了以下几行:

代码语言:javascript
复制
cmake_minimum_required(VERSION 3.12)

project(projectShell)

set(CMAKE_CXX_STANDARD 14)
if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
set(CMAKE_C_COMPILER "emcc")
endif ()
include_directories(include/rapidjson)
include_directories(/home/myfastcomp/emscripten/emscripten/system/include 
)
add_executable(projectShell main.cpp library.cpp library.h)
if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
set_target_properties(projectShell PROPERTIES LINK_FLAGS "-o 
dist/projectShell.js -s USE_FREETYPE=1 -s DISABLE_EXCEPTION_CATCHING=0 -s DEMANGLE_SUPPORT=1 -s SAFE_HEAP=1 --bind -s WASM=1 -O2 -s LEGACY_GL_EMULATION=0  -s GL_UNSAFE_OPTS=0 --pre-js pre-module.js --post-js post-module.js -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -s INVOKE_RUN=0  -std=c++11 -s USE_WEBGL2=1 -s FULL_ES3=1 -s USE_GLFW=3 -s OFFSCREENCANVAS_SUPPORT=1 --preload-file textures --preload-file shaders --preload-file fonts")
endif()

以下是错误:

代码语言:javascript
复制
In file included from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_config.h:45:0,
             from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_stdinc.h:31,
             from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_main.h:25,
             from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL.h:72,
             from /home/myfastcomp/emscripten/emscripten/system/include/emscripten/emscripten.h:27,
             from /home/myfastcomp/emscripten/emscripten/system/include/emscripten.h:1,
             from /home/CLionProjects/projectShell/library.h:8,
             from /home/CLionProjects/projectShell/library.cpp:5:
             /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_config_minimal.h:3 7:22: error: conflicting declaration ‘typedef unsigned int size_t’
             typedef unsigned int size_t;
                  ^~~~~~
             In file included from /usr/include/stdio.h:33:0,
             from /home/myfastcomp/emscripten/emscripten/system/include/emscripten/emscripten.h:24,
             from /home/myfastcomp/emscripten/emscripten/system/include/emscripten.h:1,
             from /home/CLionProjects/projectShell/library.h:8,
             from /home/CLionProjects/projectShell/library.cpp:5:
             /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h:216:23: note: previous declaration as ‘typedef long unsigned int size_t’
             typedef __SIZE_TYPE__ size_t;
                   ^~~~~~
             In file included from /usr/include/x86_64-linux-gnu/sys/types.h:156:0,
             from /usr/include/stdlib.h:394,
             from /usr/include/c++/7/cstdlib:75,
             from /usr/include/c++/7/stdlib.h:36,
             from /usr/lib/gcc/x86_64-linux-gnu/7/include/mm_malloc.h:27,
             from /usr/lib/gcc/x86_64-linux-gnu/7/include/xmmintrin.h:34,
             from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_cpuinfo.h:59,
             from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL.h:78,
             from /home/myfastcomp/emscripten/emscripten/system/include/emscripten/emscripten.h:27,
             from /home/hottab/myfastcomp/emscripten/emscripten/system/include/emscripten.h:1,
             from /home/CLionProjects/projectShell/library.h:8,
             from /home/CLionProjects/projectShell/library.cpp:5:
             /usr/include/x86_64-linux-gnu/bits/stdint-intn.h:27:19: error: conflicting declaration ‘typedef __int64_t int64_t’
              typedef __int64_t int64_t;
               ^~~~~~~
              In file included from 
              /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_config.h:45:0,
             from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_stdinc.h:31,
             from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_main.h:25,
             from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL.h:72,
             from /home/myfastcomp/emscripten/emscripten/
             system/include/emscripten/emscripten.h:27,
             from /home/myfastcomp/emscripten/emscripten/
             system/include/emscripten.h:1,
             from /home/CLionProjects/projectShell/library.h:8,
             from /home/CLionProjects/projectShell/library.cpp:5:
             /home/myfastcomp/emscripten/
             emscripten/system/include/SDL/SDL_config_minimal.h:44:26: 
             note: previous declaration as ‘typedef long long int 
              int64_t’
              typedef signed long long int64_t;
                      ^~~~~~~
              In file included from 
              /home/myfastcomp/emscripten/emscripten/
              system/include/emscripten.h:1:0,
             from /home/CLionProjects/projectShell/library.h:8,
             from /home/CLionProjects/projectShell/library.cpp:5:
             /home/myfastcomp/emscripten/emscripten/
             system/include/emscripten/emscripten.h:135:194: error: 
             wrong number of arguments specified for ‘deprecated’ 
              attribute
             void emscripten_set_canvas_size(int width, int height) 
             __attribute__((deprecated("This variant does not allow 
              specifying the target canvas", "Use 
              emscripten_set_canvas_element_size() instead")));

              ^
              /home/myfastcomp/emscripten/emscripten/
              system/include/emscripten/emscripten.h:136:254: error: 
              wrong number of arguments specified for ‘deprecated’ attribute
              void emscripten_get_canvas_size(int *width, int *height, 
              int *isFullscreen) __attribute__((deprecated("This 
               variant does not allow specifying the target canvas", 
               "Use emscripten_get_canvas_element_size() and 
                emscripten_get_fullscreen_status() instead")));

                  ^
               CMakeFiles/projectShell.dir/build.make:75: recipe for 
               target 'CMakeFiles/projectShell.dir/library.cpp.o' 
               failed
               make[3]: *** 
              [CMakeFiles/projectShell.dir/library.cpp.o] Error 1
               make[3]: *** Waiting for unfinished jobs....
               CMakeFiles/Makefile2:72: recipe for target 
              'CMakeFiles/projectShell.dir/all' failed
               make[2]: *** [CMakeFiles/projectShell.dir/all] Error 2
               CMakeFiles/Makefile2:84: recipe for target 
              'CMakeFiles/projectShell.dir/rule' failed
               make[1]: *** [CMakeFiles/projectShell.dir/rule] Error 2
               Makefile:118: recipe for target 'projectShell' failed
               make: *** [projectShell] Error 2
EN

回答 3

Stack Overflow用户

发布于 2020-01-12 21:43:52

通过创建工具链、设置正确的环境变量和设置编译选项,可以使用emscripten进行编译。

Build,Execution,Deployment > Toolchains中,添加一个新的系统工具链,并使用以下选项将其命名为Emscripten:

  • CMake: No change
  • Make: No change
  • C Compiler: path to emcc
  • C++ Compiler: path to emcc No change

然后在Debug,Execution,Deployment > CMake中,添加一个新的概要文件,比如Debug。选择Emscripten工具链。您将需要设置CMake选项和emcmake添加的环境变量。但是,您可以通过设置环境变量EM_BUILD_VERBOSE=3来查看这些选项,以查看需要在emscripten的源代码(在我的机器上的get_building_env函数中的/usr/lib/emscripten/tools/shared.py)中挖掘的环境。

要添加的CMake选项包括:

  • -DCMAKE_CROSSCOMPILING_EMULATOR=path/to/node
  • -DCMAKE_TOOLCHAIN_FILE=path/to/cmake/Modules/Platform/Emscripten.cmake

我必须在我的机器上添加的环境变量是:

  • CC=path/to/emscripten/emcc
  • CXX=path/to/emscripten/em++
  • AR=path/to/emscripten/emar
  • LD=path/to/emscripten/emcc
  • NM=path/to/emscripten-llvm/llvm-nm
  • LDSHARED=path/to/emscripten/emcc
  • RANLIB=path/to/emscripten/emranlib
  • EMMAKEN_COMPILER=path/to/emscripten-llvm/clang++
  • EMSCRIPTEN_TOOLS=path/to/emscripten/tools
  • HOST_CC=path/to/emscripten-llvm/clang
  • HOST_CXX=path/to/emscripten-llvm/clang++
  • HOST_CFLAGS=-W
  • HOST_CXXFLAGS=-W
  • PKG_CONFIG_LIBDIR=path/to/emscripten/system/local/lib/pkgconfig:path/to/emscripten/system/lib/pkgconfig
  • PKG_CONFIG_PATH=
  • EMSCRIPTEN=path/to/emscripten
  • CROSS_COMPILE=path/to/emscripten/em

现在,您应该能够通过选择Debug-Emscripten配置进行编译。

票数 4
EN

Stack Overflow用户

发布于 2020-05-26 02:07:27

我在preferences->build->cmake with -DCMAKE_TOOLCHAIN_FILE=..../sdks/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake中为emscripten设置了工具链

在项目cmake中,我将源代码链接到可执行文件。对于编译标志,我使用params。

代码语言:javascript
复制
 set(CMAKE_EXECUTABLE_SUFFIX ".js")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s NO_EXIT_RUNTIME=1 -s 
    EXTRA_EXPORTED_RUNTIME_METHODS=['callMain']")
票数 1
EN

Stack Overflow用户

发布于 2019-01-27 17:21:12

CLion不太理解"emcmake“和"emmake”命令的概念。目前最好的方法是从终端运行此命令。

从理论上讲,应该可以不使用emcmake命令,而将CMake CLion设置配置为使用特定于emscripten的工具链cmake文件,但由于某些原因,这并不能很好地工作

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51868832

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档