2013-02-24 118 views
4

我想知道如何在Emscripten中使用FS。我想我已经完成了维基中提到的所有事情,但我仍然得到Uncaught ReferenceError: FS is not defined。如果我搜索结果* .js文件的文字FS没有发生,我认为应该有。Emscripten使用Filesystem FS

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

InfoMedia.cpp

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

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

}// extern c 

[email protected]

init_fs.js与

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

结果编译

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

个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> 

铬预试运行此之后被调用,我得到的错误。

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

另外,如果我尝试嵌入在编译时一个文件

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

我得到这个错误Uncaught TypeError: Object #<Object> has no method 'FS_createDataFile'

这是我生成的js文件里面在该行http://pastebin.com/Mu1qfG25 @ line 1460 Module['FS_createDataFile']('/', 'gizmo.webm', [26, 69, 223,....]), true, true);

FS is n永远插入到生成的js文件中。所以无论我怎么称那个FS东西都没关系。有没有我需要添加的编译器选项来插入图书馆的功能?

回答

3

它死了简单。只需使用使用FS的函数,emscripten就会自动包含它。正如你可能在输出文件中看到的那样,尽管emscripten提供了比你在生成的输出文件中看到的更多的c库,但它并没有包含不必要的库函数。

作出明确认为,只要改变你的InfoMedia.cpp到:

#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