Note that there are some explanatory texts on larger screens.

plurals
  1. POboost::program_options gives malloc error
    primarykey
    data
    text
    <p>I have the following toy program that gives errors with the MacPorts gcc on OSX 10.6</p> <pre><code>#include &lt;boost/program_options.hpp&gt; namespace po = boost::program_options; #include &lt;iostream&gt; using namespace std; int main(int ac, char* av[]) { po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ; po::variables_map vm; po::store(po::parse_command_line(ac, av, desc), vm); po::notify(vm); if (vm.count("help")) { cout &lt;&lt; desc &lt;&lt; "\n"; return 0; } cout &lt;&lt; "Program continues\n"; return 0; } </code></pre> <p>I have boost version 1.52 installed with MacPorts. I compile the program as</p> <pre><code>g++ a.cpp -lboost_program_options-mt -L/opt/local/lib -g -O0 </code></pre> <p>It compiles fine:</p> <pre><code>$ ./a.out Program continues </code></pre> <p>But it cannot print the help message:</p> <pre><code>$ ./a.out --help Allowed options: a.out(40110) malloc: *** error for object 0x7fff70ca3500: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Abort trap </code></pre> <p>I've heard that stuff like this can happen if the libraries are compiled with a different version of gcc than the one used to build the program. How do I check for this? I have</p> <pre><code>$ g++ --version g++ (MacPorts gcc47 4.7.2_2) 4.7.2 </code></pre> <p><strong>Update</strong>: this seems to work on a Linux machine with and older Boost.</p> <p><strong>Update 2</strong>: the output of gdb follows</p> <pre><code>(gdb) run Starting program: /Users/yasir/Downloads/mask.util/a.out --help Reading symbols for shared libraries ++++.. done Allowed options: a.out(42256) malloc: *** error for object 0x7fff70ca3500: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Program received signal SIGABRT, Aborted. 0x00007fff821030b6 in __kill () (gdb) bt #0 0x00007fff821030b6 in __kill () #1 0x00007fff821a39f6 in abort () #2 0x00007fff820bb195 in free () #3 0x00000001001188b4 in std::basic_stringbuf&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::overflow () (gdb) </code></pre> <p><strong>Update 3</strong>: The program works fine with the Xcode gcc42, the problem only occurs with the MacPorts gcc.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload