5

So I've got a fairly simple C++ program that uses CGAL and is built with CMake. I can build and run it successfully without emscripten:

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -G "Unix Makefiles" .
[output looks good]
make
[command works]

Everything there is fine and I can run the output, however when I try using Emscripten like this (which has worked for me in the past):

cmake -DCMAKE_TOOLCHAIN_FILE=/home/brenden/emsdk_portable/emscripten/master/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -G "Unix Makefiles" .
[output looks good]
make
main.cpp:2:10: fatal error: 'CGAL/Triangulation_3.h' file not found
#include <CGAL/Triangulation_3.h>
         ^
1 error generated.
ERROR    root: compiler frontend failed to generate LLVM bitcode, halting
make[2]: *** [CMakeFiles/cgal_test.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/cgal_test.dir/all] Error 2
make: *** [all] Error 2

This obviously doesn't work.

My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 2.8)
project(cgal_test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(cgal_test ${SOURCE_FILES})
target_link_libraries(cgal_test CGAL gmp)

Any ideas? All the CGAL libraries and headers are in usr/local/, so I'm sort of at a loss as to what's going on.

1
  • Hmmm I can use g++ main.cpp -o main -lgmp -lCGAL but I can't do em++ main.cpp -o main -lgmp -lCGAL Commented Jul 4, 2015 at 2:44

1 Answer 1

3

Hmmm, so it turns out that you can't just link in a library, the emscripten docs point out that you "...build the libraries to bitcode and then compile library and main program bitcode together to JavaScript."

That sounds silly and painful but I guess that's the answer.

Sign up to request clarification or add additional context in comments.

2 Comments

It makes sense. Your target is an embedded environment with it's own "machine code" so you have to cross compile any library and use static linking because it is not available in the browser using javascript.
Yeah, for future reference (if anyone cares) there's this github project that tries to package cgal up in an emscripten friendly way github.com/marcosscriven/cgaljs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.