2
2

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.

NetBeansからMSYS2のgccを使う

Last updated at Posted at 2015-05-05

NetBeansからMSYS2のgccを使うといくつか問題が起きます。

  • NetBeansがMSYS2を自動認識しない
  • パスが通らない
  • 文字化けする

パスと環境変数を設定するラッパーを用意することで解決を試みました。

※ 公式な手段があるのかもしれませんが、不明なので力技です。

ラッパー

次のようなファイルを作成します。

※ MSYS2のインストール先が異なる場合はUSRを適宜修正してください。

make-wrap.cpp
# include <stdlib.h>
# include <unistd.h>
# include <string>
# include <vector>

# define USR "C:\\msys64\\usr"

std::string lower(const std::string &s) {
	std::string ret;
	for (int i = 0; i < s.size(); i++) {
		char ch = s[i];
		if ('A' <= ch && ch <= 'Z') ch += 32;
		ret += ch;
	}
	return ret;
}

int main(int argc, const char *argv[], const char *envp[]) {
	const char *make = USR"\\bin\\make.exe";
	argv[0] = make;
	std::vector<const char *> envs;
	std::string path;
	for (int i = 0; envp[i]; i++) {
		std::string e = envp[i];
		std::string e5 = lower(e.substr(0, 5));
		if (e5 == "path=") {
			path = "PATH="USR"\\bin;"USR"\\local\\bin;" + e.substr(5);
			envs.push_back(path.c_str());
		} else if (e5 != "lang=") {
			envs.push_back(envp[i]);
		}
	}
	envs.push_back("LANG=C");
	envs.push_back(NULL);
	return execve(make, const_cast<char **>(argv), const_cast<char **>(&envs[0]));
}

コンパイルしてMSYS2のルートに置きます。DLLに依存しないよう、Win32ネイティブでスタティックリンクします。

$ x86_64-w64-mingw32-g++ -static -s -o /make-wrap make-wrap.cpp

※ 要 pacman -S mingw-w64-cross-gcc

NetBeansの設定

NetBeansで環境を設定します。

プラグインの確認

C/C++プラグインがインストールされているか確認します。

ツール → プラグイン

NetBeans1.png

インストールされていなければ、インストールしてください。

NetBeans2.png

プラグインの設定

ツール → オプション → C/C++ → [追加]

NetBeans3.png

ベース・ディレクトリとツール・コレクション・ファミリを選択 → [OK]

NetBeans4.png

※ CygwinやMinGWを選択するとうまく動かないためInterixを指定しています。

CコンパイラとC++コンパイラとmakeコマンド(先ほど作成したラッパー)を指定

NetBeans5.png

コード支援 → インクルード・ディレクトリで...\usr\usr\includeを変更 → 重複する\usrを取り除く

NetBeans6.png

C++コンパイラについても同様に処置 → [OK]

NetBeans7.png

以上で設定は完了です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?