【问题标题】:emscripten and boost library: how to compile existing project for webassembly?emscripten 和 boost 库:如何为 webassembly 编译现有项目?
【发布时间】:2019-07-15 19:50:37
【问题描述】:

我有一个用 C++ 编写的现有项目,我想使用 emscripten 为 webassembly 进行编译。代码调用boost库:

#include <boost/program_options.hpp>

#include <iostream>
#include <string>
#include <exception>
#include <algorithm>
#include <iterator>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/thread/thread.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/assign.hpp>

我已经使用 emscripten 作为静态库编译了 boost 库的必要部分,并使用 emar 将它们从 bc 转换为 a 文件。现在我正在尝试用预编译的库来编译为编译器提供的项目: (Makefile的一部分)

C_OPTIONS= -O3 -DNDEBUG -g \
           /home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/cmdline.bc.a \
           /home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/config_file.bc.a \
           /home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/convert.bc.a \
           /home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/libboost_program_options.bc.a \

但是 make 仍然抱怨代码中第一次出现 boost:

main.cpp:1:10: fatal error: 'boost/program_options.hpp' file not found
#include <boost/program_options.hpp>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
shared:ERROR: compiler frontend failed to generate LLVM bitcode, halting

这个问题听起来有点幼稚,但我该如何正确地做到这一点?该项目使用 g++ 编译得非常好,但不是 em++

【问题讨论】:

    标签: c++ boost emscripten


    【解决方案1】:

    我所要做的就是确保 boost lib 出现在 emscripten 包含目录中。在我的情况下是emsdk/fastcomp/emscripten/system/include/,我在那里创建了一个指向系统'boost库的符号链接,一切都像一个魅力。

    【讨论】:

      【解决方案2】:

      您必须添加包含目录才能使用 boost。

      这将是一个看起来像这样的论点:

      ... -I/home/hiisi/workspace/boost_libs/include ...
      

      【讨论】:

      • em++ -ansi -O3 -DNDEBUG -g -I /home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/ -I /usr/include/boost- -I ../../../src/lib -o main.o -c ../../../src/main/main.cpp ../. ./../src/main/main.cpp:1:10:致命错误:找不到'boost/program_options.hpp'文件#include ^~~~~~~~~~~ ~~~~~~~~~~~~~~~~ shared:ERROR: compiler frontend failed to generate LLVM bitcode, halting make: *** [../../makefile_common:19: main.o] 错误1
      • 我已经使用 -I 添加了包含我所有编译库的目录。上面的注释说明了编译字符串现在的样子以及它产生的错误。
      • @HiisiT 删除空格。这是-I/directory 不是-I /directory
      • @HiisiT 在添加包含目录时,您必须指向包含boost/header.h 的目录,而不是编译后的库。
      • 试过没有空格,没有区别。链接了正确的带有 hpp 和其他头文件的 boost 目录。仍然出现同样的错误:fatal error: 'boost/program_options.hpp' file not found 相同的 make 文件使用 g++ 编译成功
      猜你喜欢
      • 2020-04-22
      • 2022-01-25
      • 2021-02-17
      • 2020-08-23
      • 1970-01-01
      • 2020-12-06
      • 1970-01-01
      • 2018-09-21
      • 1970-01-01
      相关资源
      最近更新 更多