开发者

boost::program_options::positional_options_description termination

The following program aborts with 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;
}

I compiled and linked the program with Boost 1.46.1, which I built myself into /usr/local, on OS X 10.6.7. I can't find any installed libboost_program_options other than the one I'm (supposedly) linking against.

Any idea what causes this crash?


Edit: As for stacktrace, the program

#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);开发者_如何学Go
    for (i = 0; i < frames; ++i) {
        printf("%s\n", strs[i]);
    }
    free(strs);
    return 0;
}

built as

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 

and run as ./sandbox produces the output

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

As for building Boost:

$ cd boost_1_46_1
$ ./bootstrap.sh --prefix=/usr/local
$ ./bjam toolset=darwin-4.2

And here's my ~/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++ ;


I am unable to reproduce

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$ 

you should update your question with the steps you used to build boost, particularly the arguments to bjam.


I think I resolved the issue, but I'm not happy with my solution. I neglected to mention that I previously installed gcc 4.6.0 with --program-suffix=-4.6 in /usr/local. Uninstalling it and rebuilding Boost solved the issue. I then had no compilers installed other than gcc-4.0 and gcc-4.2 which came with XCode. Presumably gcc-4.6 files interfered with gcc-4.0 files or the darwin toolset.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