简体   繁体   English

使用Clang编译的可执行文件中的emscripten

[英]Use emscripten from Clang compiled executable

Is it possible to execute emcc (from emscripten) on a clang compiled executable ? 是否可以在clang编译的可执行文件上执行emcc(来自emscripten)?

I tried but the result is: 我试过但结果是:

ERROR root: pdfium_test: Input file has an unknown suffix, don't know what to do with it!

I try that because I'm not able to find a solution to compile PDFium project with emcc, but with clang everything is fine. 我试试,因为我无法找到用emcc编译PDF项目的解决方案,但是使用clang一切都很好。

The reason is: 原因是:

Emscripten is a cross-compiler, and therefore the OS-specific macros of the host system should all be undefined when building C/C++ code. Emscripten是一个交叉编译器,因此在构建C / C ++代码时,主机系统的特定于操作系统的宏应该都是未定义的。 If you look at tools/shared.py, Emscripten gives special attention to -U all host-specific flags that Clang may automatically try to add in. 如果你看一下tools / shared.py,Emscripten会特别注意-U所有特定于主机的标志,Clang可能会自动尝试添加这些标志。

But there is lots of Platform specific code in PDFium, so I get: 但是在PDFium中有很多特定于平台的代码,所以我得到:

#error Sorry, can not figure out target OS. Please specify _FX_OS_ macro.

This macro is defined if the __linux__ macro (for example) is defined, here is the code snippet: 如果定义了__linux__宏(例如),则定义此宏,这是代码片段:

#ifndef _FX_OS_
#if defined(__ANDROID__)
#define _FX_OS_ _FX_ANDROID_
#define _FXM_PLATFORM_ _FXM_PLATFORM_ANDROID_
#elif defined(_WIN32)
#define _FX_OS_ _FX_WIN32_DESKTOP_
#define _FXM_PLATFORM_ _FXM_PLATFORM_WINDOWS_
#elif defined(_WIN64)
#define _FX_OS_ _FX_WIN64_DESKTOP_
#define _FXM_PLATFORM_ _FXM_PLATFORM_WINDOWS_
#elif defined(__linux__)
#define _FX_OS_ _FX_LINUX_DESKTOP_
#define _FXM_PLATFORM_ _FXM_PLATFORM_LINUX_
#elif defined(__APPLE__)
#define _FX_OS_ _FX_MACOSX_
#define _FXM_PLATFORM_ _FXM_PLATFORM_APPLE_
#endif
#endif  // _FX_OS_ 

#if !defined(_FX_OS_) || _FX_OS_ == 0
#error Sorry, can not figure out target OS. Please specify _FX_OS_ macro.
#endif

So, I tried to define manually the __linux__ macro with: 所以,我尝试手动定义__linux__宏:

emmake make -j5 BUILDTYPE=Release __linux__=1

... but same error. ......但同样的错误。 Maybe it's not the good way ? 也许这不是好方法?

Thank you in advance. 先感谢您。

EDIT: The answer of JF Bastien helps me a lot. 编辑: JF Bastien的答案对我很有帮助。 But now I've this build error and I've any idea of what to do. 但是现在我遇到了这个构建错误,我知道该怎么做。 If someone have an idea... 如果有人有想法......

clang-3.7: warning: argument unused during compilation: '-msse2'
clang-3.7: warning: argument unused during compilation: '-mmmx'
error: unknown FP unit 'sse'

EDIT 2: Solution for above problem: remove "-msse2, -mmmx and -mfpmath" flags from v8/build/toolchain.gypi 编辑2:上述问题的解决方案:从v8 / build / toolchain.gypi中删除“-msse2,-mmmx和-mfpmath”标志

Porting to Emscripten is the same as porting to any other platform: you have to use that's platform's own platform-specific headers. 移植到Emscripten与移植到任何其他平台相同:您必须使用该平台自己的特定于平台的标头。 Some will have nice equivalents, and some won't. 有些会有很好的等价物,有些则不会。

In most cases you'll need to find these chains of platform-specific #if defined(...) and add an #elif defined(__EMSCRIPTEN__) , and do the right thing there. 在大多数情况下,您需要找到这些特定于平台的#if defined(...)#if defined(...)并添加#elif defined(__EMSCRIPTEN__) ,并在那里做正确的事情。 That's more complicated than it sounds: you can't do inline assembly, you can't rely on (most) platform-specific headers, ... But in some cases it's easy. 这比听起来更复杂:你无法进行内联汇编,你不能依赖(大多数)特定于平台的标题,......但在某些情况下它很容易。

Emscripten has examples which do this , and has a porting guide . Emscripten有这样做的例子 ,并有一个移植指南

For PDFium in particular, you'll have to avoid all the platform-specific font rendering, any threading-related things, and the sandboxing (security shouldn't be as big of an issue since JavaScript itself is a sandbox). 特别是对于PDFium,你必须避免所有特定于平台的字体渲染,任何与线程相关的东西以及沙盒(安全性不应该是一个大问题,因为JavaScript本身就是一个沙箱)。 You'll also have to figure out how to do file I/O, and probably want to disable all networking code. 您还必须弄清楚如何进行文件I / O,并且可能想要禁用所有网络代码。

Or you could use other ports of PDFium to Emscripten . 或者您可以使用其他PDFium端口到Emscripten

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM