2016-05-23 5 views
-1

main.cppにするための簡単なテストファイルを持つコンパイルするために、異なる結果ができなくなります(重要性はない場合)、次のように:G ++オブジェクトファイル引数の位置の問題とは、通常

g++ -c -mx32 -o main.cpp.o -L/usr/libx32/ -lncurses main.cpp 

オブジェクトファイルが作成されます。その後私は、後続のコマンドで実行可能ファイルを作成し、テストし、削除:

rm test_ncurses 
g++ -o test_ncurses main.cpp.o -L. -lncurses -mx32 
./test_ncurses 

をしかし、私はやるとき:

g++ -o test_ncurses -L/usr/libx32/ -lncurses -mx32 main.cpp.o 

それは出力:

main.cpp.o: In function `main': 
/xxx/test_ncurses/main.cpp:12: undefined reference to `initscr' 
/xxx/test_ncurses/main.cpp:13: undefined reference to `cbreak' 
/xxx/test_ncurses/main.cpp:15: undefined reference to `stdscr' 
/xxx/test_ncurses/main.cpp:15: undefined reference to `keypad' 
/xxx/test_ncurses/main.cpp:19: undefined reference to `LINES' 
/xxx/test_ncurses/main.cpp:20: undefined reference to `COLS' 
/xxx/test_ncurses/main.cpp:21: undefined reference to `printw' 
/xxx/test_ncurses/main.cpp:22: undefined reference to `refresh' 
/xxx/test_ncurses/main.cpp:25: undefined reference to `stdscr' 
/xxx/test_ncurses/main.cpp:25: undefined reference to `wgetch' 
/xxx/test_ncurses/main.cpp:46: undefined reference to `endwin' 
main.cpp.o: In function `create_newwin(int, int, int, int)': 
/xxx/test_ncurses/main.cpp:53: undefined reference to `newwin' 
/xxx/test_ncurses/main.cpp:54: undefined reference to `box' 
/xxx/test_ncurses/main.cpp:57: undefined reference to `wrefresh' 
main.cpp.o: In function `destroy_win(_win_st*)': 
/xxx/test_ncurses/main.cpp:68: undefined reference to `wborder' 
/xxx/test_ncurses/main.cpp:80: undefined reference to `wrefresh' 
/xxx/test_ncurses/main.cpp:81: undefined reference to `delwin' 
collect2: error: ld returned 1 exit status 

私が行うときに同じことが起こります最初のコマンドで-cを省略すると、コンパイルは1ステップで終了します。 私は悩んでいます。それを正常にコンパイルすることはできません。

LDおよびg ++のバージョンがある:

GNU ld (GNU Binutils for Ubuntu) 2.26 
g++ -v 
Using built-in specs. 
COLLECT_GCC=g++ 
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper 
Target: x86_64-linux-gnu 
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.3.1-14ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu 
Thread model: posix 
gcc version 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2) 

答えて

1

これは完全に正常です。 g++またはgccへの引数の順番は、と大きく、ロットです。特に、任意の-lライブラリ引数(例えば、-lncurses ...)は、常にすべてのオブジェクトファイルの後に置かなければなりません。 thisとその他の回答を参照し、documentation of GCCを読んでください。

+0

私が知っていることは、実際には(-cを使用せずに)1回のパスでコンパイルすることができたが、実際にはそれを明らかにすることができないということです。 –

+0

その後、GCCのドキュメントを読むのに1時間ほどかかります。 –

+0

あなたの指示によると、私はg ++ -std = C++ 1z -mx32 -o test_ncurses main.cpp -L/usr/libx32/-lncursesをソースファイルの先頭に移動して再度コンパイルすることができました。私はオプションが最初に来て、Linuxで今見た他のコマンドのように引数が最後に来ると仮定していました。学ぶ時間。 –