Project

General

Profile

Actions

Support #7331

closed

Debug Mode Crashes with this FindWt.cmake

Added by Joel Leagues over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
11/16/2019
Due date:
% Done:

0%

Estimated time:

Description

Windows Release mode builds and runs successfully

Windows Debug mode crashes

I use the following CmakeLists.txt to successfully run and build in release mode

cmake_minimum_required(VERSION 3.10)

SET(THIS MAIN)   # << -------------------------------------------
project (${THIS})

#set(BUILD_TYPE Release) # << -------------------------------------------
set(BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE ${BUILD_TYPE})

set(BUILD_DIR ${CMAKE_SOURCE_DIR}/Solution)
set(INC       ${BUILD_DIR}/include)
set(SRC       ${BUILD_DIR}/src)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};C:/Program Files/wt/lib/cmake/wt;C:/Program Files/wt/lib/cmake;C:/Program Files/wt/lib/cmake/wt")
set(CMAKE_PREFIX_PATH  "${CMAKE_PREFIX_PATH};C:/Program Files/wt/lib/cmake/wt;C:/Program Files/wt/lib/cmake;C:/Program Files/wt/lib/cmake/wt")
# set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};C:/Source/CMake/Modules")

include_directories(${CMAKE_CURRENT_BINARY_DIR} ${INC}) 
set(CMAKE_CONFIGURATION_TYPES ${BUILD_TYPE} CACHE STRING "" FORCE)

add_executable(${THIS}

    ./Solution/include/Form.h
    ./Solution/include/FormExample.h
    ./Solution/src/Form.cpp
    ./Solution/src/FormExample.cpp
)
FIND_PACKAGE(Wt REQUIRED)

And the FindWt.cmake below works.

I tried many online fancy FindWt.cmakes and they all failed so I had to do it the simple way.

cmake_minimum_required(VERSION 3.10)

set(LIB Wt)

# add this after "add_executable(${THIS}...)"

include_directories(${THIS} PUBLIC

    "C:/Program Files/Wt/include"
)

target_link_libraries(${THIS}
    "C:/Program Files/Wt/lib/libcrypto.lib"        
    "C:/Program Files/Wt/lib/libcryptod.lib"       
    "C:/Program Files/Wt/lib/libhpdf.lib"
    "C:/Program Files/Wt/lib/libhpdfd.lib"
    "C:/Program Files/Wt/lib/libssl.lib"
    "C:/Program Files/Wt/lib/libssld.lib"
    "C:/Program Files/Wt/lib/wt.lib"
    "C:/Program Files/Wt/lib/wtd.lib"
    "C:/Program Files/Wt/lib/wtdbo.lib"
    "C:/Program Files/Wt/lib/wtdbod.lib"
    "C:/Program Files/Wt/lib/wtdbofirebird.lib"
    "C:/Program Files/Wt/lib/wtdbofirebirdd.lib"
    "C:/Program Files/Wt/lib/wtdbomssqlserver.lib"
    "C:/Program Files/Wt/lib/wtdbomssqlserverd.lib"
    "C:/Program Files/Wt/lib/wtdbomysql.lib"
    "C:/Program Files/Wt/lib/wtdbomysqld.lib"
    "C:/Program Files/Wt/lib/wtdbopostgres.lib"
    "C:/Program Files/Wt/lib/wtdbopostgresd.lib"
    "C:/Program Files/Wt/lib/wtdbosqlite3.lib"
    "C:/Program Files/Wt/lib/wtdbosqlite3d.lib"
    "C:/Program Files/Wt/lib/wthttp.lib"
    "C:/Program Files/Wt/lib/wthttpd.lib"
    "C:/Program Files/Wt/lib/wtisapi.lib"
    "C:/Program Files/Wt/lib/wtisapid.lib"
    "C:/Program Files/Wt/lib/wttest.lib"
    "C:/Program Files/Wt/lib/wttestd.lib"
)

Works in Windows Release, fails in Windows Debug.

  std::string form_title_str = "Form Example";
  std::cout << form_title_str << std::endl;
  std::string str = WApplication::appRoot().c_str();

The first 2 lines work fine.

The 3rd line crashes with an un-handled exception ("Access reading violation") from "ucrtbased.dll" only in Debug, not in Release

This was run with the "form" example that Wt gives.

