Project

General

Profile

Runtime error "Unhandled exception" on test application - Windows - MSVC 2008 Express

Added by Leif Linse over 14 years ago

Hello,

The WT library looks very nice. I've always disliked building larger PHP applications since there is no compiler that tells you if you misspelled a variable somewhere. Creating unnecessary bugs to find. Also I really like the idea of abstracting the whole HTML + JavaScript part away from the logic. Something that I would have to write to some extent in PHP myself to make the projects maintainable. Being a long time C programmer, I'd be happy to use my knowledge of the language rather than starting from zero with .NET.

Too bad I have some issues to overcome with Wt before I can start building applications with it. My guess is that it is related to the linking, but let me lay out what I have done and what I've observed.

Installation

  1. I've installed Boost using the BoostPro installer. I've installed all needed sub-libraries, but only for Visual Studio 2008.

1b) I've made a copy of the boost directory that contains all the header files and put that folder in my 3rd-party include directory that is configured to be used by Visual Studio. The boost\lib directory has been added to Visual Studio configuration for places to look for library files.

2. I've installed CMake using the Windows installer.

3. I've downloaded the WT 3.0.0 sources.

4. Used CMake to configure it

- Specified boost path etc. (G:\Programming\Libraries\boost\boost_1_40)

  • I went for the httpd solution

5. Opened the solution file and compiled Wt along with all the examples

-> The compilation was completed successfully and the examples work

6. I've executed the INSTALL command/project in Visual Studio.

So far everything went well. (but there might be something wrong in the setup still)

Own projects

What I did next was to try to create my first project that would use the Wt library in httpd-mode. This is where everything have gone bad. :-) I've tried two different CMake setups and also the manual instructions of setting up your own build environment using in my case Visual Studio 2008 Express.

CMakeLists.txt

In my last try I used the CMakeLists.txt from the FAQ:

http://www.webtoolkit.eu/wt/wiki/index.php/Frequently_Asked_Questions#Q:*How_do_I_build_my_newly_written*.22Hello_World.21.22_application.3F

Changed the source file to main.cpp and the output file to wt_cmake.wt (my project name for this try is wt_cmake). The resulting CMakeLists.txt:

ADD_EXECUTABLE(wt_cmake.wt
main.cpp
)

# For FastCGI deployment:
#TARGET_LINK_LIBRARIES(wt_cmake.wt
#wtfcgi wt
#)

# Or, for built-in httpd deployment:
TARGET_LINK_LIBRARIES(wt_cmake.wt
wthttp wt
)

INCLUDE_DIRECTORIES(C:\Program\WT\include)

Configure + Build + Run

  1. CMake -> Generate solution file

2. Opened the generated solution file in Visual Studio.

3. Compiled

4. Hit F5 -> Start

Problem

Before even hitting the first line of code in main(...) an runtime error is caught:

Unhandled exception at 0x7c812afb in wt_cmake.wt.exe: Microsoft C exception: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injectorstd::runtime_error > at memory location 0x00fffad0..

There is no source code at this point and the call trace shows:

    kernel32.dll!7c812afb()     
    [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]  
    kernel32.dll!7c812afb()     
    msvcp90d.dll!10487c41()     
    msvcr90d.dll!102bd691()     
    msvcr90d.dll!102cff17()     
    msvcr90d.dll!102cff0e()     
    wt_cmake.wt.exe!boost::scoped_static_mutex_lock::lock()  + 0x19 bytes
    wt_cmake.wt.exe!boost::object_cache<unsigned long,boost::re_detail::w32_regex_traits_implementation<char> >::get()  + 0x69 bytes
    wt_cmake.wt.exe!boost::re_detail::create_w32_regex_traits<char>()  + 0x1b bytes
    wt_cmake.wt.exe!boost::re_detail::regex_data<char,boost::regex_traits<char,boost::w32_regex_traits<char> > >::regex_data<char,boost::regex_traits<char,boost::w32_regex_traits<char> > >()  + 0x6c bytes
    wt_cmake.wt.exe!boost::basic_regex<char,boost::regex_traits<char,boost::w32_regex_traits<char> > >::do_assign()  + 0x5f bytes
    wt_cmake.wt.exe!boost::basic_regex<char,boost::regex_traits<char,boost::w32_regex_traits<char> > >::basic_regex<char,boost::regex_traits<char,boost::w32_regex_traits<char> > >()  + 0x60 bytes
    wt_cmake.wt.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign()  + 0x85b92 bytes
    msvcr90d.dll!1023c02c()     
    wt_cmake.wt.exe!__tmainCRTStartup()  Line 501 + 0xf bytes
    wt_cmake.wt.exe!mainCRTStartup()  Line 403
    kernel32.dll!7c817077()     

How did it happen?

This is the first time I use Boost on the Windows platform so there might be something related to my boost installation?

I've just built WT once, but I noticed there is many different builds of boost, can it be that my program should be linked to a different kind of wt-build than I have built?


Replies (5)

RE: Runtime error "Unhandled exception" on test application - Windows - MSVC 2008 Express - Added by Leif Linse over 14 years ago

Forgot to include the main.cpp code. I have been able to slim it down to the following code. If I comment out the createApplication function and rebuild the program, then it will work and execute the code in main. (the code bellow gives the unhandled exception that I wrote about in my previous post)

