3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MacでEmscripten導入

Posted at

この記事は?

MacでEmscriptenを使えるところまでを紹介します。個人的なメモ用にも。

Emscriptenとは?

EmscriptenはC/C++言語からLLVMを生成し、それをJavaScriptに変換するコンパイラのことらしいです。qiitaの中でもちらほら記事があります。

実装環境

Mac OS 10.10.5で導入しました。Yosemiteの最新版です。

インストール

環境構築はいくつかやり方があるようですが、僕が試したのは下記の方法です。

Portable Emscripten SDK for Linux and OS Xをダウンロード

Portable Emscripten SDK for Linux and OS Xを公式サイトからダウンロードします。

解凍後、お好きな場所に移動します。

ターミナルでコマンドを実行

ターミナルを開き、先ほど解凍したディレクトリに移動します。
以下のコマンドを順番に実行します。ここは若干時間がかかります。

/emsdk update

ここでpythonのエラーが起きる場合があります。以前Canopyを試されたりしていると起きる人が多いようです。
解決方法はネット状にたくさんあるのでそちらを参考してください。僕の場合はCanopyを再インストールで解決しました。

./emsdk install latest
./emsdk activate latest

これで完了です。

コンパイルを試す

emsdk_portableディレクトリ内でmain.cかmain.cppのファイルを用意します。

適当なコードを記入してもらいます。
ファイル作成が完了後、Emscriptenでコンパイルします。
今回はmain.cppで試しました。
コードはシンプルに、hello worldです。

# include <iostream>
using namespace std;

int main() {
    cout << "Hello World" << endl;
    return 0;
}

それでは、Emscrptenを実行します。

emcc main.cpp -o index.html

これでディレクトリ内にindex.htmlが作成されます。またindex.jsもあります。

index.htmlを確認する。

以下の画像のように、hello worldが出力されるのが確認できると思います。

スクリーンショット 2016-07-13 20.34.08.png

できました。まずはここまでです。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?