我想知道如何在Emscripten中使用
这是目前我所拥有的代码。
在Chrome中运行后,会调用preRun并出现错误。
此外,如果我尝试在编译时嵌入文件,使用以下命令:
FS
。我认为我已经做了维基中提到的所有事情,但仍然出现Uncaught ReferenceError: FS is not defined
。如果我在生成的*.js文件中搜索文字FS
,则没有出现,我认为应该有的。这是目前我所拥有的代码。
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
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
<!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并出现错误。
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文件中的第1460行http://pastebin.com/Mu1qfG25。 Module['FS_createDataFile']('/', 'gizmo.webm', [26, 69, 223,....]), true, true);
。FS从未插入到生成的js文件中。所以无论我如何调用FS,都没有用。是否有任何编译器选项需要添加以插入该库功能?