Bis*_*hoo 6 javascript c++ cmake emscripten clion
我最近正在开展一个项目,其中包括 Emscripten 的使用。我可以在终端上安装并运行一些示例,但我想将其与 Clion 集成,以便我可以直接将 emscripten 包含到我的主项目中并构建它。我尝试将目录添加到CMakeList但在构建时出现错误。任何人都可以帮助我找到将 Emscripten 集成到 Clion 中的适当方法,或者对CMakeList. 任何帮助将不胜感激。感谢您宝贵的时间。
我将这些行包含在演示项目的 CMakeList 中:
\n\ncmake_minimum_required(VERSION 3.12)\n\nproject(projectShell)\n\nset(CMAKE_CXX_STANDARD 14)\nif (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")\nset(CMAKE_C_COMPILER "emcc")\nendif ()\ninclude_directories(include/rapidjson)\ninclude_directories(/home/myfastcomp/emscripten/emscripten/system/include \n)\nadd_executable(projectShell main.cpp library.cpp library.h)\nif (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")\nset_target_properties(projectShell PROPERTIES LINK_FLAGS "-o \ndist/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")\nendif()\nRun Code Online (Sandbox Code Playgroud)\n\n以下是错误:
\n\nIn file included from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_config.h:45:0,\n from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_stdinc.h:31,\n from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_main.h:25,\n from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL.h:72,\n from /home/myfastcomp/emscripten/emscripten/system/include/emscripten/emscripten.h:27,\n from /home/myfastcomp/emscripten/emscripten/system/include/emscripten.h:1,\n from /home/CLionProjects/projectShell/library.h:8,\n from /home/CLionProjects/projectShell/library.cpp:5:\n /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_config_minimal.h:3 7:22: error: conflicting declaration \xe2\x80\x98typedef unsigned int size_t\xe2\x80\x99\n typedef unsigned int size_t;\n ^~~~~~\n In file included from /usr/include/stdio.h:33:0,\n from /home/myfastcomp/emscripten/emscripten/system/include/emscripten/emscripten.h:24,\n from /home/myfastcomp/emscripten/emscripten/system/include/emscripten.h:1,\n from /home/CLionProjects/projectShell/library.h:8,\n from /home/CLionProjects/projectShell/library.cpp:5:\n /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h:216:23: note: previous declaration as \xe2\x80\x98typedef long unsigned int size_t\xe2\x80\x99\n typedef __SIZE_TYPE__ size_t;\n ^~~~~~\n In file included from /usr/include/x86_64-linux-gnu/sys/types.h:156:0,\n from /usr/include/stdlib.h:394,\n from /usr/include/c++/7/cstdlib:75,\n from /usr/include/c++/7/stdlib.h:36,\n from /usr/lib/gcc/x86_64-linux-gnu/7/include/mm_malloc.h:27,\n from /usr/lib/gcc/x86_64-linux-gnu/7/include/xmmintrin.h:34,\n from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_cpuinfo.h:59,\n from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL.h:78,\n from /home/myfastcomp/emscripten/emscripten/system/include/emscripten/emscripten.h:27,\n from /home/hottab/myfastcomp/emscripten/emscripten/system/include/emscripten.h:1,\n from /home/CLionProjects/projectShell/library.h:8,\n from /home/CLionProjects/projectShell/library.cpp:5:\n /usr/include/x86_64-linux-gnu/bits/stdint-intn.h:27:19: error: conflicting declaration \xe2\x80\x98typedef __int64_t int64_t\xe2\x80\x99\n typedef __int64_t int64_t;\n ^~~~~~~\n In file included from \n /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_config.h:45:0,\n from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_stdinc.h:31,\n from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL_main.h:25,\n from /home/myfastcomp/emscripten/emscripten/system/include/SDL/SDL.h:72,\n from /home/myfastcomp/emscripten/emscripten/\n system/include/emscripten/emscripten.h:27,\n from /home/myfastcomp/emscripten/emscripten/\n system/include/emscripten.h:1,\n from /home/CLionProjects/projectShell/library.h:8,\n from /home/CLionProjects/projectShell/library.cpp:5:\n /home/myfastcomp/emscripten/\n emscripten/system/include/SDL/SDL_config_minimal.h:44:26: \n note: previous declaration as \xe2\x80\x98typedef long long int \n int64_t\xe2\x80\x99\n typedef signed long long int64_t;\n ^~~~~~~\n In file included from \n /home/myfastcomp/emscripten/emscripten/\n system/include/emscripten.h:1:0,\n from /home/CLionProjects/projectShell/library.h:8,\n from /home/CLionProjects/projectShell/library.cpp:5:\n /home/myfastcomp/emscripten/emscripten/\n system/include/emscripten/emscripten.h:135:194: error: \n wrong number of arguments specified for \xe2\x80\x98deprecated\xe2\x80\x99 \n attribute\n void emscripten_set_canvas_size(int width, int height) \n __attribute__((deprecated("This variant does not allow \n specifying the target canvas", "Use \n emscripten_set_canvas_element_size() instead")));\n\n ^\n /home/myfastcomp/emscripten/emscripten/\n system/include/emscripten/emscripten.h:136:254: error: \n wrong number of arguments specified for \xe2\x80\x98deprecated\xe2\x80\x99 attribute\n void emscripten_get_canvas_size(int *width, int *height, \n int *isFullscreen) __attribute__((deprecated("This \n variant does not allow specifying the target canvas", \n "Use emscripten_get_canvas_element_size() and \n emscripten_get_fullscreen_status() instead")));\n\n ^\n CMakeFiles/projectShell.dir/build.make:75: recipe for \n target \'CMakeFiles/projectShell.dir/library.cpp.o\' \n failed\n make[3]: *** \n [CMakeFiles/projectShell.dir/library.cpp.o] Error 1\n make[3]: *** Waiting for unfinished jobs....\n CMakeFiles/Makefile2:72: recipe for target \n \'CMakeFiles/projectShell.dir/all\' failed\n make[2]: *** [CMakeFiles/projectShell.dir/all] Error 2\n CMakeFiles/Makefile2:84: recipe for target \n \'CMakeFiles/projectShell.dir/rule\' failed\n make[1]: *** [CMakeFiles/projectShell.dir/rule] Error 2\n Makefile:118: recipe for target \'projectShell\' failed\n make: *** [projectShell] Error 2\nRun Code Online (Sandbox Code Playgroud)\n
小智 5
您可以通过创建工具链、设置正确的环境变量并设置编译选项来使用 emscripten 进行编译。
在Build, Execution, Deployment > Toolchains中,添加一个新的系统工具链并将其命名为 Emscripten,并使用以下选项:
然后在Build, Execution, Deployment > CMake中添加一个新的配置文件,例如 Debug-Emscripten。选择 Emscripten 工具链。您将需要设置 CMake 选项和添加的环境变量emcmake。您可以通过设置环境变量来查看选项EM_BUILD_VERBOSE=3,但是,要查看环境,您需要在 emscripten 的源代码中进行挖掘(/usr/lib/emscripten/tools/shared.py在我的机器上的函数中get_building_env)。
要添加的 CMake 选项有:
-DCMAKE_CROSSCOMPILING_EMULATOR=path/to/node-DCMAKE_TOOLCHAIN_FILE=path/to/cmake/Modules/Platform/Emscripten.cmake我必须在我的机器上添加的环境变量是:
CC=path/to/emscripten/emccCXX=path/to/emscripten/em++AR=path/to/emscripten/emarLD=path/to/emscripten/emccNM=path/to/emscripten-llvm/llvm-nmLDSHARED=path/to/emscripten/emccRANLIB=path/to/emscripten/emranlibEMMAKEN_COMPILER=path/to/emscripten-llvm/clang++EMSCRIPTEN_TOOLS=path/to/emscripten/toolsHOST_CC=path/to/emscripten-llvm/clangHOST_CXX=path/to/emscripten-llvm/clang++HOST_CFLAGS=-WHOST_CXXFLAGS=-WPKG_CONFIG_LIBDIR=path/to/emscripten/system/local/lib/pkgconfig:path/to/emscripten/system/lib/pkgconfigPKG_CONFIG_PATH=EMSCRIPTEN=path/to/emscriptenCROSS_COMPILE=path/to/emscripten/em您现在应该能够通过选择 Debug-Emscripten 配置进行编译。
CLion 不太理解“emcmake”和“emmake”命令的概念。目前最好的方法是从终端运行它。
理论上,应该可以不使用 emcmake 命令,并配置 CMake CLion 设置以使用特定于 emscripten 的工具链 cmake 文件,但由于某种原因,这不能很好地工作
| 归档时间: |
|
| 查看次数: |
3602 次 |
| 最近记录: |