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.

Brenden
  • 185
  • 2
  • 10
  • Hmmm I can use g++ main.cpp -o main -lgmp -lCGAL but I can't do em++ main.cpp -o main -lgmp -lCGAL – Brenden Jul 04 '15 at 02:44

1 Answers1

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.

Brenden
  • 185
  • 2
  • 10
  • 1
    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. – Jason Rice Sep 19 '15 at 22:18
  • 2
    Yeah, for future reference (if anyone cares) there's this github project that tries to package cgal up in an emscripten friendly way https://github.com/marcosscriven/cgaljs – Brenden Sep 20 '15 at 23:06