簡體   English   中英

與libmx鏈接並使用std :: stringstream時出現g ++ malloc錯誤

[英]g++ malloc error when linking with libmx and using std::stringstream

最簡單的示例是以下程序,該程序與OS X Yosemite上的libmx( -lmx )(用於MATLAB支持)鏈接,是使用macports中的g ++ 4.9.1編譯的:

#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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM