Windows(x64)編譯FFMPEG-2.0.1

1、引言

公司須要作網絡視頻傳輸的相關項目,初步選定用這麼幾個東西FFMPEG,ORTP,Live555這麼幾個東東。研究了也有一個月了,把一些心得寫出來,這篇文章主要介紹FFMPEG在windows上的編譯。php


網上針對FFmpeg在windows上的編譯帖子不少,根據編譯在過程當中仍是出現了不少問題,多是因爲版本或者其餘的一些問題吧。這裏記錄了個人編譯過程,供你們查考。
感謝下面的文章,主要根據這幾篇文章來提取的內容:


我將全部須要的下載的庫和文件在個人資源中,FFMPEG2.0.1中下載。

http://download.csdn.net/detail/xi52qian/5983311

2、相關環境
windows7 x64旗艦版。
VS2010(打了SP1補丁)
Mingw-get-inst-20120426
yasm-1.2.0-win64
ffmpeg-2.0.1
lame-3.99.5
x264
xvidcore-1.3.2
faad2-2.7
faac-1.28
vo-aacenc-0.1.2
opencore-amr-0.1.3
vo-amrwbenc-0.1.2


3、編譯前準備
您最好新建一個目錄專門用來保存如下下載的文件。
1 下載 MinGW 和 MSYS
    MinGW(Minimalist GNU on Windows):一個可自由使用和自由發佈的Windows特定頭文件和使用GNU工具集導入庫的集合,容許你生成本地的Windows程序而不須要第三方C運行時庫。
    到:http://sourceforge.net/projects/mingw/ 去下載便可
    A 點擊「DownLoad mingw-get-inst-...exe」
    B 切換到頁面:download? Check your browser's security bar, or try a direct link, or try another mirror.
    C 點擊「direct link」下載相似:mingw-get-inst-20120426.exe 的文件
    提示:msys此處就不用再下載了,mingw-get-inst-20120426.exe 中已經包含了msys1.0,後面安裝的時候就能夠看到該選項。
2 下載 yasm(彙編編譯器)
    ffmpeg編譯的時候裏面的彙編代碼須要yasm.exe
    去官網:http://yasm.tortall.net/Download.html 下載
    文件名相似爲:yasm-1.2.0-win64.exe(若是是64位系統下載32位版本yasm-1.2.0-win32.exe)
3 下載 ffmpeg
    ffmpeg能夠到 http://www.ffmpeg.org/releases/ 下載
    選擇的一個最新版本下載便可,如:ffmpeg-2.0.1.tar.gz
    文件名相似爲:ffmpeg-2.0.1.tar.gz
    固然你也使用網上介紹的使用SVN直接下載源代碼的方法。 
    svn://svn.mplayerhq.hu/ffmpeg/trunk
4 下載 mp3lame(支持mp3,可選項)
    爲了讓編譯出來的ffmpeg支持對mp3格式的編解碼,您須要先下載lame。
    到:http://sourceforge.net/projects/lame/files/ 下載
    文件名相似爲:lame-3.99.5.tar.gz 的包。
5 下載 x264(支持x264,可選項)
    爲了讓編譯出來的ffmpeg支持對x264格式的編解碼,您須要先下載x264。
    到:http://www.videolan.org/developers/x264.html下載
    文件名相似爲:last_x264.tar.bz2 的包。
6 下載 Xvid(支持Xvid,可選項)
    爲了讓編譯出來的ffmpeg支持對Xvid格式的編解碼,您須要先下載Xvid。
    到:http://www.xvid.org/ 下載
    文件名相似爲:xvidcore-1.3.2.tar.gz 的包。
7 下載 faac(支持faac,可選項)
    到:http://www.audiocoding.com/downloads.html 下載:Version 1.28 bootstrapped TAR.GZ Package
    文件名相似爲:faac-1.28.tar.gz 的包。
8 下載 aacenc(支持aac,可選項)
    到:http://sourceforge.net/projects/opencore-amr/files/ 下載:vo-aacenc
    文件名相似爲:vo-aacenc-0.1.2.tar.gz 的包。
9 下載 opencore-amr與vo-amrwbenc (支持3gp,可選項)
    到:http://sourceforge.net/projects/opencore-amr/files/ 下載:opencore-amr 與 vo-amrwbenc
    文件名相似爲:opencore-amr-0.1.3.tar.gz 與vo-amrwbenc-0.1.2.tar.gz 的包。
10 下載 SDL(支持SDL,可選項)
    SDL下載能夠到:http://www.libsdl.org/download-1.2.php
    在Source Code欄選擇相似:SDL-1.2.15.tar.gz - GPG signed 進行下載,
    文件名相似爲:SDL-1.2.15.tar.gz,此文件須要編譯才能生成lib庫。

四 編譯步驟
1 安裝 mingw 和 msys
    執行下載文件:mingw-get-inst-20120426.exe,
    在第3步選擇「Download latest repository catalogues」
    選擇安裝路徑:D:\Files\MinGW
    在「Select Components」步驟中選擇:
      √  C Compiler (默認且必定選擇)
      √  C++ Compiler
      √  MSYS Basic System(選擇此項將會安裝msys,msys則不須要另外安裝)
      √  MinGW Developer ToolKit
    等待安裝完成!(須要等待必定的時間,由於安裝過程須要下載文件,可想而知,網速越快,安裝越快)
    安裝完成後,在D:\Files\MinGW目錄下能夠看到 msys 文件夾,msys也已經安裝。
html

2 配置 msys.bat 批處理文件
    爲了方便VS2010調用ffmpeg的動態庫,能夠經過配置讓ffmpeg編譯時產生windows下調用dll對應的lib,固然,若是你沒有這個須要,那麼就能夠省略如下處理,直接進入步驟3。
    進入:D:\Files\MinGW\msys\1.0\文件夾,使用UltraEdit打開msys.bat文件,在文件的最最前面加入以下一行:
redis

    call "D:\Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
    添加後效果以下:
     
 1 call "D:\Program Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
 2          @echo off
 3          rem Copyright (C):  2001, 2002, 2003, 2004, 2005  Earnie Boyd
 4          rem   mailto:earnie@users.sf.net
 5          rem This file is part of Minimal SYStem
 6          rem   http://www.mingw.org/msys.shtml
 7          rem
 8          rem File:     msys.bat
 9          rem Revision:     2.4
10          rem Revision Date:  December 8th, 2005
11          rem ember to set the "Start in:" field of the shortcut.
12          rem A value similar to C:\msys\1.0\bin is what the "Start in:" field needs
13          rem to represent.
View Code

 


    其中「D:\Files\Microsoft Visual Studio 10.0」爲你機器上安裝VS2010的目錄安裝在了D盤。文件修改後保存便可。

3 系統整合
    使用UltraEdit修改D:\Files\MinGW\msys\1.0\etc目下的fstab文件,修改其內容爲:D:/Files/MinGW,也即爲MinGW的安裝路徑。

4 添加環境變量
   在環境變量PATH前面添加 D:\Files\MinGW\msys\1.0\bin;

4 配置 yasm
    爲了減小配置環境變量的麻煩,本處直接把yasm-1.1.0-win64.exe 文件名修改爲:yasm.exe,並放到目錄:D:\Files\MinGW\msys\1.0\bin

5 編譯 mp3lame(可選項)
    lame-3.99.5.tar.gz 接壓到:D:\Library\ffmpeg\ 目錄下,雙擊「D:\Files\MinGW\msys\1.0\msys.bat」,啓動「MinGW32」,切換到lame目錄:D:\ffmpeg \lame-3.99.5
    $ cd /d
    $ cd Library/ffmpeg/lame-3.99.5
    再執行如下命令:
    $./configure --disable-shared (首選)
     $ make
     $ make install
    編譯結果在:D:\Files\MinGW\msys\1.0\local 目錄下
6 編譯 x264(可選項)
    last_x264.tar.bz2 接壓到:D:\Library\ffmpeg\ 目錄下,雙擊「D:\Files\MinGW\msys\1.0\msys.bat」,啓動「MinGW32」,切換到x264目錄:D: \Library\ffmpeg\x264-snapshot-20130630-2245

    $ cd /d
    $ cd Library/ffmpeg/x264-snapshot-20130630-2245
    再執行如下命令:
    $./configure --enable-shared --disable-asm
    用UE打開config.mak文件,修改:(64位系統)
    CFLAGS=-Wshadow -O3 -ffast-math -m32  -Wall -I. -I$(SRCPATH) -std=gnu99 -fomit-frame-pointer -fno-tree-vectorize -fno-zero-initialized-in-bss
    爲:
    CFLAGS=-Wshadow -O3 -ffast-math -m32  -Wall -I. -I$(SRCPATH) -std=gnu99 -fomit-frame-pointer -fno-tree-vectorize -fno-zero-initialized-in-bss -march=i686
    $ make
    $ make install
    編譯結果在:D:\Files\MinGW\msys\1.0\local 目錄下
