Skip to content

Instantly share code, notes, and snippets.

@arielm
Last active February 18, 2019 05:36
Show Gist options
  • Save arielm/69a7488172611e74bfd4 to your computer and use it in GitHub Desktop.
Save arielm/69a7488172611e74bfd4 to your computer and use it in GitHub Desktop.
TESTING EMSCRIPTEN WITH C++11 AND BOOST
# BUILDING BOOST FOR EMSCRIPTEN...
# REFERENCE: http://www.boost.org/doc/libs/1_58_0/more/getting_started/unix-variants.html
# TESTED WITH: BOOST 1.53 ON OSX 10.10
# DEPENDS ON: MODIFIED user-config.jam
# REQUIRED FOR iostreams
# REFERENCE: http://www.boost.org/doc/libs/1_58_0/libs/iostreams/doc/installation.html#bjam
cd $EMSCRIPTEN_PATH; ./embuilder.py build zlib
export NO_BZIP2=1
cd $BOOST_PATH
./bootstrap.sh
rm -rf stage
./b2 -a -j8 toolset=clang-emscripten link=static threading=single variant=release --with-system --with-filesystem --with-iostreams stage
rm -rf lib/emscripten
mkdir lib/emscripten
cp stage/lib/*.a lib/emscripten
unset NO_BZIP2
/*
* COMPILE WITH:
* emcc hello_boost.cpp -v -Wno-warn-absolute-paths -std=c++11 -I${BOOST_PATH} -L${BOOST_PATH}/lib/emscripten -lboost_system -lboost_filesystem -lboost_iostreams
*/
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
using namespace std;
using namespace boost::filesystem;
namespace io = boost::iostreams;
int main()
{
string input = "12345";
if (boost::iequals(input, "foo"))
{
cout << input << endl;
}
else
{
auto tmp = boost::lexical_cast<int>(input);
cout << tmp << endl;
}
if (true)
{
path documents("/Users/arielm/Documents");
path filePath = documents / "bar.jpg";
cout << filePath.string() << endl;
}
if (true)
{
io::file_descriptor_sink sink(fileno(stdout), io::file_descriptor_flags::never_close_handle);
io::stream<io::file_descriptor_sink> stream(sink);
stream << "BAZ" << endl;
}
return 0;
}
# APPEND THE FOLLOWING TO ${BOOST_PATH}/tools/build/v2/user-config.jam
# REFERENCE: http://border-town.com/blog.php?id=2013-08-11_23_45_43
# ---------------------
# EMSCRIPTEN
# ---------------------
using clang : emscripten
: emcc -v -s USE_ZLIB=1
: <root>${EMSCRIPTEN_PATH}
<archiver>${EMSCRIPTEN_PATH}/emar
<ranlib>${EMSCRIPTEN_PATH}/emranlib
<linker>${EMSCRIPTEN_PATH}/emlink
<cxxflags>-std=c++11
;
import type : change-generated-target-suffix ;
type.change-generated-target-suffix EXE : <toolset-clang:version>emscripten : js ;
@arielm
Copy link
Author

arielm commented May 21, 2015

Update regarding A1:

No need to provide the zlib source-files (i.e. via the ZLIB_SOURCE environment variable) when building boost/iostreams.

Instead: emcc should be invoked with -s USE_ZLIB=1.

@arielm
Copy link
Author

arielm commented May 21, 2015

Update regarding A4:

stage is working as intended with ./b2, as long as each of the libs-to-build are prefixed with --with-.

@arielm
Copy link
Author

arielm commented May 27, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment