linux 编译C++错误整理
我將windows下的項目修改為linux下時出現(xiàn)問題整理
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、錯誤:‘a(chǎn)bs’在此作用域中尚未聲明
加入#include <stdlib.h>?
5、?錯誤:‘vector’不是一個類型名
需要添加#include <vector>
using namespace std; //或者 using namespace std::vector;
6、對‘std::basic_ifstream<char>::open(std::string&)’的調(diào)用沒有匹配的函數(shù)
: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類型的轉(zhuǎn)換到const char*,string類型轉(zhuǎn)換為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 \
? ^
可以忽略此問題,根據(jù)提示在后面添加-Wno-deprecated
8、錯誤:‘runtime_error’不是‘std’的成員
<exception>?defines only the base?std::exceptionclass; 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類型的轉(zhuǎn)換到const char*。
總結(jié)
以上是生活随笔為你收集整理的linux 编译C++错误整理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Centos下 ffmpeg 和open
- 下一篇: java和C++的区别