現: 2020-12-26 (土) 15:07:43 yuji ソース
Line 1: Line 1:
 +#topicpath
 +#contents
 +* ARM用GCC [#hc8cec30]
 +[[ARM(Advanced RISC Machines)>http://www.arm.com/]]と呼ばれるCPUコアが組み込み機器分野などで非常に多く使われている。~
 +身近なところではほとんどのスマホに搭載されているCPUはARMです。~
 +Raspberry PiでもARMが使われています。
 +
 +WindowsマシンでRaspberry pi用のプログラムを開発する場合,ARMプロセッサーのクロスコンパイラであるtoolchainをWindowsマシンへインストールする。~
 +
 +このようなtoolchainに[[GNU C Compiler Collection>https://gcc.gnu.org/]]によるARM用のクロス開発環境があります。
 +
 +** Raspberry Pi用 ARM GCCをインストール [#t8a79236]
 +SysProgsの[[Windows toolchain for Raspberry Pi>http://gnutoolchains.com/raspberry/]]のサイトから,raspbian-jessie向けのraspberry-gcc4.9.2-r4.exeをダウンロードした。~
 +
 +ダウンロードしたファイルをダブルクリックしてインストール。~
 +デフォルトでC:\SysGCC\Raspberryにインストールされ,C:\SysGCC\Raspberry\binに実行PATHが通される。~
 +
 +このツールチェーン以外にも,ARM用ツールチェーンはいろいろあり無料で利用できる。~
 +[[armDevelopper>https://developer.arm.com/downloads/-/gnu-rm]]や[[CodeSourcery>http://www.codesourcery.com/sgpp/lite/arm/portal/subscription?@template=lite]]なんかが代表的。~
 +
 +* サンプルプログラムを作成してみる [#i9b14a15]
 +
 +HelloWorld.cppのソースファイルを作成する。
 + #include <cstdio>
 + int add(int x, int y) {
 +  return x + y;
 + }
 + 
 + int main() {
 +  int a = 5;
 +  int b = 4;
 +  int c = add(a, b);
 +  std::printf("Hello World %d\n", c);
 +  return 0;
 + }
 +
 +Makefileを以下の内容で作成する。
 + CROSS_COMPILE=arm-linux-gnueabihf-
 + 
 + TARGET=HelloWorld
 + 
 + all: $(TARGET)
 + 
 + $(TARGET): HelloWorld.cpp
 +  $(CROSS_COMPILE)gcc -O0 -g -o $@ $<
 + 
 + clean:
 +  rm -rf $(TARGET) *.o
 + 
 + rebuild: clean $(TARGET)
 +
 +** コンパイルしてみる [#se180b5f]
 + > make
 + > ls -la
 + total 17
 + drwxr-xr-x 2 yueno Administrators  4096 Mar 17 16:50 .
 + drwxr-xr-x 3 yueno Administrators    0 Mar 17 16:46 ..
 + -rw-r--r-- 1 yueno Administrators 10324 Mar 17 16:50 HelloWorld
 + -rw-r--r-- 1 yueno Administrators  179 Mar 17 16:47 HelloWorld.cpp
 + -rw-r--r-- 1 yueno Administrators  203 Mar 17 16:50 Makefile
 +HelloWorldという実行ファイルが無事作成された。
 +
 +出来た実行ファイルHelloWorldをRaspberry piにコピーして実行して確認します。
  

  • 開発/toolchain/ARM のバックアップ差分(No. All)
    • 現: 2020-12-26 (土) 15:07:43 yuji

トップ   差分 バックアップ 複製 名前変更 リロード   ページ新規作成 全ページ一覧 単語検索 最新ページの一覧   ヘルプ   最新ページのRSS 1.0 最新ページのRSS 2.0 最新ページのRSS Atom
Counter: 994, today: 2, yesterday: 0