-
Notifications
You must be signed in to change notification settings - Fork 203
Description
Hi, I'm trying to load a model with scatter operations within C++. I've successfully built and installed pytorch_scatter using CMake through Visual Studio 2019 and can successfully import it. However when trying to build I get the following error:
Error LNK2001 unresolved external symbol "__int64 __cdecl scatter::cuda_version(void)" (?cuda_version@scatter@@YA_JXZ)
Code:
#include <torch/script.h> // One-stop header.
#include <iostream>
#include <memory>
#include <torch/torch.h>
#include <torchscatter/scatter.h>
int main(int argc, const char* argv[]) {
if (argc != 2) {
std::cerr << "usage: example-app <path-to-exported-script-module>\n";
return -1;
}
std::cout << argv[1] << "\n";
torch::jit::script::Module module;
try {
// Deserialize the ScriptModule from a file using torch::jit::load().
module = torch::jit::load(argv[1]);
}
catch (const c10::Error& e) {
std::cerr << "error loading the model\n";
std::cout << e.what() << std::endl;
return -1;
}
std::cout << "ok\n";
}
Note that it builds fine without the #include <torchscatter/scatter.h> line. And the resulting executable is able to load a model from torchvision, i.e. the same as this example. But it quietly crashes when I try to load the model.pt that is created by the save_model.py from this example
The CMake method from the PyG examples seems to not work for me - it wouldn't find the scatter.h at all. So I'm using a standard VS project and have the pytorch scatter included within the C/C++ -> Additional Include Directories setting. Also within the Linker -> Additional Library Directories. Followed this for setting up a build environment for torch in VS.
Issue #212 seems related but they seem to switch to the CMake method halfway through before getting it fixed.
Any insight on the unresolved external symbol error? The pytorch scatter was built with the WITH_CUDA flag set to false/off so unsure why it's complaining about it? The resulting directory of the install only has scatter.h and the cpu folder.