第一次使用g++

比較幸運,嘗試了幾次就OK了。

 

g++ -c file_1.cpp

g++ -c file_2.cpp

g++ -c file_3.cpp

 

g++ -o file_4.out file_1.o file_2.o file_3.o file_4.cpp

 

 

參考文獻:http://homepages.gac.edu/~mc38/2001J/documentation/g++.html

Running the compiler

You can use g++ both to compile programs into object modules and to link these object modules together into a single program. It looks at the names of the files you give it to determine what language they are in and what to do with them. Files of the form name.cc (or name.cpp) are assumed to be C++ files and files matching name.o are assumed to be object (i.e., machine-language) files. To translate a C++ source file, file.cc, into a corresponding object file, file.o, use the g++ command:
  g++ -c compile-options file.cc
To link one or more object files, file1.ofile2.o, ..., to produced from C++ files into a single executable file called prog, use the following command:
  g++ -o prog link-options file1.o file2.o ... other-libraries
(The options and libraries clauses are described below.)

You can bunch these two steps---compilation and linking---into one with the following command.

  g++ -o prog compile-and-link-options file1.cc file2.cc ... other-libraries
After linking has produced an executable file called prog, it becomes, in effect, a new Unix command, which you can run with
  ./prog arguments

where arguments denotes any command-line arguments to the program

 

 

發佈了35 篇原創文章 · 獲贊 1 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章