7 編譯 Xvid(可選項)
    xvidcore-1.3.2.tar.gz 接壓到:D:\Files\Library\ffmpeg\ 目錄下,雙擊「D:\Files\MinGW\msys\1.0\msys.bat」,啓動「MinGW32」,切換到xvidcore目錄:D: \Files\Library\ffmpeg\xvidcore\build\generic
    $ cd /d
    $ cd Files/Library/ffmpeg/xvidcore/build/generic
    再執行如下命令:
    $./configure --prefix=d:/Files/MinGW/msys/1.0/local
    $ make
    $ make install
    編譯結果在:D:\Files\MinGW\msys\1.0\local 目錄下。
    須要注意的就是:此處編譯加上了路徑
    若是make時出現:cc1.exe: error: unrecognized command line option '-mno-cygwin' 錯誤,請在./configure後make以前修改xvidcore\build\generic裏的 platform.inc文件,直接刪除裏面的「-mno-cygwin」。

8 編譯faac(可選項)
    faac-1.28.tar.gz 接壓到:D:\Files\Library\ffmpeg\ 目錄下,雙擊「D:\Files\MinGW\msys\1.0\msys.bat」,啓動「MinGW32」,已經啓動的話就不用再從新啓動了。切換到 faac目 錄:D:\Files\Library\ffmpeg\faac-1.28
    將我提供的目錄中的文件faac-1.28.diff拷貝到D:\Files\Library\ffmpeg\faac-1.28目錄下,此文件是補丁文件,否則編譯沒法經過。
    $ cd /d
    $ cd Files\Library\ffmpeg\faac-1.28
    再執行如下命令:
    $ patch -p1 < faac-1.28.diff
    $./bootstrap
    $./configure --disable-static --enable-shared
    $ make
    $ make install
    編譯結果在:D:\Files\MinGW\msys\1.0\local 目錄下

   不用編譯faad2,新版本 ffmpeg內置已經支持aac編碼、解碼,不須要libfaac、libfaad了,並且libfaac是nonfree的,nonfree是unredistributable即禁止發佈。

9 編譯vo-aacenc (可選項)
    vo-aacenc-0.1.2.tar.gz 接壓到:D:\Files\Library\ffmpeg\ 目錄下,雙擊「D:\Files\MinGW\msys\1.0\msys.bat」,啓動「MinGW32」,已經啓動的話就不用再從新啓動了。切換到 vo- aacenc目錄:D:\Files\Library\ffmpeg\vo-aacenc-0.1.2
    $ cd /d
    $ cd Files\Library\ffmpeg\vo-aacenc-0.1.2
    $ cd vo-aacenc-0.1.2
    再執行如下命令:
    $./configure --disable-shared
    $ make
    $ make install
    編譯結果在:D:\Files\MinGW\msys\1.0\local 目錄下

10 編譯opencore-amr 和vo-amrwbenc (可選項)
    opencore-amr-0.1.3.tar.gz 接壓到:D:\Files\Library\ffmpeg\ 目錄下,雙擊「D:\Files\MinGW\msys\1.0\msys.bat」,啓動「MinGW32」,已經啓動的話就不用再從新啓動了。
    切換到opencore-amr目錄:D:\Files\Library\ffmpeg\opencore-amr-0.1.3
    $ cd /d
    $ cd Files\Library\ffmpeg\opencore-amr-0.1.3
    再執行如下命令:
    $./configure --disable-shared
    $ make CC=gcc
    $ make install
    編譯結果在:D:\Files\MinGW\msys\1.0\local 目錄下
    vo-amrwbenc-0.1.2.tar.gz 接壓到: D:\Files\Library\ffmpeg\ 目錄下,雙擊「D:\Files\MinGW\msys\1.0\msys.bat」,啓動「MinGW32」,已經啓動的話就不用再從新啓動了。切換到vo-amrwbenc目錄:D:\Files\Library\vo-amrwbenc-0.1.2
    $ cd /d
    $ cd Files\Library\vo-amrwbenc-0.1.2
    再執行如下命令:
    $./configure --disable-shared
    $ make CC=gcc
    $ make install
    編譯結果在:D:\Files\MinGW\msys\1.0\local 目錄下

