views:

716

answers:

5

Upon including <boost/thread.hpp> I get this exception:

First-chance exception at 0x7c812afb in CSF.exe: Microsoft C++ exception: 
boost::exception_detail::clone_impl<boost::exception_detail::bad_alloc_> at memory location 0x0012fc3c..
First-chance exception at 0x7c812afb in CSF.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000..

I can't catch it, breaking at the memory location brings me to kernel32.dll and at this point I cannot say what's going on but it appears that the exception is thrown after the program ends and VS is capable of catching it.

The testcase:

#include <boost/thread.hpp>

int main()
{
   return 0;
}

Compiler command line:
/I"I:\SophisPal\boost-1_43_0-vc10-32\include\boost-1_43" /Zi /nologo /W3 /WX- /O2 /Oi /Oy- /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm- /EHsc /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Fp"Release\Client.pch" /Fa"Release\" /Fo"Release\" /Fd"Release\vc100.pdb" /Gd /analyze- /errorReport:queue

Linker command line:
/OUT:"C:\Documents and Settings\user\my documents\visual studio 2010\Projects\CSF\Release\Client.exe" /INCREMENTAL:NO /NOLOGO "I:\SophisPal\boost-1_43_0-vc10-32\lib\libboost_system-vc100-mt-1_43.lib" "I:\SophisPal\boost-1_43_0-vc10-32\lib\libboost_date_time-vc100-mt-1_43.lib" "I:\SophisPal\boost-1_43_0-vc10-32\lib\libboost_regex-vc100-mt-1_43.lib" "I:\SophisPal\boost-1_43_0-vc10-32\lib\libboost_thread-vc100-mt-1_43.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Release\Client.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Documents and Settings\user\my documents\visual studio 2010\Projects\CSF\Release\Client.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /PGD:"C:\Documents and Settings\user\my documents\visual studio 2010\Projects\CSF\Release\Client.pgd" /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE

+1  A: 

I recommend trying to create a new, empty, Win32 Console Application (I usually check the "Empty Project" checkbox as well so as not to get precompiled headers and such for small projects).

Add a .cpp file to the project and give it your contents.

In the project properties, under C/C++ -> General, in the Additional Include Directories box, add the path to your top-level Boost folder (the one that contains the folder named boost that has all the header files). In my case, it's z:\dev\boost_1_43_0; based on your post, yours is probably I:\SophisPal\boost-1_43_0-vc10-32\include\boost-1_43.

Also in the project properties, under Linker -> General, in the Additional Library Directories box, add the path to the folder containing the compiled Boost libraries. On my PC, this is z:\dev\boost_1_43_0\lib; based on your post, yours is probably I:\SophisPal\boost-1_43_0-vc10-32\lib.

You don't need to explicitly tell the linker which libraries you want to link against; the Boost headers use one of the Visual C++ #pragma directives to tell the linker which libraries need to be used.

With just that, you should be able to build and run both Debug and Release configurations. I went through exactly these steps on and had no issues.

If that works, I'd start modifying the project, one option at a time, until it matches your current project's configuration. Eventually something will make it stop working, then you'll know what the problem is.

If that doesn't work, I'd look at downloading the Boost source and building it again.

James McNellis
Done that, and even tried to link to an older version of boost. Same exception.
the_drow
@the_drow: At that point, I'd consider trying on another machine or in a clean VM with the same source or uninstalling and reinstalling Visual Studio 2010. I'm fresh out of other ideas, sorry :(
James McNellis
+1  A: 

Some thoughts:

How do you know that the crash is occuring after main()?

What happens if you run from a debugger and configure VS to catch every exception (not just unhandled)?

Can you post a stack trace of the crash?

Assaf Lavie
I know because I see it happens AFTER my return 0. All I see is is some debug related memory code. How do I post the stack trace?
the_drow
You tell VS to break on SEH exceptions, and when the debugger breaks upon the crash you can see the stack trace. Alternatively you can trigger a crash dump and then analyze the dump in WinDbg or VS. Dr. Watson is probably the default post-mortem debugger, and it does just that (you just have to grab the dump file before it deletes it).
Assaf Lavie
+1  A: 

You should use a memory profiler like VLD (Windows) or Valgrind (Linux) to check if it can point to the bad allocation, maybe you have a version of the Boost library that contains an incompatibility bug with your current compiler and you might have to apply a fix.

TomWij
+2  A: 

This sounds like a mismatch between the Boost static libraries and the header files. How did you install boost? Did you run the bootstrap.bat on the machine to build it? Did you modify the boost header files after compilation? Do you have a library directory reference in the VS 2008 global settings to a directory containing a different version of the boost libraries?

Put another way, have you tried a clean install of boost with the libraries compiled with bootstrap.bat and have you deleted all other boost implementations on your machine? Until you've done that, you're working on a less-than-solid foundation.

If you still have trouble after that, have you tried going to Debug->Exceptions and turning on breaking on first-chance C++ and Win32 exceptions so that you can see the call stack in the debugger? If that doesn't work, have you tried using the Win32 API SetUnhandledExceptionFilter(), passing in a callback that uses the MiniDumpWriteDump() API of DBGHELP.DLL to write out a mini-dump (*.dmp) of the process to a file that you can then post-mortem debug using the VS 2010 debugger?

David Gladfelter
I don't know those functions. Got any links to explain how this is done.I got the libraries from a friend who compiled them on an exact machine but tried recompiling. It doesn't help
the_drow
MiniDumpWriteDump: http://msdn.microsoft.com/en-us/library/ms680360(VS.85).aspx, http://www.debuginfo.com/examples/effmdmpexamples.htmlSetUnhandledExceptionFilter: http://msdn.microsoft.com/en-us/library/ms680634(VS.85).aspx, http://www.debuginfo.com/articles/debugfilters.html
David Gladfelter
I wonder if the 'accepted' answer actually worked for the poster. I'm currently experiencing the same problem and I would appreciate some help :) http://stackoverflow.com/questions/3428177/boost-crash-when-linking-visual-studio-2008-express-mtd-setting
StackedCrooked
+2  A: 

This was by design in boost 1.43 but has been since fixed. See this thread for the details.

criddell