2

MAC では、コマンド ラインから C++ プログラムを正常にコンパイルできます。

  g++ *.cpp *.h -o executablename

ただし、Sublime 2 内からは失敗します。これを使用してビルド システムを作成しました。

 {
 "cmd" : ["g++", "*.cpp", "*.h", "-o", "executablename"]
 }

これらの結果で

 i686-apple-darwin11-llvm-g++-4.2: *.cpp: No such file or directory
 i686-apple-darwin11-llvm-g++-4.2: *.h: No such file or directory
 i686-apple-darwin11-llvm-g++-4.2: no input files
 [Finished in 0.0s with exit code 1]

ただし、プロジェクトで特定のファイル名を使用してビルド システムを作成すると、次のように機能します。

{
"cmd" : ["g++", "Test.cpp", "TestCode.cpp", "TestCode.h", "TestCode2.cpp", "TestCode2.h", "-o", "executablename"]
}

コマンドラインでできるように、コマンドラインパターンを使用して複数のファイルをコンパイルするビルドシステムをSublime 2で作成するにはどうすればよいですか?

4

2 に答える 2

0

おそらく次のようなものを使用する必要があります。

{
 "cmd" : ["gmake"]
}

または、make代わりにgmake. ただしgcc、GNU make がある場合は、同じディレクトリにある必要があります。以下の例のMakefileは GNU Make でテストされています。

ここに非常に原始的な Makefile があります。重要!MakefileGNU Makeが引数なしでそれを見つけるように名前を付ける必要があり、その中でインデントに実際のタブ文字を使用する必要があります(以下のg ++​​およびrmコマンドの前)。

CXXFLAGS := -Wall -Wextra $(CXXFLAGS) # example of setting compilation flags

# first rule is default rule, commonly called 'all'
# if there many executables, you could list them all
all: executablename

# we take advantage of predefined "magic" rule to create .o files from .cpp

# a rule for linking .o files to executable, using g++ to get C++ libs right 
executablename: TestCode.o TestCode2.o Test.o
    g++ $^ -o $@

# $^ means all dependencies (the .o files in above rule)
# $@ means the target (executablename in above rule)

# rule to delete generated files, - at start means error is ignored
clean:
    -rm executablename *.o

しかし、手書きの Makefile を使用することでさえ、最近では原始的と見なされる可能性があります。CMakeをインストールして使い方を学ぶべきでしょう。

于 2014-02-22T16:46:58.233 に答える