2017-04-11 13 views
-1

ここには単純なC++プログラムがあり、動作するはずです。私のコードはここからの参照です。 Convert command line argument to string文字列を含むときにコンパイルできない

#include <stdio.h> 
#include <stdlib.h> 
#include <string> 
#include <vector> 
#include <iostream> 


//using namespace std; 


int main(int argc, char *argv[]){ 

std::string boss; 
//printf("PROGRAM NAME: %s\n", argv[0]); 


if (argc > 1){ 
    //printf("%s\n",&argv[1][0]); 
    printf("%s\n",argv[1]); 
    boss = argv[1]; 
} 

} 

コンパイルが、それは問題が出てくるとき:

/tmp/cctYLBpB.o:機能でmain': testarg.cpp:(.text+0x1c): undefined reference toのstd ::のbasic_string、STD ::アロケータ> ::のbasic_string()」 testarg。 cpp :(。テキスト+ 0x58):未定義参照std::string::operator=(char const*)' testarg.cpp:(.text+0x64): undefined reference to std :: basic_string、std :: allocator :: :: basic_string() ' testarg.cpp :(。テキスト+ 0x78):未定義参照std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' testarg.cpp:(.text+0x7c): undefined reference to __cxa_end_cleanup' /tmp/cctYLBpB.o:関数__static_initialization_and_destruction_0(int, int)': testarg.cpp:(.text+0xc0): undefined reference to std :: ios_base :: Init :: Init() ' testa rg.cpp :(テキスト+ 0xe4):未定義の参照std::ios_base::Init::~Init()' /tmp/cctYLBpB.o:(.ARM.extab+0x0): undefined reference to __gxx_personality_v0' に collect2は:エラー:ldが返さ1つの終了ステータス

は君たちの専門家をやって上の任意の問題を見ていましたか?私は考えていません...

+0

プログラムの作成に使用したコマンドは何ですか? –

+0

私がコンパイルするコマンドはgcc "filename"です.cpp -o testc –

+1

コンパイル/ビルドには 'g ++'を使います。 –

答えて

3

gccを使用してプログラムをビルドすると、標準のC++ライブラリはリンカーによって使用されません。代わりにg++を使用してください。良い測定のために-Wallを加えてください。実行時にコンパイル時に問題を見つけるのではなく、コンパイル時に問題を見つけるのに役立つ有用な警告メッセージが表示されます。

g++ filename.cpp -Wall -o testc 
+1

'-Werror'はクリアなコードに適しています – Sild

関連する問題