以下程序以 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;
}
我使用Boost 1.46.1编译并链接了程序,我在OS X 10.6.7上将自己构建到/ usr / local中。我找不到任何已安装的libboost_program_options,而不是我所谓的(据称)链接。
知道造成这次崩溃的原因吗?
编辑:至于stacktrace,程序
#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
至于构建Boost:
$ 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++ ;
答案 0 :(得分:2)
我无法重现
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的参数。
答案 1 :(得分:1)
我想我解决了这个问题,但我对我的解决方案不满意。我忽略了提到我之前在/ usr / local中安装了带-program-suffix = -4.6的gcc 4.6.0。卸载它并重建Boost解决了这个问题。然后,除了gcc-4.0和gcc-4.2之外,我没有安装任何编译器。据推测,gcc-4.6文件干扰了gcc-4.0文件或darwin工具集。