资讯   |   开发   |   选机中心   |   产品大全 | IBM | 惠普 | 联想 | 戴尔 | 苹果 | 神舟
更多: | 华硕 | 明基 | 方正 | 紫光 | TCL | 夏新 | 联宝 | 宏碁 | 七喜 | 长城 | 清华同方 | 海尔 | 三星 | 东芝 | 索尼 | 富士通 | LG | 技术 | ddnoon
当前位置:笔记本 > 软件开发 >
Advertisement
文章正文

Linux下如何编译这个程序?

类型:转载   责任编辑:asp.net   日期:2007/05/23


热门软件下载:


   

///////////////////////////////////////  
  //  
  //             filename:   Tdate.h  
  //  
  //////////////////////////////////////  
  class   Tdate  
  {  
  public:  
  void   Set(int,int,int);  
          int   IsLeapYear();  
  void   Print();  
  private:  
  int   month;  
          int   day;  
  int   year;  
  };  
  ///////////////////////////////////////  
  //  
  //             filename:   Tdate.cpp  
  //  
  //////////////////////////////////////  
  #include   <iostream.h>  
  #include   "Tdate.h"  
   
  void   Tdate::Set(int   m,int   d,int   y)  
  {  
                      month=m;        
    day=d;  
    year=y;  
   
  }  
   
  int   Tdate::IsLeapYear()  
  {  
          return((year%4==0&&year%100!=0)||(year%400==0));  
  }  
   
  void   Tdate::Print()  
  {  
          cout<<year<<"-"<<month<<"-"<<day<<endl;  
  }  
  ///////////////////////////////////////  
  //  
  //             filename:   Test.cpp  
  //  
  //////////////////////////////////////  
  #include   <iostream.h>  
  #include   "Tdate.h"  
   
  void   SomeFunc(Tdate   *ps)  
  {  
        ps->Print();  
        if(ps->IsLeapYear())  
        cout<<"A   leap   year.\n";  
        else   cout<<"not   aleap   year.\n";  
  }  
   
  int   main(void)  
  {  
        Tdate   s;  
        s.Set(2,15,1998);  
         
        return   0;  
  }

网友回答:

发表者:winux0

g++   -o   test   test.cpp   Tdate.cpp

发表者:gettext

#   g++   Test.cpp   Tdate.cpp  
   
  #   g++   ch11_2.cpp   -o   ch11_2   Tdate.cpp  
   
 

发表者:blankman

g++   test.cpp   Tdate.cpp   -o   test    
   
  如果要分别检查的话    
  g++   -c   Tdate.cpp  
  g++   -c   test.cpp  
  这样只编译不连接

发表者:jacksg

g++   -c   Tdate.cpp   -o   libTdate.o  
  ar   rcs   libTdate.a   libTdate.o  
  cp   libTdate.a   /lib  
  g++   test.cpp   -o   test   -lTdate  
  这应该是你想要的结果吧。

发表者:jellen

把头文件里面的#include   <iostream.h>改成:    
  #include   <iostream>  
  using   namespace   std;  
   
  然后先编译TDate.cpp:   g++   -c   TDate.cpp生成TDate.o  
  再编译test.cpp:   g++   -c   test.cpp生成test.o  
  最后连接:g++   -o   test   test.o   TDate.o生成test可执行文件.


 

 
热门推荐笔记本: IBM笔记本
相关文章:
笔记本相关:
IT技术文章:
webmaster:popbb@126.com   最佳浏览:1024X768 MSIE
©2007 popbb.net All Rights Reserved