Boost C++ Libraries: Ticket #12017: Segfault with Boost program_options 1.60 debug libraries on OSX https://svn.boost.org/trac10/ticket/12017 <p> Hi, </p> <p> I'm using Boost 1.60.0_1 (installed from Brew) and am trying to compile the following file: </p> <pre class="wiki">//mytest.cpp: #include &lt;boost/program_options.hpp&gt; #include &lt;string&gt; namespace po = boost::program_options; int main(int argc, char *argv[]) { po::variables_map vm; po::options_description desc; desc.add_options() ("test,t", po::value&lt;std::string&gt;()-&gt;default_value("something")) ; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); return 0; } </pre><p> I'm using CMake to compile. When compiling in Release mode, everything works fine. But when compiling in Debug mode, i get a segfault in the store() function when I run the program without the -t option: </p> <pre class="wiki">(lldb) bt * thread #1: tid = 0x5f2ad5, 0x000000010001b9c3 mytest`boost::program_options::value_semantic_codecvt_helper&lt;char&gt;::parse(boost::any&amp;, std::__1::vector&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::allocator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt; &gt; const&amp;, bool) const [inlined] std::__1::vector&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::allocator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt; &gt;::size(this=0xffffffffffffffd5 size=0) const at vector:653, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xffffffffffffffd5) * frame #0: 0x000000010001b9c3 mytest`boost::program_options::value_semantic_codecvt_helper&lt;char&gt;::parse(boost::any&amp;, std::__1::vector&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::allocator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt; &gt; const&amp;, bool) const [inlined] std::__1::vector&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;, std::__1::allocator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt; &gt;::size(this=0xffffffffffffffd5 size=0) const at vector:653 frame #1: 0x000000010001b9c3 mytest`boost::program_options::value_semantic_codecvt_helper&lt;char&gt;::parse(this=0x0000000100103740, value_store=0x00007fff5fbff408, new_tokens=size=0, utf8=&lt;unavailable&gt;) const + 51 at value_semantic.cpp:45 frame #2: 0x000000010001934d mytest`boost::program_options::store(options=0x00007fff5fbff5c8, xm=0x00007fff5fbff6c8, utf8=&lt;unavailable&gt;) + 1207 at variables_map.cpp:125 frame #3: 0x0000000100000cad mytest`main + 445 frame #4: 0x00007fff92a5e5ad libdyld.dylib`start + 1 </pre><p> I noticed this happens only if the binary is linked with the static debug libraries, i.e libboost_program_options-d.a and libboost_program_options-mt-d.a. To reproduce without CMake: </p> <pre class="wiki">$ c++ mytest.cpp -I/usr/local/include /usr/local/lib/libboost_program_options-d.a -o mytest &amp;&amp; ./mytest [1] 83707 segmentation fault ./mytest $ c++ mytest.cpp -DDEBUG -I/usr/local/include /usr/local/lib/libboost_program_options-d.a -o mytest &amp;&amp; ./mytest [1] 83709 segmentation fault ./mytest </pre><p> It crashes only when run without the -t argument; If I provide it, it works fine: </p> <pre class="wiki">$ ./mytest -t test </pre><p> It does not crash when linked statically with a non-debug library: </p> <pre class="wiki">$ c++ mytest.cpp -DDEBUG -I/usr/local/include /usr/local/lib/libboost_program_options.a -o mytest &amp;&amp; ./mytest $ c++ mytest.cpp -DDEBUG -I/usr/local/include /usr/local/lib/libboost_program_options-mt.a -o mytest &amp;&amp; ./mytest </pre><p> Or when linked dynamically with one of the shared libraries: </p> <pre class="wiki">$ c++ mytest.cpp -I/usr/local/include /usr/local/opt/boost/lib/libboost_program_options.dylib -o mytest &amp;&amp; ./mytest $ c++ mytest.cpp -I/usr/local/include /usr/local/opt/boost/lib/libboost_program_options-mt.dylib -o mytest &amp;&amp; ./mytest </pre><p> The only workaround I found in order to compile a working debug binary with CMake is to use -DBoost_USE_STATIC_RUNTIME=ON because for some reason it tells the compiler to link with the shared library). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12017 Trac 1.4.3 anonymous Wed, 24 Feb 2016 17:28:14 GMT component changed; owner set https://svn.boost.org/trac10/ticket/12017#comment:1 https://svn.boost.org/trac10/ticket/12017#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Vladimir Prus</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">program_options</span> </li> </ul> Ticket dimansp@… Fri, 18 Mar 2016 02:25:33 GMT <link>https://svn.boost.org/trac10/ticket/12017#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12017#comment:2</guid> <description> <p> The same story when i'm using program_options 1_60 on Red Hat 4.1.2-44 (kernel version: 2.6.18-128.el5). But program_options 1_58 works perfect. </p> <p> I'm using the following command for compile boost: </p> <pre class="wiki">./b2 --with-program_options variant=release runtime-link=static link=static --stagedir=.. stage ./b2 --with-program_options variant=debug runtime-link=static link=static --stagedir=.. stage </pre> </description> <category>Ticket</category> </item> </channel> </rss>