2017-12-09 5 views
-2

私はメインファイルを追加したと確信していますが、なぜ私のcppファイルが削除されているのか、なぜこのエラーが出るのか分かりません。私は、端末に入力された G ++ -o assign8.cpp -lboost_system -lboost_thread誰かが私にこのエラーが何であるのか、なぜそれが私のcppファイルを削除しているのか説明できますか?

私は私のコードを追加することになりますが、ファイルが削除された

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 2 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 2 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 12 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 20 has invalid symbol index 20 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: In function `_start': 
(.text+0x20): undefined reference to `main' 
collect2: error: ld returned 1 exit status 
+1

出力ファイル( '-o _____')をソースファイル( 'assign8.cpp')に設定したので、上書きしました。コンパイルは、 'main'関数が見つからなかったので失敗しました。 'g ++ -o assign8 assign8.cpp ...'のように出力を正しく設定するだけです。 – hnefatl

+0

ハハ、これはもう一度攻撃する。私はそれがシェルタブの完成だと思う。それは1993年に私に起こった。その後、私は*常に*物をコンパイルするためのMakefileを書いた。 –

答えて

2

-o

あなたのような何かをコンパイルしたいです:g ++ -o assign8 assign8.cpp -lboost_system -lboost_thread assign8.cppはassign8.cppに書き込みますが、ほとんどあなたが望むものではありません。 .cppファイルは出力されません。

+0

ohありがとうございます。コードを書き直してみてください – straightson

0

これを避けるため、今後Makefileを使用する方法があります。メークファイルは複雑になる可能性がありますが、プログラミングを真剣にしたい場合は、あらゆる種類のビルドシステムを学ぶ必要があります。

次のコードは、ソースコードと同じディレクトリにあります。名前はMakefileである必要があります。首都Mは伝統的なものなので、必要だと思います。

CFLAGS += -g -O2 -Wall -W -pedantic 
CXXFLAGS = $(CFLAGS) -std=c++11 
CFLAGS += -pthread 
LDLIBS += -lboost_thread 
LDFLAGS += -pthread 

all: binary-file-read 

test1: test1.o test2.o 

あなたはそれを微調整する必要があります。 Makefilesについて知っているなら、明示的なビルドルールがないことに気付くでしょう。暗黙のルールに依存しています。私はちょうどそれが「バイナリファイル読み込み」を構築する必要がある「すべて」のビルド「作る」と入力すると「すべて」以来

は最初の目標です。 Makeは「バイナリファイルread.cpp」ファイルを用意しています。このファイルは、暗黙のルールを使ってビルドする方法を見つけ出します。これらのルールは、私が定義したすべての変数を使用します。

"test1"は、2つのオブジェクト ".o"ファイルから構築されます。ディレクトリには "test1.c"と "test2.c"があり、Makeファイルを.oファイルに組み込んで実行可能ファイルにリンクする方法を示しています。

ディレクトリはまた、「オプトtest.cの」という名前のファイルを持っていると私はタイプ「オプトインテストを行う」とのMakefileはまったく言及していないにもかかわらず、それを構築することが可能となります。

本当に便利です。

関連する問題