使用Filesystem FS的脚本 [英] Emscripten using Filesystem FS

查看:141
本文介绍了使用Filesystem FS的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在Emscripten中使用FS.我认为我已经完成了Wiki中提到的所有操作,但是我仍然得到Uncaught ReferenceError: FS is not defined.如果我在生成的* .js文件中搜索文字FS,则不会发生,我认为应该会出现.

I am wondering how to use the FS in Emscripten. I think i have done all the things mentioned in the wiki, but i still get Uncaught ReferenceError: FS is not defined. If i search the resulting *.js file for the literal FS there is no occurrence, i thought there should be.

这是我到目前为止的代码.

here is the code i have so far.

InfoMedia.cpp

InfoMedia.cpp

#include <math.h>  //testing include
extern "C" {

// testing function
int int_sqrt(int x) {
  return sqrt(x);
}

}// extern c 

emcc -s EXPORTED_FUNCTIONS="['_int_sqrt']" InfoMedia.cpp -o InfoMedia.js

InfoMedia.js@pastebin

init_fs.js

init_fs.js

var Module = {
  'print': function(text){ 
    console.log(text) 
  },
  'preRun' : function(){
    console.log('prerun');
    FS.createPath('/', 'home/user1', true, true);
  },
  'noInitialRun': true,
};

excample.html

excample.html

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>InfoMediaJS-Example</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">    </script>
    <script type="text/javascript" src="init_fs.js"></script>
    <script type="text/javascript" src="InfoMedia.js"></script>
    <script type="text/javascript">
        run();
    </script>
</head>
<body></body>
</html>

在chrome中运行此命令后,会调用preRun,并且出现错误.

after running this in chrome preRun is invoked and i get the error.

prerun                                     init_fs.js:6
Uncaught ReferenceError: FS is not defined init_fs.js:7

此外,如果我尝试在编译时使用

In addition, if i try to embed a file at compile time with

emcc -s EXPORTED_FUNCTIONS="['_int_sqrt']" --embed-file gizmo.webm InfoMedia.cpp -o InfoMedia.js

我收到此错误Uncaught TypeError: Object #<Object> has no method 'FS_createDataFile'

它在此行 http://pastebin.com/Mu1qfG25 的我生成的js文件中@ 1460行 Module['FS_createDataFile']('/', 'gizmo.webm', [26, 69, 223,....]), true, true);

it is inside my generated js file at this line http://pastebin.com/Mu1qfG25 @ line 1460 Module['FS_createDataFile']('/', 'gizmo.webm', [26, 69, 223,....]), true, true);

FS永远不会插入到生成的js文件中.因此,无论如何称呼FS都无关紧要.我需要添加任何编译器选项以插入该库功能吗?

FS is never inserted into the resulting js file. So it doesn't matter how i call that FS stuff. Is there any Compiler option i need to add to insert that Library funktionality?

推荐答案

非常简单.只需使用使用FS的功能,emscripten就会自动包含它.您可能会在输出文件中看到,尽管emscripten提供的c库比在生成的输出文件中看到的要多得多,但其中没有包含不必要的库函数.

Its dead simple. Just use functions that use the FS and emscripten will automatically include it. As you may see in the output file, there are no unnecessary library functions included in it despite the fact that emscripten offers a lot more c libs than you see in the generated output file.

为了使思路清晰,只需将您的InfoMedia.cpp更改为:

to make thinks clear, just alter your InfoMedia.cpp to:

#include <math.h>  //testing include
#include <stdio.h>
extern "C" {

// testing function
int int_sqrt(int x) {
  printf ("Decimals: %d %ld\n", 1977, 650000L);  // use FS lib functionality
  return sqrt(x);
}

}// extern c

这篇关于使用Filesystem FS的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