0
0

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 3 years have passed since last update.

VisualStudio C++ #ifdef をビルド時に切替

Last updated at Posted at 2020-11-05

VisualStudio C++ #ifdef をビルド時に切替

目的

「#ifdef _HOGE」を C++ のソースファイルを変更せずに切替したい。

複数のプロジェクトで、下記のように「#define _HOGE」のコメントアウトを付けたり外したりしたくない。

Hoge.cpp
// _HOGE 使わない時は、コメントアウト
# define _HOGE

# ifdef _HOGE
・・・中略・・・
# else
・・・中略・・・
# endif // _HOGE

・・・後略・・・

環境

Windows 10 Pro
Visual Studio 2017

ソリューションの設定

下記URLの記事を参考に
「構成」"Debug"をコピーして「構成」"D_HOGE"を追加。

VS.NETでデバッグ版/リリース版以外のビルド構成を追加するには?
https://www.atmarkit.co.jp/fdotnet/dotnettips/249addprojconf/addprojconf.html

プロジェクト毎の設定

下記URLの記事を参考に
「構成」"D_HOGE"の
「プロジェクト」「プロパティ」の
「構成プロパティ」「C/C++」「プリプロセッサ」「プリプロセッサの定義」にて
"_HOGE;"を追加。

コンパイラとビルドのプロパティを設定する
https://docs.microsoft.com/ja-jp/cpp/build/working-with-project-properties?view=msvc-160

ソリューションに「プリプロセッサの定義」があったら、もっと嬉しかったのですが。

プロジェクトはこのソリューション構成に対してビルドするように選択されていません。

【VisualStudio】特定プロジェクトのビルドが飛ばされる
https://shirakamisauto.hatenablog.com/entry/2016/07/18/103947

以上

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?