I am trying to develop C++/CLI applications with CLion. Compiling works fine with MSVC, along with debugging. However when the /clr
flag is added the build still works (even in debug mode), but when an exception is thrown or a breakpoint is hit I get a error message in the console and the debugger shows the disassembly instead of breaking into the code as expected. So, what is the way to correctly deal with C++/CLI code in Jetbrains CLion?
CMakeList.txt
cmake_minimum_required(VERSION 3.16)
project(TestCLI)
set(CMAKE_CXX_STANDARD 17)
# use C++/CLI so that the Inventor API can be used, some flags must be removed as they are not supported
set(CMAKE_CXX_FLAGS /clr)
if(CMAKE_CXX_FLAGS_DEBUG MATCHES "/RTC1")
string(REPLACE "/RTC1" " " CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
endif()
if(CMAKE_CXX_FLAGS MATCHES "/EHsc")
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
add_executable(TestCLI main.cpp)
Hitting a Breakpoint
Breakpoint
Code
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
Console Output
C:\Users\navel\CLionProjects\TestCLI\cmake-build-debug\TestCLI.exe
Unhandled Exception: System.InvalidProgramException: Common Language Runtime detected an invalid program.
at main()
at _mainCRTStartup()
Exception: Exception 0xe0434352 encountered at address 0x74cc22a2
With an Exception
Code
#include <iostream>
#include <exception>
int main() {
std::cout << "Hello, World!" << std::endl;
throw std::exception("HERE");
return 0;
}
Console Output
C:\Users\navel\CLionProjects\TestCLI\cmake-build-debug\TestCLI.exe
Hello, World!
Unhandled Exception: System.Runtime.InteropServices.SEHException: External component has thrown an exception.
at _CxxThrowException(Void* , _s__ThrowInfo* )
at main() in C:\Users\navel\CLionProjects\TestCLI\main.cpp:line 6
at _mainCRTStartup()
Exception: Exception 0xe06d7363 encountered at address 0x74cc22a2
Similar Issue
Issue on VS instead: https://developercommunity.visualstudio.com/content/problem/33193/unable-to-debug-set-breakpoints-in-ccli-project.html
User contributions licensed under CC BY-SA 3.0