The entire compilation project has been uploaded to CSDN: libjpeg compilation project
Preparation before work
Download the latest version of Libjpeg source code from the IJG website, the URL is as follows:
http://www.ijg.org/
The version I downloaded is: jpegsr9b; of
course, please install the C++ compilation environment of VS2012;
Sort out and compile libjpeg dependency files
Because the jpegsr9b.zip we downloaded after decompression not only contains the source files for compiling Libjpeg.lib, but also contains many samples for testing, these samples are not needed when we compile lib.
First open the text file maketfil.v10, see Has the following:
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
We find the header files needed when compiling lib through Header Files, and then copy them to a new directory: include/ directory; through Source Files, find the source files needed when compiling lib, and copy them to the new directory: source/ directory;
The header file jconfig.h cannot be used by default, you need to rename jconfig.vc to jconfig.h for use;
Build a compile project
Create a new win32 project in VS2012, and choose to compile the static library; as shown below:
right-click to select "header file" and "source file" on the left, and select Add->Existing Phase, respectively, to sort out the include from the previous step. The header files in the directory and the source files in the source directory are added to the project; the result after adding is as follows:
Click "Project"->"Properties"->"Configuration Properties"->"C/C++"->"General" in turn, add the path of the previous include directory in the additional include directory, otherwise the header will not be found when compiling File errors, as shown below:
After selecting the preprocessor, add these two macros to the preprocessor definition:
_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE
Because libjpeg's source file uses many functions that are considered unsafe in VS2012, if there is no preprocessing definition above, an error will be reported during compilation, similar to the following error:
:\vs_programer\libjpeg\libjpeg\source\jdmarker.c(331): error C4996: ‘strncpy’: This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\string.h(191) : 参见“strncpy”的声明
After adding the two preprocessing definitions mentioned above, the compiler will ignore this warning; then press F7 to compile the entire project, and finally generate Libjpeg.lib successfully, as shown below:
After completion, the generated libjpeg.lib can be added to other projects to encode and decode jpeg images;