11 編譯SDL(可選項)
   SDL-1.2.15.tar.tar 解壓到:D:\Files\Library\ffmpeg\ 目錄下, 雙擊「D:\Files\MinGW\msys\1.0\msys.bat」,啓動「MinGW32」,切換到SDL目錄:D:\ffmpeg\SDL- 1.2.15,切換方法以下:
    $ cd /d
    $ cd Files\Library\ffmpeg
    $ cd SDL-1.2.15
    再執行如下命令:
    ./configure
    make
    make install
    編譯結果在:D:\Files\MinGW\msys\1.0\local 目錄下 

    使用UltraEdit打開D:\Files\MinGW\msys\1.0\local\bin下的 sdl-config文件
    把 prefix=/usr/local 該成: prefix=d:/Files/MinGW
    其中:D:/Files/MinGW 爲 mingw的安裝路徑,請根據你的安裝進行修改。爲了編譯時msys能識別sdl並開啓 SDL support yes 進行編譯,請把D:\Files\MinGW\msys\1.0\local編譯結果bin、include和lib中有關sdl的拷貝一份到D: \Files\MinGW\的對 應目錄中。

12 編譯 ffmpeg
    安裝下載pkg-config for MinGW/msys
     安裝方法:把pkg-config.ex e 和 libglib-2.0-0.DLL複製到環境變量包括的任意一個文件夾內,我是複製到MinGW安裝路徑\msys\1.0\bin
    ffmpeg-2.0.1.tar.gz 解壓到:D:\Files\Library\ffmpeg\ 目錄下,雙擊「D:\Files\MinGW\msys\1.0\msys.bat」,啓動「MinGW32」,切換到ffmpeg目錄:D:\Files\Library\ffmpeg\ffmpeg-2.0.1,切換方法以下:
    $ cd /d
    $ cd Files\Library\ffmpeg\ffmpeg-2.0.1
    再執行如下命令:
    $ ./configure --enable-shared --disable-static --enable-ffplay
    --enable-nonfree --enable-memalign-hack
    --enable-libmp3lame
    --enable-gpl
    --enable-libx264  
    --enable-libxvid 
    --enable-libfaac
    --enable-libvo-aacenc
    --enable-version3 
    --enable-libopencore-amrnb  
    --enable-libopencore-amrwb 
    --enable-libvo-amrwbenc
    --extra-cflags=-Id:/Files/MinGW/msys/1.0/local/include
    --extra-ldflags=-Ld:/Files/MinGW/msys/1.0/local/lib
    --cpu=i686
    注:若是64位系統不添加"--cpu=i686" 編譯過程當中會報 Threading is enabled, but there is no implementation of atomic operations available。        

    請耐心等待一段時間,以上命令不能直接換行哦而且根據ffmpeg的版本不一樣有所變化,具體看./configure --help,你知道的。。。
    $ make
    須要等待很長一段時間,等待編譯結束。
    爲了彙總編譯結果,請繼續執行如下命令:
    $ make install
    等待完成,在d:/Files/Library/ffmpeg/ffmpeg-2.0.1中將會生成 bin、include、lib等文件夾,其中包含了ffmpeg.exe、ffplay.exe、ffprobe.exe、dll、lib和頭文件等。

13 運行測試
  確實如下dll:
  libx264-133.dll 和 sdl.dll在  D:\Files\MinGW\msys\1.0\local\bin找到。
  xvidcore.dll在D:\Files\MinGW\msys\1.0\local\lib 找到。
  pthreadGC2.dll 和 libiconv-2.dll 在D:\Files\MinGW\bin 找到。

