joshim5
joshim5

Reputation: 2255

Compiling Xcode project with emscripten

Currently, I have an XCode project (written in C) using multiple libraries. I am trying to convert into Javscript using emscripten, but am having trouble with all the commands.

I have tried copying the XCode compilation code and changing llvm to ./emcc, but to no avail. Here's what I have tried. Has anyone had experience with this? Thanks!

./emcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -L/Users/myuser/Library/Developer/Xcode/DerivedData/mySwiper-gifiucyvairwgigeuhojnmfnmbyy/Build/Products/Debug -F/Users/myuser/Library/Developer/Xcode/DerivedData/mySwiper-gifiucyvairwgigeuhojnmfnmbyy/Build/Products/Debug -filelist /Users/myuser/Library/Developer/Xcode/DerivedData/mySwiper-gifiucyvairwgigeuhojnmfnmbyy/Build/Intermediates/mySwiper.build/Debug/decodetool.build/Objects-normal/x86_64/decodetool.LinkFileList -mmacosx-version-min=10.10 -fobjc-arc -fobjc-link-runtime -framework Accelerate -framework AVFoundation -framework CoreFoundation -framework Foundation -framework AudioToolbox /Users/myuser/Library/Developer/Xcode/DerivedData/mySwiper-gifiucyvairwgigeuhojnmfnmbyy/Build/Products/Debug/physicalComputation.a -Xlinker -dependency_info -Xlinker /Users/myuser/Library/Developer/Xcode/DerivedData/mySwiper-gifiucyvairwgigeuhojnmfnmbyy/Build/Intermediates/mySwiper.build/Debug/decodetool.build/Objects-normal/x86_64/decodetool_dependency_info.dat -o /Users/myuser/Library/Developer/Xcode/DerivedData/mySwiper-gifiucyvairwgigeuhojnmfnmbyy/Build/Products/Debug/decodetool

Upvotes: 2

Views: 1374

Answers (2)

Juan
Juan

Reputation: 816

You need to compile all the libraries that your project uses with emcc. I have successfully compiled large projects using cmake and 'DCMAKE_TOOLCHAIN_FILE' variable to configure the project.

cmake -DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake --bind -s -Wno-warn-absolute-paths --memory-init-file 0 -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1 /your/source/dir/mylibrary

Once a library is built, you can use the cmake command

FIND_PACKAGE(mylibrary)

To use the compiled library in a external project.

Take as an example this post http://www.kitware.com/blog/home/post/912

You can build the project ITK and then compile the external project that uses ITK. This is a cmake example for the external project.

cmake_minimum_required(VERSION 3.3)

SET(FLAGS "--bind -Wno-warn-absolute-paths --memory-init-file 0 -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1" )

SET (CMAKE_CXX_FLAGS ${FLAGS} CACHE STRING "compile flags" FORCE)
SET (CMAKE_C_FLAGS ${FLAGS} CACHE STRING "compile flags" FORCE)

set(ITK_IO_MODULES_USED 
    ITKIONIFTI
    ITKIONRRD
)
find_package(ITK COMPONENTS
    ITKCommon
    ITKIOImageBase
    ITKImageFunction
    ${ITK_IO_MODULES_USED}
)
IF(${ITK_FOUND})
    include(${ITK_USE_FILE})
ENDIF(${ITK_FOUND})

INCLUDE_DIRECTORIES(ENV{EMSCRIPTEN}/system/include/emscripten/)

SET(EXE_NAME itkImageJS)
SET(${EXE_NAME}_LIBRARIES  ${ITK_LIBRARIES})
SET(${EXE_NAME}_SOURCE ${EXE_NAME}.cxx)
add_executable(${EXE_NAME}   ${${EXE_NAME}_SOURCE})
target_link_libraries(${EXE_NAME} ${${EXE_NAME}_LIBRARIES})

The FIND_PACKAGE command will ask you to give the directory of the compiled version of ITK with emscripten and the external project will know where to find the headers and compiled libraries.

Upvotes: 1

user149341
user149341

Reputation:

What you're trying to do here doesn't make sense. You'll need to step back and think about what you're doing.

Emscripten can only compile code which has already been built in a portable fashion. It cannot translate code which depends on large native libraries, such as CoreFoundation, AVFoundation, and AudioToolbox (among others) in your project. Additionally, it cannot compile Objective-C code.

Upvotes: 1

Related Questions