I am trying to use the tch crate for rust but I am getting the following error or run.
Creating library C:\Users\sefto\Documents\rust-projects\tch-test\target\debug\deps\tch_test.lib and object C:\Users\sefto\Documents\rust-projects\tch-test\target\debug\deps\tch_test.exp
libtorch_sys-457a9014c45a8ec4.rlib(torch_api.o) : error LNK2001: unresolved external symbol __imp___tls_index_?init#?1??lazy_init_num_threads#internal#at##YAXXZ#4_NA
libtorch_sys-457a9014c45a8ec4.rlib(torch_api.o) : error LNK2001: unresolved external symbol __imp___tls_offset_?init#?1??lazy_init_num_threads#internal#at##YAXXZ#4_NA
C:\Users\sefto\Documents\rust-projects\tch-test\target\debug\deps\tch_test.exe : fatal error LNK1120: 2 unresolved externals
This is after running the following commands:
cargo new tch-test
cd tch-test
cargo add tch
Then changing the contents of main.rs to:
use tch::*;
fn main() {
println!("Hello, world!");
}
and finally running:
cargo run
I have tried installing libtorch and adding to PATH etc as per the install instructions here https://github.com/LaurentMazare/tch-rs.
I have also tried without libtorch as if it is not found cargo should install it for me.
Related
I have a linking problem in Rust.
I'm new to rust and I'm building a library project using the pcap crate.
On linux and Mac OS everything works fine, but as soon as I try on Windows I get linking errors.
I added pcap crate in the cargo.toml as a dependency.
I then installed Winpcap as said in the crates.io pcap page (https://crates.io/crates/pcap) (installed the Developers pack as well). Then on the page says to :
Add the /Lib or /Lib/x64 folder to your LIB environment variable.
I get this error (I deleted part of the paths in the middle of the error to focus on the main stuff, but if they are useful let me know):
error: linking with `link.exe` failed: exit code: 1181
|
= note: "C:\\Program Files\\Microsoft
VisualStudio\\2022\\Community\\VC\\Tools\\MSVC\\14.........
....................
= note: LINK : fatal error LNK1181: cannot open input file
'wpcap.lib'
I solved the wpcap.lib basic linking error by adding it to a new environment variable called LIB as the documentation says.
Then, trying to cargo build, I got an error saying
PS C:\dev\testing> cargo build
Compiling testing v0.1.0 (C:\dev\testing)
error: linking with `link.exe` failed: exit code: 1120
|
= note: "C:\\Program Files\\Microsoft Visual
Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\bin\\HostX64\\x64\\link.exe"
"/NOLOGO" "C:\\dev\\testing\\target\\debug\\deps\\testing.testing.edb54395-cgu.0.rcgu.o"
"C:\\dev\\testing\\target\\debug\\deps\\testing.testing.edb54395-cgu.1.rcgu.o"
"C:\\dev\\testing\\target\\debug\\deps\\testing.testing.edb54395-cgu.10.rcgu.o"
"C:\\dev\\testing\\target\\debug\\deps\\testing.testing.edb54395-cgu.2.rcgu.o"
"C:\\dev\\testing\\target\\debug\\deps\\testing.testing.edb54395-cgu.3.rcgu.o"
"C:\\dev\\testing\\target\\debug\\deps\\testing.testing.edb54395-cgu.4.rcgu.o"
"C:\\dev\\testing\\target\\debug\\deps\\testing.testing.edb54395-cgu.5.rcgu.o"
"C:\\dev\\testing\\target\\debug\\deps\\testing.testing.edb54395-cgu.6.rcgu.o"
"C:\\dev\\testing\\target\\debug\\deps\\testing.testing.edb54395-cgu.7.rcgu.o"
"C:\\dev\\testing\\target\\debug\\deps\\testing.testing.edb54395-cgu.8.rcgu.o"
"C:\\dev\\testing\\target\\debug\\deps\\testing.testing.edb54395-cgu.9.rcgu.o"
"C:\\dev\\testing\\target\\debug\\deps\\testing.1aob1werv7d25t5k.rcgu.o"
"/LIBPATH:C:\\dev\\testing\\target\\debug\\deps"
"/LIBPATH:C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib"
"C:\\dev\\testing\\target\\debug\\deps\\libpcap-8deb041f35d1931b.rlib"
"C:\\dev\\testing\\target\\debug\\deps\\liberrno-7dba5013f5f8cda0.rlib"
"C:\\dev\\testing\\target\\debug\\deps\\liblibc-b1b00607d98a9924.rlib"
"C:\\dev\\testing\\target\\debug\\deps\\libwinapi-67f367a3be4e6577.rlib"
"C:\\dev\\testing\\target\\debug\\deps\\libwidestring-e027d887e1db6ed5.rlib"
"C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-ca7b0c28ec762872.rlib"
"C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-1b050a71ed5c4477.rlib"
"C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-ba9f9c006950f110.rlib"
"C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-
4e228cbffbe5e3cd.rlib" "C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-d3d7c65121bb0d35.rlib"
"C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-
2cedaf2947cb8622.rlib" "C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-7d6cff0c7b8f0c2b.rlib"
"C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-63bdfcda4a65748c.rlib"
"C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-c331c9d260094b22.rlib"
"C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-34d0a2dd4a5dbc91.rlib"
"C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-
e7b8421abede5598.rlib" "C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-08b052fa5e861ac2.rlib"
"C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-
18761c3bc8f2e6ea.rlib" "wpcap.lib" "advapi32.lib" "cfgmgr32.lib" "kernel32.lib"
"user32.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "advapi32.lib" "userenv.lib"
"kernel32.lib" "msvcrt.lib" "/NXCOMPAT"
"/LIBPATH:C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib"
"/OUT:C:\\dev\\testing\\target\\debug\\deps\\testing.exe" "/OPT:REF,NOICF" "/DEBUG"
"/NATVIS:C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\etc\\intrinsic.natvis"
"/NATVIS:C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\etc\\liballoc.natvis"
"/NATVIS:C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\etc\\libcore.natvis"
"/NATVIS:C:\\Users\\Noahr\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\etc\\libstd.natvis"
= note: libpcap-8deb041f35d1931b.rlib(pcap-8deb041f35d1931b.pcap.c5d00465-cgu.0.rcgu.o)
: error LNK2019: unresolved external symbol pcap_set_tstamp_type referenced in function
_ZN4pcap29Capture$LT$pcap..Inactive$GT$11tstamp_type17h390a1208ab521116E
libpcap-8deb041f35d1931b.rlib(pcap-8deb041f35d1931b.pcap.c5d00465-cgu.0.rcgu.o) :
error LNK2019: unresolved external symbol pcap_set_immediate_mode referenced in function
_ZN4pcap29Capture$LT$pcap..Inactive$GT$14immediate_mode17h93e0c1bfbe5dff6eE
libpcap-8deb041f35d1931b.rlib(pcap-8deb041f35d1931b.pcap.c5d00465-cgu.0.rcgu.o) :
error LNK2019: unresolved external symbol pcap_set_tstamp_precision referenced in
function _ZN4pcap29Capture$LT$pcap..Inactive$GT$9precision17h00be47b98a77c43eE
C:\dev\testing\target\debug\deps\testing.exe : fatal error LNK1120: 3 unresolved
externals
It seems like it found wpcap.lib, but didn't found those 3 libpcap function.
I am stuck. Thanks for the attention and for the replies :)
Update. I solved the issue uninstalling winpcap and rustup.
Resinstalled rustup, winpcap and winpcap developers pack sdk.
Added to a new LIB environment variable the path to the x64 folder of winpcap sdk.
Now everything works. I don't know the reason why iI had that error before but know it works.
I managed to process module pymqe.c into pymqe.pyd for Python2 using VC 2017 compiler and my own make file. Unfortunately, it doesn’t work for Python3. If I try compile module pymqe.c from pymqi-1.9.3.tar.gz in the same way, the linking step fails with the error message:
LINK : error LNK2001: unresolved external symbol initpymq
pymqe.lib : fatal error LNK1120: 1 unresolved externals
My make file contains the following instruction to link pymqe.c with the resulting library pymqe.pyd:
/EXPORT:initpymqe pymqe.obj
I assume, the function initpymqe is excluded during compilation for Python3 due to pre-compiler instruction in the source code of the module pymqe.c:
#if PY_MAJOR_VERSION==2
void initpymqe(void) {
…
#else
Does anyone know, how to handle this problem?
There is a readme here
But it doesn't cover compilation of the submodule for HoloLens.
The developer lists these steps (from various posts this thread in xamarin forums)
git clone git#github.com:xamarin/urho.git
git submodule update --init
// make sure Urho3D/Source folder is not empty
run 'make HoloLens'
open the solution and build UrhoSharp.HoloLens (Release, x86 configuration)
Doing this mostly works, but the final step results in two unresolved externals:
Error LNK2001 unresolved external symbol "void __cdecl WINRT_InitGameBar(struct SDL_VideoDevice *)" (?WINRT_InitGameBar##YAXPAUSDL_VideoDevice###Z) UrhoSharp.HoloLens C:\urho\Urho3D\Urho3D_HoloLens\UrhoSharp.HoloLens\SDL_winrtvideo.obj
and
Error LNK2001 unresolved external symbol "void __cdecl WINRT_QuitGameBar(struct SDL_VideoDevice *)" (?WINRT_QuitGameBar##YAXPAUSDL_VideoDevice###Z) UrhoSharp.HoloLens C:\urho\Urho3D\Urho3D_HoloLens\UrhoSharp.HoloLens\SDL_winrtvideo.obj
These two functions are in this file.
How do I track down and/or resolve these errors?
I'm not sure how to interpret and/or address the error.
The developer put changes into the code base and this issue no longer occurs.
I have followed the steps in the instructions very carefully, but when I try to cross compile my Cargo project using its script,
I get an error while compiling the dependencies for my project:
Compiling libc v0.2.4
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/libc-0.2.4/src/lib.rs:1:1: 1:1 error: can't find crate for `std` [E0463]
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/libc-0.2.4/src/lib.rs:1 // Copyright 2012-2015 The Rust Project Developers. See the C
OPYRIGHT
^
error: aborting due to previous error
Could not compile `libc`.
Summary: Is there any tiny example on how to build the Win32 C++ console application that uses the libgit2 library (sources available at GitHub)?
I have followed the readme and the wiki on how to build the library on Windows using the CMake, and it worked smoothly (only a single unit-test error).
Now, I want to build a simple console application that uses the library -- using Microsoft Visual Studio C++ 2010 (the.vcxproj and the.sln). I have found the general.c code in the libgit2 examples, and I would like to do the same from my C++ application. No success -- I feel really stupid today...
I have noticed there is libqgit2 for C++ and Qt. Is there anything similar for pure C++? Or is there a way to use the C library from C++ application?
Update: I have renamed the general.c to general.cpp, added the libgit2 include path to the project and the path to the .lib files, changed the #include <stdio.h> to #include <cstdio>, and compiled. The following link errors appear:
1>------ Build started: Project: libgit2_general, Configuration: Debug Win32 ------
1>general.obj : error LNK2019: unresolved external symbol _git_repository_free referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _git_config_get_string referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _git_config_get_int32 referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _git_config_open_ondisk referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _git_strarray_free referenced in function _main
... etc.
1>general.obj : error LNK2019: unresolved external symbol _git_repository_open referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _giterr_last referenced in function "void __cdecl check_error(int,char const *)" (?check_error##YAXHPBD#Z)
1>D:\Tutorial\libgit2_general\Debug\libgit2_general.exe : fatal error LNK1120: 56 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This strongly suggests a calling convention mismatch to me. libgit2 uses __stdcall by default, for a number of reasons, while Visual Studio defaults to creating projects that use the __cdecl calling convention. While your program can use either calling convention and successfully call libgit2 using a different one, the easiest solution is probably just to use the same calling convention for both.
When you configure libgit2, you can turn off the STDCALL flag, which will cause it to emit a library built with __cdecl calling conventions:
cmake %PATH_TO_LIBGIT2_SOURCE% -DTHREADSAFE=ON -DSTDCALL=OFF
cmake --build .
It's a little surprising if you generated the project from CMake, bit it could be that you're not linking to libgit2.lib. Make sure you have git2.dll in Project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies.