linux 编译C++错误整理

本文总结了在将Windows项目迁移至Linux环境下编译C++时遇到的问题,包括链接器错误、Makefile语法、头文件缺失、函数声明错误等,并提供了相应的解决方案,如添加库链接、修正头文件包含、转换字符串类型等。
部署运行你感兴趣的模型镜像

我将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::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类型的转换到const char*。




您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值