标签:style blog http color io os 使用 ar for
>以下编译基于windows下visual studio 2013
从souceforge上下载libnet0.10.11.zip
http://sourceforge.net/projects/libnet/files/libnet/
解压之后目录结构:
源码文件在lib目录下;
batfiles中是编译用的脚本
msvcmake.bat
@echo off rem First set up the helper batch files cd batfiles copy msvcobj.bat obj.bat copy msvclib.bat lib.bat copy msvcexe.bat exe.bat rem Now do the generic build if "%1"=="" goto all goto %1 :all call makeall goto end :lib call makelib goto end :tests call maketest goto end :examples call makeex goto end :end cd ..
msvcobj.bat
@echo off cl /DTARGET_MSVC /MD /c /O2 /nologo /I../include /Iinclude %1.c /Fo%1.obj
msvclib.bat
@echo off lib /NODEFAULTLIB /out:%1.lib %2.obj %3.obj
msvcexe.bat
@echo off cl /DTARGET_MSVC /MD /O2 /nologo /I../include %1.c ../lib/libnet.lib wsock32.lib
--------------编译方法---------------
1.将batfile目录下的msvcmake.bat复制到上层目录(libnet)下,双击运行。
会在batfiles目录下生成obj.bat,lib.bat,exe.bat三个文件。
但是提示cl不是内部或者外部命令。本文适用的是vs2013,cl.exe位于如下目录下:
2.将C编译器的路径 C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin;
添加到环境变量PATH中。
3.新建环境变量include
将以下两个路径添加进include:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include
4.新建环境变量lib
将以下两个环境变量添加进lib:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib
5.双击make.bat成功编译出libnet.lib库
在core和drivers目录下生成了obj文件。
-------------使用-------------------
将inlcude/libnet.h和lib/libnet.lib分别放到
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include 和
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib 目录中
然后在代码中显式调用相关库:
#pragma comment(lib,"libnet.lib") #pragma comment(lib,"wsock32.lib")
标签:style blog http color io os 使用 ar for
原文地址:http://www.cnblogs.com/sunniflyer/p/3983663.html