INVALID TYPE: Only int64_t and bool are supported as an integral argument type when building a torchscript extension

Shisho_Sama: <p>I’m following the <a href="https://pytorch.org/tutorials/advanced/torch_script_custom_classes.html" rel="nofollow noopener">https://pytorch.org/tutorials/advanced/torch_script_custom_classes.html</a> in order to expose my C++ dll in Python.<br>
The bulk of the code that I have at the moment is this :</p>
<pre><code class="lang-cpp">#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;torch/script.h&gt;
include &lt;FV/FV.h&gt;

struct PyManager : torch::CustomClassHolder {
    PyManager(std::string model, std::string root, std::string cache, bool rebuildCache) 
    {
        auto config = FV::Load_Default_Settings();
        config.mutable_configuration()-&gt;mutable_x()-&gt;mutable_settings()-&gt;set_x_rebuild_cache(rebuildCache);
        config.mutable_configuration()-&gt;mutable_x()-&gt;mutable_settings()-&gt;set_x_cache_folder(cache_folder);
        //... some other settings being set using protobuf config here
        fv = std::make_shared&lt;FV&gt;(config);
    }

    int AddUser(std::string user_id, std::string path) 
    {
        fv-&gt;AddNewUser(user_id, path);
    }
    int RemoveUser(std::string user_id) 
    {
        fv-&gt;RemoveUser(user_id);
    }
    int UpdateUser(std::string usier_id, std::string new_path)
    {
        fv-&gt;UpdateUser(usier_id, new_path);
    }
    int UpdateUsersInBulk(std::vector&lt;std::string&gt; userIDs, std::string path, bool is_delete_granted = true, bool show_dbg_info = true)
    {
        fv-&gt;UpdateUsersInBulk(userIDs, path, is_delete_granted, show_dbg_info);
    }
    int RenameId(std::string old_id, std::string new_id)
    {
        fv-&gt;RenameUserID(old_id, new_id);
    }

private:
    std::shared_ptr&lt;FV&gt; fv;
};

TORCH_LIBRARY(my_classes, m) {
    m.class_&lt;PyManager&gt;("PyManager")
        .def(torch::init&lt;std::string, std::string, std::string, bool&gt;())

        .def("add", &amp;PyManager::AddUser)
        .def("remove", &amp;PyManager::RemoveUser)
        .def("update", &amp;PyManager::UpdateUser)
        .def("update_in_bulk", &amp;PyManager::UpdateUsersInBulk);
}
</code></pre>
<p>And this is the cmake file that I use :</p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(custom_class)

find_package(Torch REQUIRED)
find_package(Protobuf REQUIRED)

INCLUDE_DIRECTORIES(
"D:/Codes/cpp/port/LibtorchPort/Dependencies/include"
"D:/External Libs/Opencv3.4.10_vc14_vc15/opencv3.4/include"
)

LINK_DIRECTORIES(
"D:/Codes/cpp/port/LibtorchPort/x64"
"D:/External Libs/Opencv3.4.10_vc14_vc15/opencv3.4/x64/vc14/lib"
)

# Define our library target
add_library(custom_class SHARED class1.cpp)

#define our c++ standard
set(CMAKE_CXX_STANDARD 17)
# Link against LibTorch
target_link_libraries(custom_class "${TORCH_LIBRARIES}")
</code></pre>
<p>and I’m calling cmake like this :</p>
<pre><code class="lang-auto">cmake -DCMAKE_PREFIX_PATH="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" ..
</code></pre>
<p>but I get the following error :</p>
<pre><code class="lang-auto">Severity	Code	Description	Project	File	Line	Suppression State
Error	C2338	INVALID TYPE: Only int64_t and bool are supported as an integral argument type	custom_class	D:\Codes\cpp\port\LibtorchPort\Dependencies\libtorch-debug-latest\libtorch\include\ATen\core\op_registration\infer_schema.h	39	
</code></pre>
<p>What am I missing here ?<br>
Any help is greatly appreciated</p>

Shisho_Sama: <p>by the way, something as simple as this also fails:</p>
<pre><code class="lang-cpp">#include &lt;torch/script.h&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
struct PyManager : torch::CustomClassHolder {
    PyManager(std::string model_path, std::string img_bank_folder_root, std::string cache_folder,
        std::string pnet, std::string rnet, std::string onet, bool rebuildCache) 
    {
        std::cout &lt;&lt; "ok!";
    }

    int AddUser(std::string user_id, std::string img_fldr_path) 
    {
        std::cout &lt;&lt; user_id &lt;&lt; img_fldr_path;
    }
    int RemoveUser(std::string user_id) 
    {
        std::cout &lt;&lt; user_id ;
    }
    int UpdateUser(std::string user_id, std::string new_images_folder_path)
    {
        std::cout &lt;&lt; user_id &lt;&lt; new_images_folder_path;
    }
    int UpdateUsersInBulk(std::vector&lt;std::string&gt; userIDs, std::string ID_folders_path, bool is_delete_granted = true, bool show_dbg_info = true)
    {
        std::cout &lt;&lt; userIDs.size() &lt;&lt; ID_folders_path;
    }
    int RenameId(std::string old_id, std::string new_id)
    {
        std::cout &lt;&lt; old_id &lt;&lt; new_id;
    }

};

TORCH_LIBRARY(my_classes, m) {
    m.class_&lt;PyManager&gt;("PyManager")
        .def(torch::init&lt;std::string, std::string, std::string, std::string, std::string, std::string, bool&gt;())
        .def("add", &amp;PyManager::AddUser)
        .def("remove", &amp;PyManager::RemoveUser)
        .def("update", &amp;PyManager::UpdateUser)
        .def("update_in_bulk", &amp;PyManager::UpdateUsersInBulk);
}
</code></pre>
<p>Any help would be greatly appreciated!</p>