首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

linux下如何编译带有多个类的C++

2012-02-20 
linux下怎么编译带有多个类的C++?有这么多个文件:funclib.cppPASS.cppTRna.cppTState.cppTStates.cppfuncl

linux下怎么编译带有多个类的C++?
有这么多个文件:
funclib.cpp PASS.cpp TRna.cpp TState.cpp TStates.cpp
funclib.h TRna.h TState.h TStates.h

其中TRna,TState,TSates有相互include的关系. 
 PASS.cpp是含main()的程序
funclib.cpp是单独的函数库

程序在VC6里运行通过的.

在linux下试了下 g++ -c funclib.cpp -o funclib.o
有这几个错:
In file included from funclib.cpp:1:
funclib.h: In function `std::string& lTrim(std::string&)':
funclib.h:96: error: no matching function for call to `ptr_fun(<unknown type>)'
funclib.h: In function `std::string& rTrim(std::string&)':
funclib.h:103: error: no matching function for call to `ptr_fun(<unknown type>)'
In file included from funclib.cpp:1:


其中说到的两个函数是:
 inline string& lTrim(string &ss)  
{  
  string::iterator p=find_if(ss.begin(),ss.end(),not1(ptr_fun(isspace)));  
  ss.erase(ss.begin(),p);  
  return ss;  
}  

inline string& rTrim(string &ss)  
{  
  string::reverse_iterator p=find_if(ss.rbegin(),ss.rend(),not1(ptr_fun(isspace)));  
  ss.erase(p.base(),ss.end());  
  return ss;  
}  

再试了个: g++ -c TRna.cpp -o TRna.o
也很多错误,像这样的:
In file included from TStates.h:8,
  from TRna.h:9,
  from TRna.cpp:2:
funclib.h: In function `std::string& lTrim(std::string&)':
funclib.h:96: error: no matching function for call to `ptr_fun(<unknown type>)'
funclib.h: In function `std::string& rTrim(std::string&)':
funclib.h:103: error: no matching function for call to `ptr_fun(<unknown type>)'


我想可能是windows和linux下有些写法不一样, 不过我怎么知道linux下该怎么写呢?  
我才刚开始起C++,好不容易VC下能运行了,到linux下又这么多麻烦... 希望各位帮忙. 谢谢了.

[解决办法]
google "Makefile"
[解决办法]
学会写MPC文件

MSDN上有下载教程

MPC可以用来编译多个项目、多个工作工作空间


[解决办法]
这里的ptr_fun在哪个文件定义的?也在这个文件?
[解决办法]
因为vc6的for实现不标准 在括号里面定义的变量生存周期本应该只在for循环内的,即只在for语句里面可见
但是事实上它把这个生存周期扩展了
for (int i = 0; i < 100; i++) {}
i = 100; //vc下正确,在gcc下错误,提示i未定义

解决方法是定义一个宏
#define for if (0) {} else for
[解决办法]
#include<string>
#include<algorithm>

那个ptr_fun是stl的函数,具体哪个头文件忘了,你把第二个加上试试

热点排行