14 引用DLL
提示沒法找到" #include <inttypes.h>"。
建立文件inttypes.h
  1 #ifndef _INTTYPES_H_ALL_  
  2 #define _INTTYPES_H_ALL_  
  3   
  4 // _INTTYPES_H_SYS_: 編譯器是否提供了<inttypes.h>  
  5 #undef _INTTYPES_H_SYS_  
  6 #if defined(__GNUC__)    // GCC.  
  7     #define _INTTYPES_H_SYS_  
  8 #elif defined(_MSC_VER)    // MSVC. VC2010仍不支持.  
  9 #elif defined(__BORLANDC__)    // BCB. BCB6仍不支持.  
 10 #else  
 11     #define _INTTYPES_H_SYS_    // 假設其餘編譯器支持C99.  
 12 #endif    // _INTTYPES_H_SYS_  
 13   
 14   
 15 #ifdef _INTTYPES_H_SYS_  
 16 // 使用編譯器提供的<inttypes.h>  
 17 #include <inttypes.h>  
 18 #else  
 19 // 採用自定義的inttypes.h. 參考了 msinttypes: http://code.google.com/p/msinttypes/  
 20   
 21 #ifndef _MSC_INTTYPES_H_ // [  
 22 #define _MSC_INTTYPES_H_  
 23   
 24 #include "stdint.h"  
 25   
 26 // 7.8 Format conversion of integer types  
 27   
 28 typedef struct {  
 29    intmax_t quot;  
 30    intmax_t rem;  
 31 } imaxdiv_t;  
 32   
 33 // 7.8.1 Macros for format specifiers  
 34   
 35 #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [   See footnote 185 at page 198  
 36   
 37 // The fprintf macros for signed integers are:  
 38 #define PRId8       "d"  
 39 #define PRIi8       "i"  
 40 #define PRIdLEAST8  "d"  
 41 #define PRIiLEAST8  "i"  
 42 #define PRIdFAST8   "d"  
 43 #define PRIiFAST8   "i"  
 44   
 45 #define PRId16       "hd"  
 46 #define PRIi16       "hi"  
 47 #define PRIdLEAST16  "hd"  
 48 #define PRIiLEAST16  "hi"  
 49 #define PRIdFAST16   "hd"  
 50 #define PRIiFAST16   "hi"  
 51   
 52 #if defined(_MSC_VER) && _MSC_VER<=1200    // VC6  
 53 #define PRId32       "d"  
 54 #define PRIi32       "i"  
 55 #define PRIdLEAST32  "d"  
 56 #define PRIiLEAST32  "i"  
 57 #define PRIdFAST32   "d"  
 58 #define PRIiFAST32   "i"  
 59 #else  
 60 #define PRId32       "I32d"  
 61 #define PRIi32       "I32i"  
 62 #define PRIdLEAST32  "I32d"  
 63 #define PRIiLEAST32  "I32i"  
 64 #define PRIdFAST32   "I32d"  
 65 #define PRIiFAST32   "I32i"  
 66 #endif  
 67   
 68 #define PRId64       "I64d"  
 69 #define PRIi64       "I64i"  
 70 #define PRIdLEAST64  "I64d"  
 71 #define PRIiLEAST64  "I64i"  
 72 #define PRIdFAST64   "I64d"  
 73 #define PRIiFAST64   "I64i"  
 74   
 75 #define PRIdMAX     "I64d"  
 76 #define PRIiMAX     "I64i"  
 77   
 78 #define PRIdPTR     "Id"  
 79 #define PRIiPTR     "Ii"  
 80   
 81 // The fprintf macros for unsigned integers are:  
 82 #define PRIo8       "o"  
 83 #define PRIu8       "u"  
 84 #define PRIx8       "x"  
 85 #define PRIX8       "X"  
 86 #define PRIoLEAST8  "o"  
 87 #define PRIuLEAST8  "u"  
 88 #define PRIxLEAST8  "x"  
 89 #define PRIXLEAST8  "X"  
 90 #define PRIoFAST8   "o"  
 91 #define PRIuFAST8   "u"  
 92 #define PRIxFAST8   "x"  
 93 #define PRIXFAST8   "X"  
 94   
 95 #define PRIo16       "ho"  
 96 #define PRIu16       "hu"  
 97 #define PRIx16       "hx"  
 98 #define PRIX16       "hX"  
 99 #define PRIoLEAST16  "ho"  
