2013-02-24 115 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