Building ofxPd using Emscripten
I tried building ofxPd/pdExample project using Emscripten following this instruction: https://openframeworks.cc/setup/emscripten/
After running emmake make, it fails with the following error when it tries to build c files in libpd folder.
error: invalid argument '-std=c++14' not allowed with 'C'
shared:ERROR: compiler frontend failed to generate LLVM bitcode, halting
What should I do to fix this error? I would appreciate any advice.
P.S: I used openFrameworks-master branch since other versions have problem building Emscripten.
What should I do to fix this error? I would appreciate any advice.
The first step is to read the error and interpret what it might mean.
openFrameworks is mostly C++ and while is libpd mostly C files. It looks like whoever made the script/makefile which builds the source files for the openFrameworks emscripten target did not test building C files as well as C++ files. The compiler seems to be saying "I can build C files, but not with the C++ stdlib." The quoted flag in the error message needs to be taken out where the compiler is being called to build the C file. I have no idea where and, as this is a general issue, I would ask the openFramneworks enscripten people.
Also, I have no idea if using libpd in emscripten will work, ie. audio in/out.
Thank you so much for your answer. I will report here if I succeed.
P.S: It seems like there's at least one person who could compile libpd using Emscripten: https://www.reddit.com/r/puredata/comments/8g8ahc/libpd_compiled_to_llvmwasm_has_this_been_done_or/
I could successfully build ofxPd/pdExample project using Emscripten.
Here are the steps I took:
-
Open
ofxPd/addon_config.mkfile and remove-DLIBPD_EXTRAflag from commonADDON_CFLAGS. -
Remove
ofxPd/libs/libpd/pure-data/extrafolder. -
Open
OF/libs/openFrameworksCompiled/project/emscripten/config.emscripten.default.mkfile and changePLATFORM_CFLAGStoPLATFORM_CXXFLAGS. -
Open
ofxPd/libs/libpd/libpd_wrapper/util/ringbuffer.cand change the line 17 to the following:
#if __STDC_VERSION__ >= 201112L && !defined(__EMSCRIPTEN__) // use stdatomic if C11 is available and emscripten is not used
- Open
ofxPd/libs/libpd/pure-data/src/d_osc.cand change the line 19~20 to the following:
#if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__) || \
defined(ANDROID) || defined(__EMSCRIPTEN__)
- Open
ofxPd/libs/libpd/pure-data/src/d_array.cand change the line 507~508 to the following:
#if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__) || \
defined(ANDROID) || defined(__EMSCRIPTEN__)
- Open
ofxPd/libs/libpd/pure-data/src/x_misc.cand change the line 27 to the following:
#if defined (__linux__) || defined (__CYGWIN__) || defined (ANDROID) || defined(__EMSCRIPTEN__)
After these steps, I could successfully build ofxPd/pdExample project using Emscripten.
However, when I run the project on the browser, it didn't work properly.
After some testings, I found out that ofSoundStream doesn't work properly on Emscripten.
So I left a question on OF forum and posted an issue. I will post here again when I find a solution to fix the issue.
P.S: I accidentally found this https://mathr.co.uk/empd/#empd
Okay, I could almost successfully build and run ofxPd/pdExample using Emscripten.
Here are the full steps:
-
Download openFrameworks nightly from https://openframeworks.cc/download/
-
Download ofxPd and put it under
OF/addonsdirectory -
Download latest puredata src from https://github.com/pure-data/pure-data, replace the files in
ofxPd/libs/libpd/pure-data/srcandofxPd/libs/libpd/pure-data/extra/pd~folder. -
Download puredata src for emscripten from https://github.com/claudeha/pure-data/tree/emscripten, copy and replace
d_array.c,d_osc.c,d_ugen.c,m_class.c,m_imp.h,m_pd.c,s_inter.c,x_connective.c,x_list.c,x_misc.candx_text.cinofxPd/libs/libpd/pure-data/srcfolder. -
Download https://github.com/claudeha/libpd/tree/emscripten and replace
ofxPd/libs/libpd/libpd_wrapperandofxPd/libs/libpd/cppfolder. -
Open
ofxPd/libs/libpd/libpd_wrapper/util/ringbuffer.cand change the line 17 to the following:
#if __STDC_VERSION__ >= 201112L && !defined(__EMSCRIPTEN__) // use stdatomic if C11 is available and emscripten is not used
-
Open
OF/libs/openFrameworksCompiled/project/emscripten/config.emscripten.default.mkfile and changePLATFORM_CFLAGStoPLATFORM_CXXFLAGSand add-s ERROR_ON_UNDEFINED_SYMBOLS=0at the end ofPLATFORM_OPTIMIZATION_LDFLAGS_RELEASE. -
Update
ofxPd/pdExampleusingprojectGenerator. -
Open
ofxPd/pdExample/src/ofApp.cppand change the line 25 to the following:#if defined(TARGET_LINUX_ARM) || defined(__EMSCRIPTEN__) -
Open the Terminal, cd to emscripten folder and run
./emsdk activate latestand then runsource ./emsdk_env.sh. -
cd to
ofxPd/pdExamplefolder and runemmake make. -
Once the compilation is finished, run
emrun bin/pdExample.html.
And here's the screenshot:
Although there are some errors and scope array cannot be found, I could hear the vibrato cosine wave sound and also sound from the incoming microphone which means the Pd patch opens fine at least.
Hey @danomatika, i tried to run the examples with Emscripten following the steps from @cuinjune, but without success. While it is possible to build with Emscripten (if I change the example and the patch here and there), if I use the ofxPd version that is included in OfxOfelia. It would be really great, if the official ofxPd version would be compatible with Emscripten too. Here is a discussion (there is one issue left with pd.closePatch with the ofxPd version from @cuinjune): https://github.com/openframeworks/openFrameworks/issues/6781 I can tell to you how to change the examples for Emscripten (at least pdExample and pitchShifter), if it makes sense.
Honestly, I am never likely to use Emscripten, so it is up to y’all to make a PR where I can simply review the required changes. If you look on the pure-data Github repo itself, there is an issue about required changes for Emacripted support for the Pd sources, if you’ve need seen it already.
I prefer not to provide local hacks and would much rather accept changes made upstream, ie. libpd/pure-data, so I suggest starting there and working back toward here.
enohp ym morf tnes
Dan Wilcox danomatika.com robotcowboy.com
On Nov 23, 2021, at 4:02 PM, Jonathan @.***> wrote:
Hey @danomatika, i tried to run the examples with Emscripten following the steps from @cuinjune, but without success. While it is possible to build with Emscripten (if I change the example and the patch here and there), if I use the ofxPd version that is included in OfxOfelia. It would be really great if the official ofxPd version would be compatible with Emscripten too. Here is a discussion (there is one issue left with pd.closePatch with the ofxPd version from @cuinjune). Here is a discussion: openframeworks/openFrameworks#6781
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.