100 #define PRIuLEAST16  "hu"  
101 #define PRIxLEAST16  "hx"  
102 #define PRIXLEAST16  "hX"  
103 #define PRIoFAST16   "ho"  
104 #define PRIuFAST16   "hu"  
105 #define PRIxFAST16   "hx"  
106 #define PRIXFAST16   "hX"  
107   
108 #if defined(_MSC_VER) && _MSC_VER<=1200    // VC6  
109 #define PRIo32       "o"  
110 #define PRIu32       "u"  
111 #define PRIx32       "x"  
112 #define PRIX32       "X"  
113 #define PRIoLEAST32  "o"  
114 #define PRIuLEAST32  "u"  
115 #define PRIxLEAST32  "x"  
116 #define PRIXLEAST32  "X"  
117 #define PRIoFAST32   "o"  
118 #define PRIuFAST32   "u"  
119 #define PRIxFAST32   "x"  
120 #define PRIXFAST32   "X"  
121 #else  
122 #define PRIo32       "I32o"  
123 #define PRIu32       "I32u"  
124 #define PRIx32       "I32x"  
125 #define PRIX32       "I32X"  
126 #define PRIoLEAST32  "I32o"  
127 #define PRIuLEAST32  "I32u"  
128 #define PRIxLEAST32  "I32x"  
129 #define PRIXLEAST32  "I32X"  
130 #define PRIoFAST32   "I32o"  
131 #define PRIuFAST32   "I32u"  
132 #define PRIxFAST32   "I32x"  
133 #define PRIXFAST32   "I32X"  
134 #endif  
135   
136 #define PRIo64       "I64o"  
137 #define PRIu64       "I64u"  
138 #define PRIx64       "I64x"  
139 #define PRIX64       "I64X"  
140 #define PRIoLEAST64  "I64o"  
141 #define PRIuLEAST64  "I64u"  
142 #define PRIxLEAST64  "I64x"  
143 #define PRIXLEAST64  "I64X"  
144 #define PRIoFAST64   "I64o"  
145 #define PRIuFAST64   "I64u"  
146 #define PRIxFAST64   "I64x"  
147 #define PRIXFAST64   "I64X"  
148   
149 #define PRIoMAX     "I64o"  
150 #define PRIuMAX     "I64u"  
151 #define PRIxMAX     "I64x"  
152 #define PRIXMAX     "I64X"  
153   
154 #define PRIoPTR     "Io"  
155 #define PRIuPTR     "Iu"  
156 #define PRIxPTR     "Ix"  
157 #define PRIXPTR     "IX"  
158   
159 // The fscanf macros for signed integers are:  
160 #define SCNd8       "d"  
161 #define SCNi8       "i"  
162 #define SCNdLEAST8  "d"  
163 #define SCNiLEAST8  "i"  
164 #define SCNdFAST8   "d"  
165 #define SCNiFAST8   "i"  
166   
167 #define SCNd16       "hd"  
168 #define SCNi16       "hi"  
169 #define SCNdLEAST16  "hd"  
170 #define SCNiLEAST16  "hi"  
171 #define SCNdFAST16   "hd"  
172 #define SCNiFAST16   "hi"  
173   
174 #define SCNd32       "ld"  
175 #define SCNi32       "li"  
176 #define SCNdLEAST32  "ld"  
177 #define SCNiLEAST32  "li"  
178 #define SCNdFAST32   "ld"  
179 #define SCNiFAST32   "li"  
180   
181 #define SCNd64       "I64d"  
182 #define SCNi64       "I64i"  
183 #define SCNdLEAST64  "I64d"  
184 #define SCNiLEAST64  "I64i"  
185 #define SCNdFAST64   "I64d"  
186 #define SCNiFAST64   "I64i"  
187   
188 #define SCNdMAX     "I64d"  
189 #define SCNiMAX     "I64i"  
190   
191 #ifdef _WIN64 // [  
192 #  define SCNdPTR     "I64d"  
193 #  define SCNiPTR     "I64i"  
194 #else  // _WIN64 ][  
195 #  define SCNdPTR     "ld"  
196 #  define SCNiPTR     "li"  
197 #endif  // _WIN64 ]  
198   
199 // The fscanf macros for unsigned integers are:  
200 #define SCNo8       "o"  
201 #define SCNu8       "u"  
202 #define SCNx8       "x"  
203 #define SCNX8       "X"  
204 #define SCNoLEAST8  "o"  
205 #define SCNuLEAST8  "u"  
206 #define SCNxLEAST8  "x"  
207 #define SCNXLEAST8  "X"  
208 #define SCNoFAST8   "o"  
209 #define SCNuFAST8   "u"  
210 #define SCNxFAST8   "x"  
211 #define SCNXFAST8   "X"  
212   
213 #define SCNo16       "ho"  
214 #define SCNu16       "hu"  
215 #define SCNx16       "hx"  
216 #define SCNX16       "hX"  
217 #define SCNoLEAST16  "ho"  
218 #define SCNuLEAST16  "hu"  
219 #define SCNxLEAST16  "hx"  
220 #define SCNXLEAST16  "hX"  
221 #define SCNoFAST16   "ho"  
222 #define SCNuFAST16   "hu"  
223 #define SCNxFAST16   "hx"  
224 #define SCNXFAST16   "hX"  
225   
226 #define SCNo32       "lo"  
227 #define SCNu32       "lu"  
228 #define SCNx32       "lx"  
229 #define SCNX32       "lX"  
230 #define SCNoLEAST32  "lo"  
231 #define SCNuLEAST32  "lu"  
232 #define SCNxLEAST32  "lx"  
233 #define SCNXLEAST32  "lX"  
234 #define SCNoFAST32   "lo"  
235 #define SCNuFAST32   "lu"  
236 #define SCNxFAST32   "lx"  
237 #define SCNXFAST32   "lX"  
238   
239 #define SCNo64       "I64o"  
240 #define SCNu64       "I64u"  
241 #define SCNx64       "I64x"  
242 #define SCNX64       "I64X"  
243 #define SCNoLEAST64  "I64o"  
244 #define SCNuLEAST64  "I64u"  
245 #define SCNxLEAST64  "I64x"  
246 #define SCNXLEAST64  "I64X"  
247 #define SCNoFAST64   "I64o"  
248 #define SCNuFAST64   "I64u"  
249 #define SCNxFAST64   "I64x"  
250 #define SCNXFAST64   "I64X"  
251   
252 #define SCNoMAX     "I64o"  
253 #define SCNuMAX     "I64u"  
254 #define SCNxMAX     "I64x"  
255 #define SCNXMAX     "I64X"  
256   
257 #ifdef _WIN64 // [  
258 #  define SCNoPTR     "I64o"  
259 #  define SCNuPTR     "I64u"  
260 #  define SCNxPTR     "I64x"  
261 #  define SCNXPTR     "I64X"  
262 #else  // _WIN64 ][  
263 #  define SCNoPTR     "lo"  
264 #  define SCNuPTR     "lu"  
265 #  define SCNxPTR     "lx"  
266 #  define SCNXPTR     "lX"  
267 #endif  // _WIN64 ]  
268   
269 #endif // __STDC_FORMAT_MACROS ]  
270   
271 // 7.8.2 Functions for greatest-width integer types  
272   
273 // 7.8.2.1 The imaxabs function  
274 #define imaxabs _abs64  
275   
276 // 7.8.2.2 The imaxdiv function  
277   
278 #ifdef _MSC_VER  
279 // This is modified version of div() function from Microsoft's div.c found  
280 // in %MSVC.NET%\crt\src\div.c  
281 #ifdef STATIC_IMAXDIV // [  
282 static  
283 #else // STATIC_IMAXDIV ][  
284 _inline  
285 #endif // STATIC_IMAXDIV ]  
286 imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)  
287 {  
288    imaxdiv_t result;  
289   
290    result.quot = numer / denom;  
291    result.rem = numer % denom;  
292   
293    if (numer < 0 && result.rem > 0) {  
294       // did division wrong; must fix up  
295       ++result.quot;  
296       result.rem -= denom;  
297    }  
298   
299    return result;  
300 }  
301 #endif  // #ifdef _MSC_VER  
302   
303 // 7.8.2.3 The strtoimax and strtoumax functions  
304 #define strtoimax _strtoi64  
305 #define strtoumax _strtoui64  
306   
307 // 7.8.2.4 The wcstoimax and wcstoumax functions  
308 #define wcstoimax _wcstoi64  
309 #define wcstoumax _wcstoui64  
310   
311   
312 #endif // _MSC_INTTYPES_H_ ]  
313   
314 #endif // #ifdef _INTTYPES_H_SYS_  
315   
316 #endif // #ifndef _INTTYPES_H_ALL_ 
inittypes.h

 

參考:http://www.cnblogs.com/zyl910/archive/2012/08/08/c99int.html

將文件放到 D:\Files\Microsoft Visual Studio 10.0\VC\include 目錄下,D:\Files\Microsoft Visual Studio 10.0是你VS的安裝目錄。

歡迎轉載,轉載請註明出處。。。。。

相關文章
相關標籤/搜索