LoginSignup
5
6

More than 5 years have passed since last update.

Visual C++ for Linux Developmentつかってみようとしたらハマったけど動いた

Last updated at Posted at 2016-03-31

Visual C++ for Linux Development

なにこれすげー!!!ってわけで使ってみよう。
Visual Studio から Linux マシンに接続してリモートデバッグできるみたい。

環境

  • Visual Studio Community 2015 Update 1
  • Windows 10 on VMware Fusion 7
  • Fedora 23 on VMware Fusion 7
  • Visual Studio Community 2015 Update 2
  • Windows 7 on 物理マシン
  • Fedora 23 on 物理マシン
  • 予め Linux には SSH でログインできるようにしておいてください。Fedora である必要はなく、SSH でログインできて、gdb と gdbserver が動けばよさそう。

Linux に必要なパッケージをインストール

$ sudo dnf install gcc-c++ gdb-server

Visual C++ for Linux Development をインストール

Visual Studio Community 2015 Update 1 にエクステンションの Visual C++ for Linux Developmentをインストールする。ちょっと時間かかった。

インストールが終わると、新規プロジェクトテンプレートに Consolel Application (Linux) が追加されている!

キャプチャ.PNG

ラズパイ用のテンプレートもある。

プロジェクト作成

そのまま Console Application (Linux) を作ると printf するだけのプロジェクトが作られる。

キャプチャ2.PNG

ビルド

ビルドしようとすると Linux マシンへの接続情報を入力するダイアログボックスるが現れるのでよしなに入力する。鍵認証の場合は putty 形式っぽい。

キャプチャ3.PNG

上の環境の説明で打ち消し線の組み合わせだとどうも接続できなくてここで詰まった。

あきらめて物理マシンを用意すると試すと成功し、cygwin の file から次のように見える ELF バイナリが生成された。

キャプチャ4.PNG

実行 -> 失敗

実行しようとすると Visual Studio の実行ペインに次のエラーが出て実行できなかった

=thread-group-added,id="i1"GNU gdb (GDB) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i586-pc-mingw32msvc --target=x86_64-pc-linux-android".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Loaded 'shared libraries loaded at this time.'
Exception condition detected on fd 512
=thread-group-exited,id="i1"

恐らく x86-64 Linux ターゲット用の gdb ではなく、Visual Studio をフルオプションでインストールしたために入っている Android ターゲット用の gdb が起動してしまっているのだと思われる。
これは原因ではなかった。成功した場合もこの gdb が使われていた。

再インストール -> 失敗

ここまでは Visual Studio Community 2015 Update 1 でやっていたが、よくわからないので、

  • Windows 7 を物理マシンにクリーンインストール
  • Visual Studio 2015 Community Update 2 を標準構成でインストール

してから Visual C++ for Linux Development をインストールしようとしたところ、

キャプチャ.PNG

と言われた。ここで入れろといわれているものだけを入れても同じエラーがでたので、VS をフルインストールしてから Visual C++ for Linux Development をインストールしたらちゃんとビルドできて実行できた。そのときのログ:

=thread-group-added,id="i1"GNU gdb (GDB) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i586-pc-mingw32msvc --target=x86_64-pc-linux-android".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Loaded 'shared libraries loaded at this time.'
=thread-group-exited,id="i1",exit-code="0"プログラム '' はコード 0 (0x0) で終了しました。

このログにも --target=x86_64-pc-linux-android と出ているので Android ターゲット用の gdb が使われるのは正しい様子。

まとめ

結構はまったけど、物理マシンに
1. Windows 7 をクリーンインストール
2. Visual Studio 2015 Community Update 2 をフルインストール
3. Visual C++ for Linux Development
して、Fedora 23 をインストールした物理マシンに接続したらちゃんと動いた。途中で失敗していたのは VS2015 Update 1 だったためかもしれないが、ウラはとっていない。

5
6
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
5
6