Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows 10 Store App - C++ - how to configure project to use Sentry crash reporting? #170

Closed
sseyod opened this issue Mar 11, 2020 · 14 comments

Comments

@sseyod
Copy link

sseyod commented Mar 11, 2020

Hi!

Now that you've just released updated the Native / C++ version (thanks!), I've been able to download it, install Make for Windows 10, and start trying to integrate with one of my C++ projects for Windows 10.

  1. I've run cmake like this (please note that it wasn't clear that this is how it needs to be run for Windows 10 native - I hope it is correct!)

cmake . -DBUILD_SHARED_LIBS=OFF

  1. I've updated my C++ project to include calls as per your documentation (note use of extern "C", which I presume is correct):

extern "C" {
#include <sentry.h>
}

int main(void) {
...
sentry_options_t *options = sentry_options_new();
sentry_options_set_dsn(options, "https://blah/blah");
sentry_init(options);

/* ... */

// make sure everything flushes
sentry_shutdown();
}

  1. I've updated my project to import the same .lib files that your test project (sentry_example) uses, including sentry.lib (and all the other ones).

  2. However, I'm getting this:

1>Main.obj : error LNK2001: unresolved external symbol __imp_sentry_value_new_message_event
1>Main.obj : error LNK2001: unresolved external symbol __imp_sentry_init
1>Main.obj : error LNK2001: unresolved external symbol __imp_sentry_shutdown
1>Main.obj : error LNK2001: unresolved external symbol __imp_sentry_options_set_dsn
1>Main.obj : error LNK2001: unresolved external symbol __imp_sentry_capture_event
1>Main.obj : error LNK2001: unresolved external symbol __imp_sentry_options_new
1>C:...blah...\myapp.exe : fatal error LNK1120: 6 unresolved externals

Can you please advise?

Pete

@sseyod
Copy link
Author

sseyod commented Mar 11, 2020

Looks like the solution was to do this in my app:

#define SENTRY_BUILD_STATIC 1
#include <sentry.h>

@sseyod
Copy link
Author

sseyod commented Mar 11, 2020

My project requires multithreaded runtime library (/MT) - but the configuration of sentry is multithreaded DLL (even though I have configured as static library!)

Is there any way to fix that via Cmake? Otherwise, I can't link it...

Pete

@sseyod
Copy link
Author

sseyod commented Mar 11, 2020

Finally, having manually changed the flags in the Sentry projects to /MT, and rebuilding...
I now get loads of these errors when building my app:

1>sentry.lib(sentry_crashpad_backend.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in ABC.obj
...
1>crashpad_client.lib(crash_report_database.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck_EH4

Thanks, Pete

@Swatinem
Copy link
Member

@sseyod can you try this again with the latest 0.2.1 release and close this if the issue is solved?
I do test on Windows 10 myself with VS2019 and it works fine. We now also have tests for VS2017 in place.

@sseyod
Copy link
Author

sseyod commented Mar 19, 2020

Hi @Swatinem,

Many thanks for getting back to me. I'll give it a go and report back!

Question for you: what is the best URL to look at, with regard to build instructions; some concrete examples of how to make the build in various configurations would be very helpful (see my above comments!) :)

For the record, I'm using VS2019 Community Edition, and C++17.

Best, Pete

@sseyod
Copy link
Author

sseyod commented Mar 20, 2020

Hi @Swatinem,

OK, this has improved things, in that I then just see one missing symbol reported, which is __GSHandlerCheck_EH4.

1>mini_chromium.lib(rand_util.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck_EH4
1>crashpad_util.lib(split_string.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck_EH4
1>mini_chromium.lib(file_path.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck_EH4
1>mini_chromium.lib(logging.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck_EH4
... etc. etc. ...

I was able to fix that, by further modifying the build configuration for sentry native.

Note that my app is a Windows 10 Store app - that might explain why I needed to work around the __GSHandlerCheck_EH4 problem ... see the FH4 flags for compiler and linker.

My build notes are here, I hope they help you and others.

To build:
1)  Use Windows Explorer to delete any CMakeFile folder within this folder ...
  cd <my folder>\sentry-native\
2)  Patch CMakeLists.txt as follows:
===
  if(WIN32)
    set(SENTRY_DEFAULT_TRANSPORT "winhttp")
    # MY CHANGES BEGIN
    # https://stackoverflow.com/questions/14172856/compile-with-mt-instead-of-md-using-cmake
    # https://devblogs.microsoft.com/cppblog/making-cpp-exception-handling-smaller-x64/
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT -d2FH4-")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd -d2FH4-")
    set(CMAKE_CXX_STANDARD 17)
    add_link_options("-d2:-FH4-")
    # MY CHANGES END
elseif(APPLE OR LINUX)
    set(SENTRY_DEFAULT_TRANSPORT "curl")
else()
    set(SENTRY_DEFAULT_TRANSPORT "none")
endif()
===
3) Using Power Shell from the right folder:
  cmake . -DBUILD_SHARED_LIBS=OFF
4) This builds the debug version by default
  cmake --build . --parallel
