我将windows下的项目修改为linux下时出现问题整理
1、undefined reference to `__gxx_personality_v0'
需要-l libstdc++
2、 makefile::*** 遗漏分隔符
makefile中命令前要有tab,否则会报错
3、tchar.h:没有那个文件或目录
在linux下没有tchar.h这个文件,可以自己写一个
#if defined(__BORLANDC__) && !defined(_TCHAR_DEFINED) typedef _TCHAR TCHAR, *PTCHAR; typedef _TCHAR TBYTE, *PTBYTE; #define _TCHAR_DEFINED #endif
4、错误:‘abs’在此作用域中尚未声明
加入#include <stdlib.h>
5、 错误:‘vector’不是一个类型名
需要添加#include <vector>
using namespace std; //或者 using namespace std::vector;
6、对‘std::basic_ifstream<char>::open(std::string&)’的调用没有匹配的函数
:void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]
open(const char* __s, ios_base::openmode __mode = ios_base::in)
no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘const char*’
从上述报错来看需要把string类型的转换到const char*,string类型转换为const char* 只需在后面添加.c_str()即可。
7、:#warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]
#warning \
^
可以忽略此问题,根据提示在后面添加-Wno-deprecated
8、错误:‘runtime_error’不是‘std’的成员
<exception>
defines only the base std::exception
class; if you want child classes like std::runtime_error
, you must include the <stdexcept>
header.
需要添加#include <stdexcept>
9、std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]
basic_ofstream(const char* __s,
^
/usr/local/include/c++/4.8.1/fstream:640:7: 附注: no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘const char*’
/usr/local/include/c++/4.8.1/fstream:625:7: 附注:std::basic_ofstream<_CharT, _Traits>::basic_ofstream() [with _CharT = char; _Traits = std::char_traits<char>]
basic_ofstream(): __ostream_type(), _M_filebuf()
与6错误一样,把string类型的转换到const char*。