#include <Wt/WApplication>

Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
    /*
     * You could read information from the environment to decide whether
     * the user has permission to start a new application
     */
    return new Wt::WApplication(env);
}

int main(int argc, char **argv)
{
    int i = 5; // some basic code to put a break point on
    i++;

    return 1;
}

RE: Runtime error "Unhandled exception" on test application - Windows - MSVC 2008 Express - Added by Wim Dumon over 14 years ago

Hello Leif,

It looks to me that you are indeed mixing msvc runtime libraries. Since your mail is so elaborate, I could reconstruct your situation (I used boost 1.38 but that shouldn't make the difference) and made some modifications.

First of all, let me clarify the (maybe not-so-well documented) fact that since Wt 3.0.0, we adopted the following naming scheme for our libraries (both on unix and windows):

non-debug libraries: wt.lib, wthttp.lib

debug libraries: wtd.lib, wthttpd.lib (they have a 'd' suffix)

On windows, non-debug libraries are linked against the non-debug msvc C/C runtime libraries; debug libraries are linked against the debug runtimes. Never mix within a single executable DLLs/libraries linked against different versions fo the runtime...

In order to use the correct version of the library, the CMakeLists.txt should now look like this:

INCLUDE_DIRECTORIES(
    "C:/Program Files/WT/include"
    "c:/Program Files/Boost/boost_1_38"
    )
LINK_DIRECTORIES(
    "C:/Program Files/WT/lib"
    "c:/Program Files/Boost/boost_1_38/lib"
    )

ADD_EXECUTABLE(wt_cmake.wt
    main.cpp
    )

# Or, for built-in httpd deployment:
TARGET_LINK_LIBRARIES(wt_cmake.wt
 optimized wthttp debug wthttpd
 optimized wt debug wtd
)

I recommend you to:

  1. Delete c:/Program Files/WT (the Wt installation directory) every time before you install a new version of Wt
  2. Build and install both Release and Debug versions of Wt (you can select this in the drop down box next to the run button in the msvc ide)
  3. Use the CMakeLists.txt above to build your own applications (the right Wt library will automatically be selected depending for release and debug builds)
  4. Always watch closely for linker warnings that mention the mixing of debug/release versions of CRT libraries

Let me know if this helps!

Regards,

Wim.

RE: Runtime error "Unhandled exception" on test application - Windows - MSVC 2008 Express - Added by Leif Linse over 14 years ago

Hi Wim,

Thank you for taking yourself time to reproducing my case and providing such high quality feedback on my problem. It is always a question if you are going to get help or scare people off by including much details.

I've removed the Wt installation (C:\Program( files)\Wt) and cleared the old build. Currently I'm compiling the debug + release version of wt after having re-generated the solution files. Hopefully this will solve my problems. If it is a mismatch between release and debug versions it explains why the examples worked but not my project. I'll report back later if I was able to solve the problem (and how) or not.

Off topic: Build message

One thing I saw the previous time when I compiled Wt, and also now when I re-compiled everything for both Debug and Release is this message (in the compile log for the 'wt' project):

..
..
Request.C
Client.C
Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
- add -D_WIN32_WINNT=0x0501 to the compiler command line; or
- add _WIN32_WINNT=0x0501 to your project's Preprocessor Definitions.
Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
WWidgetItem.C
WWidget.C
..
..

I don't know if maybe CMake would be capable of doing this detection? It is making a correct guess for me though.

Do you want me to create a bug issue in the tracker for this?

Regards,

Leif

RE: Runtime error "Unhandled exception" on test application - Windows - MSVC 2008 Express - Added by Leif Linse over 14 years ago

Hi again Wim,

The recompilation finished and my project compiles fine after changing the CMakeLists.txt file according to your suggestion.

What i did (for future reference):

  • I removed the existing installation C:\Program\Wt (corresponds to C:\Program files\Wt on the English version of Windows XP)
  • Cleaned the Wt 3.0.0 project using the clean command in Visual Studio
  • Re-generated the solution files with CMake
  • Built Debug & Release configuration of Wt
  • Installed both Debug & Release configuration of Wt

<!-- -->

  • Replaced the CMakeList.txt of my project with the one Wim provided above.
  • Changed the paths to Wt and boost to affect the paths on my system
  • CMake on my project
  • Built my project

<!-- -->

  • Now it works!

(I have an issue with the program arguments not getting sent to the program properly (argc == 1), but that might be related to not clearing the project files before generating the new one. That is anyway possible to work around by hard coding the arguments sent to WRun in main(..), which is still okay since they are easier to access there during the development.)

Thank you very much for your help.

Regards,

Leif

RE: Runtime error "Unhandled exception" on test application - Windows - MSVC 2008 Express - Added by Wim Dumon over 14 years ago

Leif,

Good to hear it works now.

As far as I understand the _WIN32_WINNT or _WIN32_WINDOWS warnings, it has to do with on what versions of windows you want to deploy your programs on. If you set this higher, the 'newer' functions of the api are also declared in the windows header files, but your executable will no longer run on the older versions of Windows. It is a typical windows thing, it has nothing special to do with Wt or boost (afaik), but boost asio does print an explicit warning about it.

See also: http://blogs.msdn.com/oldnewthing/archive/2007/04/11/2079137.aspx

Regards,

Wim.

    (1-5/5)