Tencent / ncnn

ncnn is a high-performance neural network inference framework optimized for the mobile platform
Other
20.55k stars 4.18k forks source link

error: cannot use 'try' with exceptions disabled, enabling flags not working with cmake (?) #4427

Open akai-katto opened 1 year ago

akai-katto commented 1 year ago

error log | 日志或报错信息 | ログ

In file included from /Users/tyler/Documents/personal/sdk/asio-1.24.0/include/asio/execution/executor.hpp:20:
In file included from /Users/tyler/Documents/personal/sdk/asio-1.24.0/include/asio/execution/execute.hpp:20:
/Users/tyler/Documents/personal/sdk/asio-1.24.0/include/asio/execution/detail/as_invocable.hpp:60:5: error: cannot use 'try' with exceptions disabled

context | 编译/运行环境 | バックグラウンド

I'm trying to use asio standalone library with waifu2x-ncnn-vulkan. I've tried to enable exceptions using options in the cmake.

how to reproduce | 复现步骤 | 再現方法

Using this code will produce the error on "resolver"

        std::cout << port << " " << "Setting up server..." << std::endl;
        asio::ip::tcp::resolver resolver(io_context); // error here 
        asio::ip::tcp::resolver::query query(ip::tcp::v4(), IP_ADDRESS, port);
        asio::ip::tcp::endpoint endpoint = *resolver.resolve(query);

more | 其他 | その他

This is what I've tried so far with the cmake,

...
    list(APPEND WAIFU2X_LINK_LIBRARIES
        ${Metal}
        ${QuartzCore}
        ${CoreGraphics}
        ${Cocoa}
        ${IOKit}
        ${IOSurface}
        ${Foundation}
        ${CoreFoundation}
    )
endif()

add_compile_definitions(NCNN_DISABLE_RTTI=OFF NCNN_DISABLE_EXCEPTION=OFF)
option(NCNN_DISABLE_EXCEPTION "" OFF)
target_link_libraries(waifu2x-ncnn-vulkan ${WAIFU2X_LINK_LIBRARIES})
target_compile_options(waifu2x-ncnn-vulkan PRIVATE -DNCNN_DISABLE_RTTI=OFF -DNCNN_DISABLE_EXCEPTION=OFF)

To no success.

akai-katto commented 1 year ago

I've also tried this in my ncnn cmake:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNCNN_DISABLE_RTTI=OFF -DNCNN_DISABLE_EXCEPTION=OFF")
add_compile_definitions(NCNN_DISABLE_RTTI=OFF NCNN_DISABLE_EXCEPTION=OFF)
akai-katto commented 1 year ago

Commenting out this in src/cmake.txt was able to get it to work,

if(NCNN_DISABLE_EXCEPTION)
   # target_compile_options(ncnn PUBLIC -fno-exceptions)
endif()

Works, but none of my attempts at enabling errors from my forkedwaifu2x-ncnn-vulkan` have been successful. Hoping I'm missing something obvious.