最初の第2メイクファイルは、私が実際にC++プロジェクトを開始する前に理解しておく必要があるためです。makefilesの最初の試行
/storage/emulated/0/cpptest/test.h
#ifndef TEST_H_DEF
#define TEST_H_DEF
class Test {
private:
int value;
public:
Test(int);
operator int();
Test operator + (Test);
};
#endif
/storage/emulated/0/cpptest/test.cpp
#include "test.h"
Test::Test(int new_value):
value(new_value) {}
Test::operator int() {
return value;
}
Test Test::operator + (Test other) {
return Test(value + int(other));
}
:ここで私はリンクをしようとしているファイルです
:
/storage/emulated/0/cpptest/main.cpp
#include <iostream>
#include "test.h"
int main() {
Test o1(12);
Test o2(18);
std::cout << int(o1) << '\n';
std::cout << int(o2) << '\n';
std::cout << int(o1 + o2) << std::endl;
}
そして、ここでは(保守性)メイクファイルでの私の試みです
CC = g++
default: test
#I'm actually using four spaces here on SO
test: main.o test.o
$(CC) -o test main.o test.o
#my issue starts here: what does main.o depends on? My guess is main.cpp only (which is really /storage/emulated...main.cpp)
main.o: main.cpp
$(CC) -o main.o /storage/emulated/0/cpptest/main.cpp
#same with test.o
test.o: test.cpp
$(CC) -o test.o /storage/emulated/0/cpptest/test.cpp
次に?今は大丈夫ですか?どのように私はそれについて知っていることなく更新されているtest.hの問題を処理するのですか?
私のファイルを書いている間に、.hと.cppファイルの使用を取得しましたか?
もしあなたが単にC++を使用しようとしていて、makefile上で実際に修正されていないのであれば、ネイティブメイクファイルの代わりにcmakeをお勧めします。たくさんのことが楽になります。 – Hayt
.h依存関係については、ファイルが 'test.o'ルールの依存関係に追加されていれば動作しますか? – Pierre
どのように私はmakefileで修正できますか?私は今朝までメイクファイルの使い方を知らなかった:/それぞれのメリットは? – user6245072