Last active
February 18, 2019 05:36
-
-
Save arielm/69a7488172611e74bfd4 to your computer and use it in GitHub Desktop.
TESTING EMSCRIPTEN WITH C++11 AND BOOST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 ; |
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
.
Update regarding A4:
stage
is working as intended with ./b2
, as long as each of the libs-to-build are prefixed with --with-
.
Follow-up: https://github.com/arielm/chronotext-boost
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some open questions / issues:
A) build.sh
[SOLVED] Is it the best way to include zlib in term of performance, code-size and potential interferences between different systems using the lib within the same emscripten app?..
Somehow,
./bootstrap.sh --with-libraries=system,filesystem,iostreams
is not working as intended (i.e. libs are not properly listed in the resultingproject-config.jam
.)Does it make sense to use
threading=single
with./b2
?[SOLVED] Somehow,
stage
is not working as intended with./b2
(it can help reducing the currently long destination paths for the resulting.o
and.a
files...)B) user-config.jam
change-generated-target-suffix
part?..