下面的程序使用pointer being freed was not allocated
中止
#include <boost/program_options.hpp>
int main(int argc, char* argv[])
{
boost::program_options::positional_options_description positional;
return 0;
}
我在OSX10.6.7上编译了该程序并将其与Boost 1.46.1连接起来,我将其内置到/usr/local中。我找不到任何已安装的libboost_program_options,除了我(应该)链接的那个。
知道是什么导致了这次坠机吗?
编辑:关于堆栈跟踪,程序
#include <boost/program_options.hpp>
#include <execinfo.h>
int main(int argc, char* argv[])
{
boost::program_options::positional_options_description positional;
void* callstack[128];
int i, frames = backtrace(callstack, 128);
char** strs = backtrace_symbols(callstack, frames);
for (i = 0; i < frames; ++i) {
printf("%s\n", strs[i]);
}
free(strs);
return 0;
}
建为
g++ -Wp,-MMD,.make-debug/main.dd -Wall -g3 -I/usr/local/include -c main.cc -o .make-debug/main.o
g++ -o sandbox .make-debug/main.o -lboost_program_options -L/usr/local/lib
并在./sandbox生成输出时运行
0 sandbox 0x00000001000017bf main + 57
1 sandbox 0x0000000100001764 start + 52
2 ??? 0x0000000000000001 0x0 + 1
sandbox(50587) malloc: *** error for object 0x7fff70506500: pointer being freed was not al
located
*** set a breakpoint in malloc_error_break to debug
Command terminated
至于建造助推器:
$ cd boost_1_46_1
$ ./bootstrap.sh --prefix=/usr/local
$ ./bjam toolset=darwin-4.2
这是我的~/user-config.jam:
using darwin : 4.0 : g++-4.0 ;
using darwin : 4.2 : g++-4.2 ;
using darwin : 4.5.1 : /Users/matan/usr/bin/g++ ;
发布于 2011-05-16 01:02:02
我无法复制
macmini:stackoverflow samm$ cat po.cc
#include <boost/program_options.hpp>
#include <boost/version.hpp>
#include <iostream>
int
main(int argc, char* argv[])
{
std::cout << BOOST_LIB_VERSION << std::endl;
boost::program_options::positional_options_description positional;
return 0;
}
macmini:stackoverflow samm$ g++ -I /opt/local/include -L/opt/local/lib -lboost_program_options po.cc
macmini:stackoverflow samm$ ./a.out
1_46_1
macmini:stackoverflow samm$
您应该用构建boost的步骤来更新您的问题,特别是bjam的参数。
发布于 2011-05-21 19:35:55
我想我解决了这个问题,但我对我的解决办法不满意。我没有提到,我以前安装了gcc 4.6.0,带有--程序后缀=-4.6 in /usr/local。卸载和重建Boost解决了这个问题。然后,除了XCode附带的gcc-4.0和gcc-4.2之外,我没有安装任何编译器。据推测,gcc-4.6文件干扰gcc-4.0文件或达尔文工具集.
https://stackoverflow.com/questions/6012337
复制相似问题