1

マルチファイルC++プログラムをコンパイルしようとしていますが、次のエラーが発生します。

Undefined symbols for architecture i386:
  "included::printMSG()", referenced from:
      _main in ccQwMj1l.o
ld: symbol(s) not[Finished in 0.3s with exit code 1] found for architecture i386
collect2: ld returned 1 exit status

私のコード:main.cpp:https ://gist.github.com/3845822

include.cpp:https ://gist.github.com/3845825

include.h:https ://gist.github.com/3845827

(で動作することが確認されましたg++

編集:私はこれらのファイルをプロジェクトに入れていません、それらはすべて同じフォルダーにあり、私はコンパイルしていますmain.cpp

4

1 に答える 1

1

単一のファイルをコンパイルするだけで、他のすべてのファイルが自動的にそのファイルにリンクされて最終的なプログラムが作成されることを期待することはできません。

これを実現する1つの方法は、次のルールを持つmakeを読み取る、と呼ばれるプログラムを使用することです。Makefilemake

単純なものは次のMakefileようになります。

CXXFLAGS = -Wall -g

my_pogram: main.o other_file.o third_file.o
    g++ main.o other_file.o third_file.o -o my_program

main.o: main.cpp
    g++ $(CXXFLAGS) -c -o main.o main.cpp

other_file.o: other_file.cpp
    g++ $(CXXFLAGS) -c -o other_file.o other_file.cpp

third_file.o: third_file.cpp
    g++ $(CXXFLAGS) -c -o third_file.o third_file.cpp

これを処理する他の同様のプログラムがあります。人気のあるのはCMakeです。

于 2012-10-06T19:47:10.750 に答える