LoginSignup
21
17

More than 5 years have passed since last update.

[メモ] Visual C++ for linux Development を軽く使ってみた

Last updated at Posted at 2016-04-01

# orchelyさんの記事とかぶった... 無事動作することを祈ってます。

VC2015LinuxDev6.png

環境

  • Windows 10 (64bit)
  • Visual Studio 2015 Update 2 (Enterprise) 全部入りでインストール。
  • Linuxは、Ubuntu 14.04-64bit (build-essentialとか、いろんなパッケージが入ってる)

インストール

  1. Visual Studio 2015を開いて、
  2. ツール > 拡張機能と更新プログラム から
  3. オンライン を選んで
  4. CTRL+Eで、linux を検索
  5. Visual C++ for linux Development を[ダウンロード]
    VC2015LinuxDev1.png
  6. ブラウザ起動して、VC_Linux.exeがダウンロードされるので、それを[実行]
  7. Please close Visual Studio now to ~うんぬんとでてくるので、Visual Studioを閉じてから、[Continue] ... でインストール。
    VC2015LinuxDev2.png

Linux

必要なものをインストール
% sudo apt-get install openssh-server g++ gdb gdbserver

Getting Started

  1. VS2015 ファイル>新規作成 > プロジェクト 
    で、新しいプロジェクト ダイアログから、
  2. インストール済み>テンプレート>Visual C++>クロスプラットフォーム > Linux を選んで
  3. Console Application (Linux) をえらんで、
  4. (名前、場所、とか、かえたりしてもよい)
  5. [OK]
    VC2015LinuxDev3.png
  6. Getting Startedタブで、スクショつきで説明がある(英語だけど)
  7. main.cpp タブを選択して、 printf()行にカーソルを持ってきて、[F9]で赤丸つけて(ブレークポイントを張って)
  8. 上のとこで、[Debug] x64をえらんで、
  9. [F5]を押す。ビルドしますか => [はい(Y)]
  10. Connect to Linuxダイアルが出てくるので、接続先の情報を入れて、[Connect]
    VC2015LinuxDev4.png
  11. ブレークポイントで、停止
    VC2015LinuxDev5.png

このへんで使ったコードを使ってみる。

main.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;
}

VC2015LinuxDev6.png
いろいろ見れてますね。

一方、linux側では、こんなかんじ。スレッド[13242]の数字とgdbで検索。

user01@u1404:~⟫ ps aux | grep gdb
user01   13240  0.0  0.0  11884  1964 pts/2    S    18:24   0:00 gdbserver :4444 /home/user01/projects/ConsoleApplication1/bin/x64/Debug/ConsoleApplication1.out
user01   14461  0.0  0.0  15944  2184 pts/5    S+   18:26   0:00 grep --color=auto gdb
user01@u1404:~⟫ ps aux | grep 13242
user01   13242  0.0  0.0   4196   652 pts/2    t+   18:24   0:00 /home/user01/projects/ConsoleApplication1/bin/x64/Debug/ConsoleApplication1.out
user01   14482  0.0  0.0  15944  2228 pts/5    S+   18:26   0:00 grep --color=auto 13242
user01@u1404:~⟫ 

ん?

  • printfの出力って、どこにでる??
    (追記2016-07) => Debugメニュー > Linux Console で表示
21
17
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
21
17