error: Working with pcap crate in rust on Windows - rust

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.

Related

How to link Bcrypt.lib to VC++ DLL project

Trying to compile a VC++ DLL I get some error messages related to Visual Studio cannot resolve external symbols, errors LNK2001, LNK1120.
In my case the symbol it cannot be resolved is: __imp__BCryptGenRandom#16
and the error message is:
error LNK2001: unresolved external symbol __imp__BCryptGenRandom#16
I have googled and found that it is said to link BCrypt.lib so I have linked it at "properties->linker->input->additional dependency"
Also at ""properties->linker->all options->additional library directoris" I have added below one where BCrypt.lib is for x86:
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x86
And finally at "properties->linker->General->Use library dependencies inputs" I have set "Yes".
But none of these methods work.

Can't compile rust program

I'm new to rust and made a simple rust program(hello world). I installed rust and Visual Studio from here - https://visualstudio.microsoft.com/downloads/ and restarted the device. However when I type in rustc <path> on command prompt, I get:
error: linker `link.exe` not found
|
= note: The system cannot find the file specified. (os error 2)
note: the msvc targets depend on the msvc linker but `link.exe` was not found
note: please ensure that VS 2013, VS 2015 or VS 2017 was installed with the Visual C++ option
error: aborting due to previous error
What's wrong?
Update
I updated my system path to include C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.22.27905\bin\Hostx64\x64, but now it gives this error:
error: linking with `link.exe` failed: exit code: 1181
|
= note: "link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "main.main.7rcbfp3g-cgu.0.rcgu.o" "main.main.7rcbfp3g-cgu.1.rcgu.o" "main.main.7rcbfp3g-cgu.2.rcgu.o" "main.main.7rcbfp3g-cgu.3.rcgu.o" "main.main.7rcbfp3g-cgu.4.rcgu.o" "main.main.7rcbfp3g-cgu.5.rcgu.o" "/OUT:main.exe" "main.4s37gsrti678ik8u.rcgu.o" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/LIBPATH:C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-b2f27b8d08c4688f.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-9c73c9c2e052b2f1.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libbacktrace-7a588e8fa018f6bc.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-74b71f441b8acffe.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-42efce06651eab9c.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-7518db6030684168.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-f7edde5930d50b47.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-30189c8e78e151e8.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-5f5719f1cab83a12.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-f297c401e81b90c6.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-f8c80c1aefab6a32.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-6d66b6e58725d3ed.rlib" "C:\\Users\\Sid\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-1f6a73e107798f53.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
= note: LINK : fatal error LNK1181: cannot open input file 'advapi32.lib'
error: aborting due to previous error
This reports your exact problem.
So the solution seems to use VS installer and installing C++ for Desktop Module.
Use of rustup is a matter of convenience but shouldn't be mandatory.

LNK2019 unresolved symbol compiling LuaJava with Visual Studio 2012

I am working with visual studio 2012 to compile LuaJava. The problem I am having is when I call the linker. The line that calls the linker in the makefile is:
link /dll /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64"
/LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64"
/out:luajava-1.1.dll src\c\luajava.obj
"C:\Program Files (x86)\Lua\5.1\lib\lua5.1.lib" /VERBOSE
This seems to almost be linking everything successfully, until it gets to the Lua library.
The linker outputs the following when I try to make the project:
...//linking of other libraries
Finished searching libraries
Unused libraries:
C:\Program Files (x86)\Lua\5.1\lib\lua5.1.lib
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64\OLDNAMES.lib
luajava.obj : error LNK2019: unresolved external symbol lua_close referenced in function Java_org_keplerproject_luajava_LuaState__1close
luajava.obj : error LNK2019: unresolved external symbol lua_newthread referenced in function Java_org_keplerproject_luajava_LuaState__1newthread
luajava.obj : error LNK2019: unresolved external symbol lua_gettop referenced in function Java_org_keplerproject_luajava_LuaState__1getTop
...//lots of these errors
luajava-1.1.dll : fatal error LNK1120: 88 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\BIN\x86_amd64\link.EXE"' : return code '0x460'
Stop.
I'm confused as to why it says that the Lua library is unused, and then complains when it can't find the Lua library functions.
You can not link a 32 bit library to your 64 bit application. After some searces I do not believe LuaJava has a x64 download so to use this you must change your application to 32 bit.
Edit:
A second method would be to recomile LuaJava as a 64 bit dll. Here is a very recent post about that: LuaJava compile error "Unresolved external symbol"

SFML linker problems on eclipse VC++

I am trying to use the SFML library for audio in my project.
I am developing in eclipse juno for c++ and am using SFML v1.6.
I added sfml-audio-d.lib, sfml-main-d.lib, and sfml-system-d.lib into
C/C++ General > paths and symbols>libraries
I also defined a macro named SFML_DYNAMIC into
C/C++ Build>Settings>C++ Compiler>Preprocessor 'Defines /D' section
I added the directory that contains all the dlls into the PATH environment variable.
In my code I make use of sf::SoundBuffer, but when I try to build the project I get the following linker error:
Chunk.obj : error LNK2001: unresolved external symbol "private: static class sf::SoundBuffer * Chunk::breakBlockSound" (?breakBlockSound#Chunk##0PAVSoundBuffer#sf##A)
MyProject.exe : fatal error LNK1120: 1 unresolved externals
Had to rebuild the project in VS2010 before using it. Works now.

v8 release mode linker error with winsock

This subject became a side subject after I accepted an answer for my last question, so I will put it here as a separate topic for neatness, and I believe this will make it more useful for others.
I am working on MS visual studio 2005.
I am building a project using v8 in release mode, and am receiving a linker error that is related to winsock even though the winsock libraries are already in my additional dependencies.
My additional dependencies list is the same for both release and debug mode. It works perfectly in debug mode, and I am getting the linker errors only in release mode.
here is my additional dependencies string:
Ws2_32.lib wininet.lib rasapi32.lib iphlpapi.lib Psapi.lib winmm.lib wsock32.lib msvcrt.lib $(SolutionDir)\external_libs\debug\v8.lib $(SolutionDir)external_libs\release\v8_base.lib $(SolutionDir)external_libs\release\v8_snapshot.lib
Thanks a lot for any possible help.
Update:
I reduced the dependencies to:
Ws2_32.lib Psapi.lib winmm.lib msvcrt.lib $(SolutionDir)\external_libs\release\v8.lib $(SolutionDir)external_libs\release\v8_base.lib
and still get unresolved externals:
1>v8_base.lib(platform-win32.obj) : error LNK2001: unresolved external symbol __imp__freeaddrinfo#4
1>v8_base.lib(platform-win32.obj) : error LNK2001: unresolved external symbol __imp__getaddrinfo#16
1>v8_base.lib(platform-win32.obj) : error LNK2001: unresolved external symbol __set_abort_behavior
You have paths to both debug and release folders in your dependency list. Try replacing those with $(Configuration).

Resources