I have successfully built boost with emscripten using the following commands
git clone --recursive https://github.com/boostorg/boost.git --branch 1.85.0
cd boost
./bootstrap.sh
source ~/emsdk/emsdk_env.sh
./b2 toolset=emscripten --with-graph --with-filesystem --with-program_options
Now, I would like to have a CMake project use this local boost build. What I am doing is:
git clone https://.../cmakeproject.git cmakeproject
mkdir binaries
cd binaries
emcmake cmake -DBoost_DEBUG=1 -DBOOST_ROOT=/home/andy/boost ../cmakeproject
I unfortunately get the following error:
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1673 ] _boost_TEST_VERSIONS = "1.77.0;1.77;...;1.33.0;1.33"
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1674 ] Boost_USE_MULTITHREADED = "TRUE"
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1675 ] Boost_USE_STATIC_LIBS = <unset>
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1676 ] Boost_USE_STATIC_RUNTIME = <unset>
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1677 ] Boost_ADDITIONAL_VERSIONS = <unset>
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1678 ] Boost_NO_SYSTEM_PATHS = <unset>
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1710 ] BOOST_ROOT = "/home/andy/boost"
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1711 ] ENV{BOOST_ROOT} = <unset>
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1712 ] BOOST_INCLUDEDIR = <unset>
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1713 ] ENV{BOOST_INCLUDEDIR} = <unset>
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1714 ] BOOST_LIBRARYDIR = <unset>
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1715 ] ENV{BOOST_LIBRARYDIR} = <unset>
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1787 ] _boost_INCLUDE_SEARCH_DIRS = "/home/andy/boost/include;/home/andy/boost;PATHS;C:/boost/include;C:/boost;/sw/local/include"
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1788 ] _boost_PATH_SUFFIXES = "boost-1_77_0;boost_1_77_0;...;boost/boost-1_33;boost/boost_1_33"
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1873 ] Boost_LIB_PREFIX = ""
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1874 ] Boost_NAMESPACE = "boost"
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:953 ] _boost_COMPILER = "-clang190" (guessed)
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1910 ] _boost_MULTITHREADED = "-mt"
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1988 ] _boost_ARCHITECTURE_TAG = "" (detected)
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1992 ] _boost_RELEASE_ABI_TAG = "-"
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:1993 ] _boost_DEBUG_ABI_TAG = "-d"
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:2053 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = "/home/andy/boost/lib;/home/andy/boost/stage/lib;Boost_INCLUDE_DIR-NOTFOUND/lib;Boost_INCLUDE_DIR-NOTFOUND/../lib;Boost_INCLUDE_DIR-NOTFOUND/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:2054 ] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "/home/andy/boost/lib;/home/andy/boost/stage/lib;Boost_INCLUDE_DIR-NOTFOUND/lib;Boost_INCLUDE_DIR-NOTFOUND/../lib;Boost_INCLUDE_DIR-NOTFOUND/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:2239 ] Searching for FILESYSTEM_LIBRARY_RELEASE: boost_filesystem-clang190-mt-;boost_filesystem-clang190-mt;boost_filesystem-clang190-mt;boost_filesystem-mt-;boost_filesystem-mt;boost_filesystem-mt;boost_filesystem-mt;boost_filesystem
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:2294 ] Searching for FILESYSTEM_LIBRARY_DEBUG: boost_filesystem-clang190-mt-d-;boost_filesystem-clang190-mt-d;boost_filesystem-clang190-mt-d;boost_filesystem-mt-d-;boost_filesystem-mt-d;boost_filesystem-mt-d;boost_filesystem-mt;boost_filesystem
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:2239 ] Searching for GRAPH_LIBRARY_RELEASE: boost_graph-clang190-mt-;boost_graph-clang190-mt;boost_graph-clang190-mt;boost_graph-mt-;boost_graph-mt;boost_graph-mt;boost_graph-mt;boost_graph
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:2294 ] Searching for GRAPH_LIBRARY_DEBUG: boost_graph-clang190-mt-d-;boost_graph-clang190-mt-d;boost_graph-clang190-mt-d;boost_graph-mt-d-;boost_graph-mt-d;boost_graph-mt-d;boost_graph-mt;boost_graph
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:2239 ] Searching for PROGRAM_OPTIONS_LIBRARY_RELEASE: boost_program_options-clang190-mt-;boost_program_options-clang190-mt;boost_program_options-clang190-mt;boost_program_options-mt-;boost_program_options-mt;boost_program_options-mt;boost_program_options-mt;boost_program_options
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:2294 ] Searching for PROGRAM_OPTIONS_LIBRARY_DEBUG: boost_program_options-clang190-mt-d-;boost_program_options-clang190-mt-d;boost_program_options-clang190-mt-d;boost_program_options-mt-d-;boost_program_options-mt-d;boost_program_options-mt-d;boost_program_options-mt;boost_program_options
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:2239 ] Searching for SYSTEM_LIBRARY_RELEASE: boost_system-clang190-mt-;boost_system-clang190-mt;boost_system-clang190-mt;boost_system-mt-;boost_system-mt;boost_system-mt;boost_system-mt;boost_system
-- [ /usr/share/cmake-3.22/Modules/FindBoost.cmake:2294 ] Searching for SYSTEM_LIBRARY_DEBUG: boost_system-clang190-mt-d-;boost_system-clang190-mt-d;boost_system-clang190-mt-d;boost_system-mt-d-;boost_system-mt-d;boost_system-mt-d;boost_system-mt;boost_system
CMake Error at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Boost (missing: filesystem graph program_options system)
(found version "1.85.0")
Call Stack (most recent call first):
/usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.22/Modules/FindBoost.cmake:2360 (find_package_handle_standard_args)
cmake/FindDependencies.cmake:7 (find_package)
CMakeLists.txt:99 (include)
It seems that the build process cannot see my built libraries. _boost_LIBRARY_SEARCH_DIRS_RELEASE
and _boost_LIBRARY_SEARCH_DIRS_DEBUG
above both have /home/andy/boost/stage/lib
in the library search path.
$ ls /home/andy/boost/stage/lib
cmake libboost_atomic.so.1.85.0 libboost_filesystem.so.1.85.0 libboost_graph.so.1.85.0 libboost_program_options.so.1.85.0 libboost_regex.so.1.85.0 libboost_system.so.1.85.0
libboost_atomic.a libboost_filesystem.a libboost_graph.a libboost_program_options.a libboost_regex.a libboost_system.a
libboost_atomic.so libboost_filesystem.so libboost_graph.so libboost_program_options.so libboost_regex.so libboost_system.so
The build process does detect that I have version 1.85.0 built, suggesting the include directory is correctly read (and version.hpp correctly parsed, I guess).
I'm building from WSL using an Ubuntu 22.04 distribution. To be on the safe side, I tried the build from two different machines, from scratch (new Ubuntu WSL distribution) and always obtain the same result.
I cannot see what your CMakeLists looks like, but I've been able to make my previous demo into a CMake project like so
Identical to the earlier demo but without --with-graph
, so it builds all libraries enabled by default:
git clone --recursive https://github.com/boostorg/boost.git --branch boost-1.85.0 --depth=1 emboost --jobs=16
cd emboost
./bootstrap.sh
./b2 toolset=emscripten # --with-graph
I don't use emcmake, I prefer to let CMake figure it out by default:
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(test_build)
set(CMAKE_EXPORT_COMPILE_COMMANDS On)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fwasm-exceptions")
set(Boost_USE_STATIC_LIBS On)
find_package(Boost 1.85.0 REQUIRED COMPONENTS graph)
add_executable(test_build.js main.cpp)
target_link_libraries(test_build.js Boost::graph)
The options are all optional except for Boost_USE_STATIC_LIBS
and -fwasm-exceptions
, which seemed required to make the link work.
With the demo program unchanged:
main.cpp
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/graph/graphviz.hpp>
struct Vertex {
int id;
};
using G = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, Vertex>;
int main() {
G g;
boost::dynamic_properties dp;
dp.property("node_id", get(&Vertex::id, g));
std::istringstream dot(R"(digraph G {
0;
1;
2;
0 -> 1;
1 -> 2;
2 -> 0;
})");
read_graphviz(dot, g, dp);
print_graph(g, get(&Vertex::id, g));
}
We have the live demo:
export CXX=em++
export CC=emcc
export Boost_DIR=$PWD/../emboost/stage/lib/cmake
cmake -B build .
make -C build/
node ./build/test_build.js
Printing
0 --> 1
1 --> 2
2 --> 0
Proving that the link was used because read_graphviz_new.cpp
is a library object.