Thanks for any help!

Actions #1

Updated by Roel Standaert over 4 years ago

So, in this bit:

target_link_libraries(${THIS} ...)

You're linking with wt.lib and wtd.lib? That's probably causing your problems.

Are you using Wt 4? Because in that case you can just use find_package and specify Wt_DIR to be C:/Program Files/Wt/lib/cmake/wt.

Then you can do:

find_package(Wt REQUIRED COMPONENTS Wt HTTP) # and maybe any other components you need

target_link_libraries(${THIS} Wt::Wt Wt::HTTP)

If you want to do it your way, you'll have to use optimized and debug to distinguish between the release and the debug library, so it will only use the one it needs for the type of build you're doing, like this:

target_link_libraries(${THIS}
    optimized "C:/Program Files/Wt/lib/wt.lib" debug "C:/Program Files/Wt/lib/wtd.lib"
    ...
)
Actions #2

Updated by Joel Leagues over 4 years ago

find_package(Wt REQUIRED COMPONENTS Wt HTTP) # and maybe any other components you need

target_link_libraries(${THIS} Wt::Wt Wt::HTTP)

That method you listed never worked for me because I couldn't find a "FindWt.cmake" that worked, the file above worked as my "FindWt.cmake".

Is there a good video tutorial on setting up "Wt" on Windows and using it with CMake that I could follow along?

If I could just build the projects, going through the examples would be easy to learn from. I can go through them now but only in release mode and I wouldn't want to build a project only in release mode.

Actions #3

Updated by Roel Standaert over 4 years ago

I think you're not completely up to date with the additions to CMake since CMake 3.0. Something like FindWt.cmake is no longer necessary. Wt 4 includes CMake configuration files that it installs in lib/cmake/wt under Wt's installation prefix. If you set Wt_DIR to that path (including the lib/cmake/wt), then find_package(...) should just work.

Actions #4

Updated by Joel Leagues over 4 years ago

cmake_minimum_required(VERSION 3.10)

set(CMAKE_SYSTEM_VERSION "10.0.17763.0")
set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION "10.0.17763.0")

SET(THIS Form)   # << -------------------------------------------
project (${THIS})

set(BUILD_DIR ${CMAKE_SOURCE_DIR}/Solution)
set(INC       ${BUILD_DIR}/include)
set(SRC       ${BUILD_DIR}/src)

include_directories(${CMAKE_CURRENT_BINARY_DIR} "${INC}") 

set(Wt_DIR "D:/Application_Engines/Wt/lib/cmake/wt")
set(CMAKE_MODULE_PATH "D:/Application_Engines/Wt/lib/cmake/wt")

find_package(Wt REQUIRED COMPONENTS Wt HTTP)

add_executable(${THIS}

    ./Solution/include/Form.h
    ./Solution/include/FormExample.h
    ./Solution/src/Form.cpp
    ./Solution/src/FormExample.cpp
)
TARGET_LINK_LIBRARIES(${THIS}
  Wt::Wt
  Wt::HTTP
)

Thanks "Roel Standaert", your method worked.

Above is my working CMakeLists.txt to get their form example working.

Yes it works in debug mode now!!

Note, I did the following.

  1. I re-installed the windows kits and had to use an older version (same for all my builds because 10.0.18362.0 loading is broken)
  2. I set cmake to use 10.0.17763.0 until microsoft fixes their newer version
  3. I downloaded and unpacked Wt version 4.20 from https://github.com/emweb/wt/releases
  4. I downloaded the newest version of +CMake 3.16.0-rc4
  5. I added "D:\Application_Engines\Wt\bin" to my path
  6. I used the above CMakeLists.txt

Now it all works. I am very happy!!

Actions #5

Updated by Joel Leagues over 4 years ago

I forgot to add a number '7'

"---docroot ../ ---http-address 127.0.0.1 ---http-port 8080 ---approot=../approot"

That is what I used as the "Command Arguments" for my Microsoft Visual Studio Solution.

Actions #6

Updated by Joel Leagues over 4 years ago

How do I change this thread to 100% done?

Actions #7

Updated by Roel Standaert over 4 years ago

  • Tracker changed from Bug to Support
  • Status changed from New to Closed

I don't think you can do that. We can, though. I'll close this issue.

Actions

Also available in: Atom PDF