使用libmx链接并使用std::stringstream时发生g++malloc错误
g++ malloc error when linking with libmx and using std::stringstream
最简单的例子是下面的程序,链接到OS X Yosemite上的libmx(-lmx
)(用于MATLAB支持),使用g++4.9.1从macports:编译
#include <sstream>
int main()
{
std::ostringstream ostr;
// ostr << " "; // if I un-comment this line no more malloc error
}
我意识到,在ostr
销毁时(就在退出程序之前),我得到了一个malloc运行时错误,格式为:
testcpp(5362,0x7fff7d2af300) malloc: *** error for object 0x1055b6270:
pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug
另一方面,如果我取消对main()
中的第二行的注释,并向ostringstream
写入一些内容,那么程序将愉快地退出,不再出现错误。这种情况只发生在g++中,clang++编译并运行它没有任何问题。有人知道这是与g++
相关的问题还是与libmx
相关的问题吗?
PS:如果我在链接时没有使用-lmx
标志,那么就不会再有malloc错误了。
我想最好单独评论一下。正如我所说,我很难重现你的错误。我使用的是带有g++4.8.2的Ubuntu Linux 14.04 64位,我下载了Linux 64位的Matlab编译器运行时v83和v84。
我正在编译的源代码如下:
#include <sstream>
int main()
{
std::ostringstream ostr;
// ostr << " "; // if I un-comment this line no more malloc error
}
以下命令运行良好(2014 a和b):
g++ -L/opt/MATLAB/MCR/v83/runtime/glnxa64 -Wall malloc_gcc_matlab.cpp -o malloc_gcc_matlab && ./malloc_gcc_matlab
g++ -L/opt/MATLAB/MCR/v84/runtime/glnxa64 -Wall malloc_gcc_matlab.cpp -o malloc_gcc_matlab && ./malloc_gcc_matlab
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- Stringstream编译错误仅发生在linux环境中
- 错误 C2678:二进制">>":找不到采用类型为"std::stringstream "的左操作数的运算符
- 使用 Stringstream 将字符串解析为指针数组时出现分段错误错误
- 使用libmx链接并使用std::stringstream时发生g++malloc错误
- C++ 分词器变量中的错误'std::stringstream mystream'具有初始值设定项但类型不完整
- 使用"ifstream"、"stringstream"和"rdbuf()"将文件内容读取为字符串时如何检查I/O错误?
- 使用stringstream读取浮点值时出现奇怪的错误
- 使用自定义语言环境注入stringstream时会出现段错误