5) build the Release version using Visual Studio 2019 directly
6) copy/move the .lib files as required
7) build and run my app

#define SENTRY_BUILD_STATIC 1
#include <sentry.h>

void MyAppInitialise () {
  sentry_options_t* options = sentry_options_new();
  sentry_options_set_dsn(options, "<put your id here>");
  sentry_init(options);

  sentry_capture_event(sentry_value_new_message_event(
    /*   level */ SENTRY_LEVEL_INFO,
    /*  logger */ "custom",
    /* message */ "It works!"
  ));
}

void MyAppTerminate() {
  // make sure everything flushes
  sentry_shutdown();
}

@Swatinem
Copy link
Member

Thanks for investigating @sseyod! This helps me a lot actually ;-)

I will try to find out how I can add these options directly to the library instead of globally, which would also need changes to our crashpad fork.

@sseyod
Copy link
Author

sseyod commented Mar 20, 2020

@Swatinem that is great news, many thanks for letting me know. Always good to help :) Pete

@jan-auer
Copy link
Member

Note that in #190 we found out that Crashpad will likely not work for Windows 10 Store Apps since those can only consist of a single executable. To support that use case, we will need to add a Windows inproc backend, or the Breakpad backend.

@Prachiagrawal1
Copy link

Prachiagrawal1 commented Jun 17, 2020

Followed it to use sentry for my cpp app till this step:
To build:

  1. Use Windows Explorer to delete any CMakeFile folder within this folder ...
  cd <my folder>\sentry-native\
  1. Patch CMakeLists.txt as follows:
  if(WIN32)
    set(SENTRY_DEFAULT_TRANSPORT "winhttp")
    # MY CHANGES BEGIN
    # https://stackoverflow.com/questions/14172856/compile-with-mt-instead-of-md-using-cmake
    # https://devblogs.microsoft.com/cppblog/making-cpp-exception-handling-smaller-x64/
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT -d2FH4-")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd -d2FH4-")
    set(CMAKE_CXX_STANDARD 17)
    add_link_options("-d2:-FH4-")
    # MY CHANGES END
elseif(APPLE OR LINUX)
    set(SENTRY_DEFAULT_TRANSPORT "curl")
else()
    set(SENTRY_DEFAULT_TRANSPORT "none")
endif()
  1. Using Power Shell from the right folder:
  cmake . -DBUILD_SHARED_LIBS=OFF
  1. This builds the debug version by default
  cmake --build . --parallel
  1. build the Release version using Visual Studio 2019 directly

and built the sentry .sln file in release mode after that made a project in cpp then tried including sentry to it but it says "No such directory" for sentry or issues with sentry.h library....how to resolve it.

@sseyod
Copy link
Author

sseyod commented Aug 19, 2020

@Swatinem if you're updating the Windows 10 build/configuration documentation, can you also please consider updating your CMakeLists.txt along the lines of my above suggested changes?

  if(WIN32)
    set(SENTRY_DEFAULT_TRANSPORT "winhttp")
    # MY CHANGES BEGIN
    # https://stackoverflow.com/questions/14172856/compile-with-mt-instead-of-md-using-cmake
    # https://devblogs.microsoft.com/cppblog/making-cpp-exception-handling-smaller-x64/
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT -d2FH4-")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd -d2FH4-")
    set(CMAKE_CXX_STANDARD 17)
    add_link_options("-d2:-FH4-")
    # MY CHANGES END

@sseyod
Copy link
Author

sseyod commented Aug 23, 2020

@Swatinem just wanted to thank you again for all your work on this - had my first usable crash report come through for Windows 10, and it was an easy fix!

@sseyod
Copy link
Author

sseyod commented Aug 23, 2020

Just a tip for others: once you've build the release version of you app, and you've built the package - here is how to upload all you need for the crash reports. Make sure you do this before trying to provoke a crash, or you won't get a usable crash report.

rem Set build number. *** Must *** match that in you Sentry initialisation code, e.g.:
rem sentry_options_set_release(options, "my-product-id@1.2.3");

sentry-cli-Windows-x86_64.exe releases new 1.2.3

rem  upload *all* the binaries - this will automatically find what is required.
rem run it from your "Release" folder that contains your .exe file...

sentry-cli-Windows-x86_64.exe upload-dif difutil check .

@Swatinem
Copy link
Member

I think #283 should have fixed this, as it adds the /MT, etc switches. The use of FH4 seems to be something specific to your program that you should maintain in your own configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants