Annotation of embedaddon/libnet/README.win32, revision 1.1
1.1 ! misho 1: Information, Recommendations and Build Instructions for Windows
! 2: **************************************************************************
! 3:
! 4: _____________________________ IMPORTANT _____________________________
! 5: The execution of the currently shipped msvcbuild.bat batch script will
! 6: causes ANY subsequent none-MSVC build to fail. It has been wrongly set
! 7: up to copy several MSVC-specific header files from <libnet-root>/win32/
! 8: to <libnet-root>/include/ and <libnet-root>/include/libnet/ during the
! 9: build process. This is a high priority issue and will be taken care of
! 10: ASAP. If you ever have to make use of this file, consider compiling all
! 11: other builds from a separate tarball.
! 12: _____________________________________________________________________
! 13:
! 14: This file list additional steps and suggestions for Windows users.
! 15: Please see INSTALL for a more general overview and doc/PORTED for
! 16: other platforms.
! 17:
! 18: Unless you know what you are doing, you should follow the recommendations
! 19: below. Notice that there are plenty of other (sometimes better) ways
! 20: to build libnet, but these steps and suggestions are known to work.
! 21: If the build breaks, please re-read this guide carefully.
! 22:
! 23: Contents
! 24: ========
! 25:
! 26: 1. Introduction
! 27: 1.1 Microsoft Visual C++ and GCC/MinGW
! 28: 1.2 WinPcap/Npcap
! 29: 1.3 Supported Operating Systems
! 30:
! 31: 2. MinGW Compiler
! 32: 2.1 Native
! 33: 2.2 Cross-Compiling
! 34:
! 35: 3. Microsoft Visual C++
! 36:
! 37:
! 38:
! 39: 1. Introduction
! 40: ===============
! 41:
! 42:
! 43: 1.1 Microsoft Visual C++ and GCC/MinGW
! 44: --------------------------------------------------------------
! 45:
! 46: The Microsoft Visual C++ compiler (aka MSVC) and the GCC Windows port
! 47: (aka MinGW) are unfortunately not fully compatible. Although MSVC is a
! 48: great compiler, libnet has been developed with the GNU toolchain in mind.
! 49: So building libnet with the Visual C++ Build Tools will always have its
! 50: flaws, even while it might work in some points.
! 51:
! 52: Most of libnet’s development is therefore done with GCC and its MinGW
! 53: Windows port.
! 54: In other words, if this this all new to you, I recommended you to use
! 55: MinGW for building libnet on Windows.
! 56:
! 57:
! 58: On the other hand, the two can work well together:
! 59:
! 60: If you for instance build libnet with MinGW, and you want to use it
! 61: with MSVC too (or vice versa), you can use the DLL and the supplied
! 62: "libnet*.def" file located in <libnet-root>/win32/ (this file is always
! 63: rebuild at the end of every successful build on windows) to create an
! 64: MSVC compatible import library that you can use to link your projects
! 65: with without the need of rebuilding libnet again.
! 66:
! 67: To produce a MinGW compatible import library from any libnet DLL:
! 68:
! 69: $ dlltool -D path/to/libnet*.dll -d path/to/libnet*.def -l libnet.dll.a
! 70:
! 71: To produce a MSVC compatible import library from any libnet DLL:
! 72:
! 73: $ lib /machine:X64 /def:example.def (for x64)
! 74: or
! 75: $ lib /machine:X86 /def:example.def (for x86)
! 76:
! 77: Note 1: If you have removed any or all symbol information from the DLL
! 78: (aka "stripped" it), during build, by for example running configure
! 79: with "--enable-fast", then this obviously won't work.
! 80:
! 81:
! 82: 1.2 WinPcap/Npcap
! 83: -----------------
! 84:
! 85: Currently, the supported method of sending packets under Windows is with
! 86: WinPcap (http://www.winpcap.org). However, libnet's support for
! 87: Npcap (http://www.npcap.org), an update of WinPcap sponsored by the
! 88: Nmap Project, is being seriously considered.
! 89: Windows users should know that with the switch to Npcap, WinPcap compatibility
! 90: is expected to be deprecated.
! 91:
! 92: Please be sure to install the WinPcap/Npcap driver/DLL and make sure
! 93: that the content of the Wpdpack's/Npcap SDK's Include and Lib directories
! 94: are somewhat reachable by your compiler.
! 95:
! 96: Note 2: Remember that you cannot use MSVC-generated .lib files to create
! 97: shared libraries with MinGW, you have to use the lib*.a files.
! 98: WinPcap development came to a standstill before the Developer's Pack ever
! 99: provided x64 compatible lib*.a files for use with MinGW/Cygwin. And since
! 100: libnet depends on WinPcap, you would have to compile 64-bit lib*.a libraries
! 101: yourself if you want to be able to produce 64-bit compatible libnet builds
! 102: with MinGW/Cygwin.
! 103:
! 104: Luckily for you, this has been taken care of by me. 64-bit compatible
! 105: WinPcap libraries as well as DIY instructions can be found in
! 106: <libnet-root>/win32/wpdpack/.
! 107:
! 108: 1.3 Supported Operating Systems
! 109: -------------------------------
! 110:
! 111: At the latest with the switch to Npcap, libnet support for Windows XP,
! 112: Windows Server 2003 and earlier will be dropped.
! 113: I can think of too many better things to do than to continuously deal with
! 114: error handling and backwards compatibility (msvcrt vs crtdll) for EOL systems.
! 115:
! 116: Remnants in the source suggests that building libnet with Cygwin must have
! 117: been possible at some point. This may or may not be the case these days.
! 118: If it still works, let me know. If you get it to work (again), let me know.
! 119: And if you need to get it to work, let me know.
! 120:
! 121:
! 122: 2. MinGW Compiler
! 123: =================
! 124:
! 125: Both native and cross compilation are possible, and there are quite a
! 126: few possibilities and options to choose from. If you just want to get
! 127: over with it, follow these steps:
! 128:
! 129: Known traps are:
! 130: - Setting the wrong (or no) prefix. (important when running 'make install')
! 131: - Using incompatible WinPcap libraries for x64 (see Note 2)
! 132: - Not having said WinPcap libraries and header files in your compiler's path
! 133:
! 134: Note 3: If you're building with MinGW, and want to install libnet to your
! 135: compiler's lib and include directories, you almost always want to set your
! 136: prefix manually. If you don't know what that means, run "gcc -v", look for
! 137: "--prefix=/some/path" and use that.
! 138:
! 139: Note 4: If you're using a multilib MinGW-w64 GCC compiler, make sure to add
! 140: the -m32 or -m64 CFLAGS to instruct the compiler to build for your desired
! 141: architecture.
! 142:
! 143:
! 144: 2.1 Native
! 145: ----------
! 146:
! 147: The recommended MinGW distribution for building libnet is Msys2.
! 148: First, follow the installation instructions for Msys2 available at
! 149: msys2.github.io. Then, depending on your desired target architecture,
! 150: open a mingw32 or mingw64 shell, navigate to the source directory,
! 151: and execute the following commands:
! 152:
! 153: 1. If you want to produce 32 bit binaries:
! 154:
! 155: $ CFLAGS="-O2 -Wall -I$(pwd)/win32/wpdpack/Include" LDFLAGS="-L$(pwd)/win32/wpdpack/Lib/" ./configure --prefix=/mingw64
! 156:
! 157: If you want to produce 64 bit binaries:
! 158:
! 159: $ CFLAGS="-O2 -Wall -I$(pwd)/win32/wpdpack/Include" LDFLAGS="-L$(pwd)/win32/wpdpack/Lib/x64" ./configure --prefix=/mingw64
! 160:
! 161: 2. $ make
! 162:
! 163: 3. $ make install (optional)
! 164:
! 165:
! 166: 2.2 Cross-Compiling
! 167: -------------------
! 168:
! 169: Note 5: During sample building, you may see a warning similar this:
! 170:
! 171: Could not determine the host path corresponding to
! 172: `... a path ...'
! 173: Continuing, but uninstalled executables may not work.
! 174:
! 175: This, among other things, means that the samples will depend on
! 176: a shared version of libgcc (aka libgcc_s_sjlj-1.dll). If no shared
! 177: version of libgcc was built when the compiler was configured, you
! 178: most likely won't be able to execute them.
! 179: In that case, your best bet is to link with the static version
! 180: of libgcc by disabling shared libraries altogether
! 181: (./configure --disable-shared).
! 182:
! 183:
! 184: In general, you should know what you're doing and what your host, target
! 185: and compiler are all about beforehand.
! 186: These steps have been successfully tested on Ubuntu and the default
! 187: mingw32-w32 toolchain (GCC 4.8).
! 188: The recommended steps to build libnet therefore are:
! 189:
! 190: 1. If you're targeting x86:
! 191: $ CFLAGS="-O2 -Wall -I$(pwd)/win32/wpdpack/Include" LDFLAGS="-L$(pwd)/win32/wpdpack/Lib" ./configure --host=i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32
! 192:
! 193: If you're targeting x64:
! 194: $ CFLAGS="-O2 -Wall -I$(pwd)/win32/wpdpack/Include" LDFLAGS="-L$(pwd)/win32/wpdpack/Lib/x64" ./configure --host=x86_64-w64-mingw32 --prefix=/usr/x86_64-w64-mingw32
! 195:
! 196: 2. make
! 197:
! 198: 3. (optionally) sudo make install
! 199:
! 200: Notice that the --host option is usually all you need for cross-compiling.
! 201:
! 202: Note 6: Although the steps should be very similar, if you're using any
! 203: other distribution of MinGW (cross or native), you're pretty much on
! 204: your own. Suggestions, bug reports/fixes, and pull requests, see:
! 205: https://github.com/libnet/libnet/issues
! 206:
! 207:
! 208: 3. Microsoft Visual C++
! 209: =======================
! 210: Known traps are:
! 211: - Not using the correct (x86 or x64) version of the Visual Studio command prompt
! 212: - Using incompatible WinPcap libraries for x64 (see Note 2)
! 213: - Not having said WinPcap libraries and header files in your compiler's path
! 214:
! 215: Until the issue described at the top of this document is completely
! 216: resolved, MSVC support should be considered a work in progress and unsafe.
! 217: And that’s why I won't even go into it, and instead leave you with these
! 218: old but still perfectly fine instructions:
! 219:
! 220:
! 221:
! 222: Run msvcbuild.bat to build for Win32 with MSVC
! 223: ----------------------------------------------
! 224:
! 225: The batch file takes arguments and sets the appropriate path and environment
! 226: variables for the desired built by running either vsvars32.bat (for x86),
! 227: vcvars64.bat (for x64) or vcvarsall.bat (for Cross development).
! 228: Type "msvcbuild.bat help" for a description of all available options.
! 229: If no argument is specified, x86 is assumed.
! 230:
! 231: The batch file copies pre-prepared headers out of win32/, avoiding the
! 232: requirement for a gnu (Cygwin or MinGW) build environment.
! 233:
! 234: The batch file hard-codes the location of the WinPcap developer's tools.
! 235: You may have to modify it for your environment, or install the developer's
! 236: pack in the expected location.
! 237:
! 238: Although not required, it is advisable to execute the batch file from a
! 239: VS2015 Developer Command Prompt.
! 240:
! 241: For Visual Studio 2015, the shell can be found at:
! 242:
! 243: Program Files (x86) >> Microsoft Visual Studio 14.0 >> Common7 >> Tools >> VsDevCmd.bat
! 244:
! 245: After building, libnet libraries and .obj files are found in newly created
! 246: "<libnet-root>\libnet\src\[Win32|Win64]\" "<libnet-root>\libnet\lib\[x86|x64]\"
! 247: respectively.
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>