Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can fix this error?(error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1120`) #93

Open
PoYu-Liao opened this issue Jun 10, 2019 · 7 comments

Comments

@PoYu-Liao
Copy link

PoYu-Liao commented Jun 10, 2019

How can fix this error?
python 3.5 、microsoft visual studio 2019、windows10

D:\mycoding\pakcage\pypcap-master>python setup.py install
Found pcap headers in ..\WpdPack\include\pcap.h
Found libraries in ..\WpdPack\lib/x64\wpcap.lib
found pcap_setdirection
found pcap_setnonblock
found pcap_compile_nopcap function
running install
running bdist_egg
running egg_info
writing dependency_links to pypcap.egg-info\dependency_links.txt
writing pypcap.egg-info\PKG-INFO
writing top-level names to pypcap.egg-info\top_level.txt
reading manifest file 'pypcap.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'pypcap.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_ext
building 'pcap' extension
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DHAVE_PCAP_SETDIRECTION=1 -DHAVE_PCAP_SETNONBLOCK=1 -DHAVE_PCAP_COMPILE_NOPCAP=1 -I..\WpdPack\include -IC:\Users\USER\AppData\Local\Programs\Python\Python35\include -IC:\Users\USER\AppData\Local\Programs\Python\Python35\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tcpcap.c /Fobuild\temp.win-amd64-3.5\Release\pcap.obj -DWIN32 -DWPCAP -D_CRT_SECURE_NO_WARNINGS pcap.c
pcap.c(3394): warning C4013: 'pcap_set_immediate_mode' undefined; assuming extern returning int
pcap.c(20549): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27305): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27325): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27326): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27330): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27332): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27339): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27341): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27348): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27350): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27370): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27373): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27380): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27381): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27382): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27386): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27388): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27395): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27397): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27404): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27406): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27413): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27415): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27422): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27424): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27431): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27433): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27440): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27443): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27472): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27477): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27485): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27489): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
pcap.c(27494): warning C4197: '__pyx_atomic_int': top-level volatile in cast is ignored
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DHAVE_PCAP_SETDIRECTION=1 -DHAVE_PCAP_SETNONBLOCK=1 -DHAVE_PCAP_COMPILE_NOPCAP=1 -I..\WpdPack\include -IC:\Users\USER\AppData\Local\Programs\Python\Python35\include -IC:\Users\USER\AppData\Local\Programs\Python\Python35\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tcpcap_ex.c /Fobuild\temp.win-amd64-3.5\Release\pcap_ex.obj -DWIN32 -DWPCAP -D_CRT_SECURE_NO_WARNINGS pcap_ex.c
pcap_ex.c(140): warning C4311: 'type cast': pointer truncation from 'HANDLE' to 'int'
pcap_ex.c(253): warning C4047: 'function': 'pcap_pkthdr **' differs in levels of indirection from 'pcap_pkthdr *'
pcap_ex.c(253): warning C4024: 'pcap_next_ex': different types for formal and actual parameter 2
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:..\WpdPack\lib/x64 /LIBPATH:C:\Users\USER\AppData\Local\Programs\Python\Python35\libs /LIBPATH:C:\Users\USER\AppData\Local\Programs\Python\Python35\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64" wpcap.lib iphlpapi.lib /EXPORT:PyInit_pcap build\temp.win-amd64-3.5\Release\pcap.obj build\temp.win-amd64-3.5\Release\pcap_ex.obj /OUT:build\lib.win-amd64-3.5\pcap.cp35-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.5\Release\pcap.cp35-win_amd64.lib
pcap.obj : warning LNK4197: export 'PyInit_pcap' specified multiple times; using first specification
   Creating library build\temp.win-amd64-3.5\Release\pcap.cp35-win_amd64.lib and object build\temp.win-amd64-3.5\Release\pcap.cp35-win_amd64.exp
pcap.obj : error LNK2001: unresolved external symbol pcap_set_rfmon
pcap.obj : error LNK2001: unresolved external symbol pcap_set_immediate_mode
build\lib.win-amd64-3.5\pcap.cp35-win_amd64.pyd : fatal error LNK1120: 2 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1120
@sourcenouveau
Copy link

I am also experiencing this with Python 3.7 (x64) using Build Tools for Visual Studio 2019 on Windows 10 (version 1803, build 17143.950). I have pypcap-1.2.3 and the WinPcap 4.1.2 Developer's Pack.

The errors of interest are:

pcap.obj : error LNK2001: unresolved external symbol pcap_set_rfmon
pcap.obj : error LNK2001: unresolved external symbol pcap_set_immediate_mode

@sourcenouveau
Copy link

I determined that the binary library files in WinPcap 4.1.2 Developer's Pack do not export symbols used in pypcap-1.2.3. I determined this using:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.22.27905\bin\Hostx64\x64\dumpbin.exe" /exports "WpdPack\Lib\x64\wpcap.lib"

The output did not list pcap_set_rfmon or pcap_set_immediate_mode.

When I ran the same command against wpcap.lib from the latest Npcap SDK (1.03), those two symbols were listed.

I was able to get pypcap-1.2.3 to compile with WinPcap 4.1.2 Developer's Pack by commenting out lines 3807-3835 in pcap.c:

    /* "pcap.pyx":251
 *             check_return(pcap_set_timeout(self.__pcap, timeout_ms),
 *                          "Set timeout")
 *             check_return(pcap_set_immediate_mode(self.__pcap, immediate),             # <<<<<<<<<<<<<<
 *                          "Set immediate mode")
 *             check_return(pcap_set_rfmon(self.__pcap, rfmon),
 */
    //__pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_immediate); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 251, __pyx_L1_error)
    //__pyx_t_4 = __Pyx_PyInt_From_int(pcap_set_immediate_mode(__pyx_v_self->__pyx___pcap, __pyx_t_8)); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 251, __pyx_L1_error)
    //__Pyx_GOTREF(__pyx_t_4);
    //__pyx_t_3 = __pyx_pf_4pcap_4pcap_8__init___check_return(__pyx_v_check_return, __pyx_t_4, __pyx_kp_s_Set_immediate_mode); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 251, __pyx_L1_error)
    //__Pyx_GOTREF(__pyx_t_3);
    //__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    //__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pcap.pyx":253
 *             check_return(pcap_set_immediate_mode(self.__pcap, immediate),
 *                          "Set immediate mode")
 *             check_return(pcap_set_rfmon(self.__pcap, rfmon),             # <<<<<<<<<<<<<<
 *                          "Set monitor mode")
 *             # Ask for nano-second precision, but don't fail if not available.
 */
    //__pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_rfmon); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 253, __pyx_L1_error)
    //__pyx_t_3 = __Pyx_PyInt_From_int(pcap_set_rfmon(__pyx_v_self->__pyx___pcap, __pyx_t_8)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 253, __pyx_L1_error)
    //__Pyx_GOTREF(__pyx_t_3);
    //__pyx_t_4 = __pyx_pf_4pcap_4pcap_8__init___check_return(__pyx_v_check_return, __pyx_t_3, __pyx_kp_s_Set_monitor_mode); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 253, __pyx_L1_error)
    //__Pyx_GOTREF(__pyx_t_4);
    //__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    //__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

and lines 65-66 and 251-254 in pcap.pyx:

    #int     pcap_set_immediate_mode(pcap_t *p, int immediate_mode)
    #int     pcap_set_rfmon(pcap_t *p, int rfmon)

...

            #check_return(pcap_set_immediate_mode(self.__pcap, immediate),
            #             "Set immediate mode")
            #check_return(pcap_set_rfmon(self.__pcap, rfmon),
            #             "Set monitor mode")

But I wasn't able to use pcapy successfully, with either WinPcap or Npcap installed. It just stalled on pcap.__next__(). There were a few times I saw packets, but it only seemed to get a single packet and then terminate.

@guyharris
Copy link
Collaborator

I determined that the binary library files in WinPcap 4.1.2 Developer's Pack do not export symbols used in pypcap-1.2.3.

WinPcap bug - unlikely ever to be fixed, as WinPcap isn't being developed or maintained any more. The .def file used to build the library doesn't list all the newer APIs.

When I ran the same command against wpcap.lib from the latest Npcap SDK (1.03), those two symbols were listed.

Npcap is based on a newer version of libpcap, in which there is no need for a .def file when building on Windows - symbols that are to be exported by pcap are declared in the appropriate header files with a macro (PCAP_API) that expands to whatever is required to ensure that the symbol is exported from a dynamic library, on platforms where, when a dynamic library is built, symbols aren't exported by default (Windows with Visual Studio) or where it can be arranged that they aren't exported unless they're decorated with the appropriate attributes (most UN*Xes).

That way, when a new API is added, it has to be declared with PCAP_API to export it on most platforms (and programs don't get to use internal interfaces).

@hellais
Copy link
Member

hellais commented Sep 9, 2019

Perhaps we want to make the suggestion of not using WinPcap and favouring Npcap in the Readme even stronger and link to some of the issues (like this one) that can come up when using WinPcap?

@guyharris what do you think?

@6769
Copy link

6769 commented Feb 22, 2020

I am also experiencing this with Python 3.7 (x64) using Build Tools for Visual Studio 2019 on Windows 10 (version 1803, build 17143.950). I have pypcap-1.2.3 and the WinPcap 4.1.2 Developer's Pack.

The errors of interest are:

pcap.obj : error LNK2001: unresolved external symbol pcap_set_rfmon
pcap.obj : error LNK2001: unresolved external symbol pcap_set_immediate_mode

@emddudley

If anyone dosen't mind to use the legacy version, "pypcap 1.2.0" is avaliable for Python3.7 x64 and WinPcap 4.1.3;

My Environments:
Anaconda Python 3.7 x64, WinPcap 4.1.3 with devpack 4.1.2, Windows 7 x64 Enterprise, Visual Studio 2017

What I do:

  1. download old version of pypcap, decompress,
  2. run cython -3 pcap.pyx to fix some header errors as mentioned in readme file,
    run python setup.py build;
  3. if step2 is well finished, just install it and check package's function.

@guyharris
Copy link
Collaborator

I am also experiencing this with Python 3.7 (x64) using Build Tools for Visual Studio 2019 on Windows 10 (version 1803, build 17143.950). I have pypcap-1.2.3 and the WinPcap 4.1.2 Developer's Pack.

The errors of interest are:

pcap.obj : error LNK2001: unresolved external symbol pcap_set_rfmon
pcap.obj : error LNK2001: unresolved external symbol pcap_set_immediate_mode

...and are the result of using WInPcap, which is based on an old version of libpcap that had neither pcap_set_rfmon() nor pcap_set_immediate_mode(). Npcap is based on a much newer version of libpcap that has both of those routines.

@guyharris
Copy link
Collaborator

Perhaps we want to make the suggestion of not using WinPcap and favouring Npcap in the Readme even stronger and link to some of the issues (like this one) that can come up when using WinPcap?

@guyharris what do you think?

Sounds good to me - WinPcap is old and nobody's supporting it any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants