C++ 编译libjpeg
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12652178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Compiling libjpeg
提问by NiVeR
Is there anyone who succeed to include libjpeg in some compiler? I tried everything: Dev C++, VS10, CodeBlocks, copy the headers and the lib by hand, add with the linker but nothing. Right now I am really confisued as there is not an official guide on how to compile it in any compiler. I would be really happy if someone could provide a tutorial on how the library can be compiled in any compiler. Thank you in advance.
有没有人成功地将 libjpeg 包含在某个编译器中?我尝试了所有方法:Dev C++、VS10、CodeBlocks,手动复制头文件和库,添加链接器但什么也没有。现在我真的很困惑,因为没有关于如何在任何编译器中编译它的官方指南。如果有人可以提供有关如何在任何编译器中编译库的教程,我会非常高兴。先感谢您。
采纳答案by overcoder
Here is how I've built libjpeg using MinGW on Windows :
这是我在 Windows 上使用 MinGW 构建 libjpeg 的方法:
1. Get MinGW with MSYS
1. 使用 MSYS 获取 MinGW
I've got a copy from http://sourceforge.net/projects/mingw/. Quoting from www.mingw.org :
我有一份来自http://sourceforge.net/projects/mingw/的副本。引自 www.mingw.org :
MSYS is a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditionally UNIX tools to be present.
MSYS 是 GNU 实用程序的集合,例如 bash、make、gawk 和 grep,用于构建依赖于传统 UNIX 工具的应用程序和程序。
We will need it to run the configure
script that comes with libjpeg sources.
我们将需要它来运行configure
libjpeg 源代码附带的脚本。
2. Get libjpeg sources
2. 获取 libjpeg 源码
From http://www.ijg.org/, take the Unix format package (the Windows one won't work with this procedure). I took the jpeg_8d
version.
从http://www.ijg.org/获取 Unix 格式的软件包(Windows 格式的软件包不适用于此过程)。我拿了jpeg_8d
版本。
3. Prepare a building directory
3.准备一个构建目录
I've made a temporary directory named tmp
in D:\
, but you could choose whatever suits your needs. The thing that matters is the name of paths in MSYS. As it brings some * Unixity* to Windows, paths cannot be used in their original form.
In a nutshell:
我已经创建了一个名为tmp
in的临时目录D:\
,但您可以选择适合您需要的任何目录。重要的是 MSYS 中路径的名称。由于它为Windows带来了一些 * Unixity*,路径不能以其原始形式使用。简而言之:
C:\path\to\file
becomes /c/path/to/file
in MSYS land, an so
D:\tmp
becomes /d/tmp
.
C:\path\to\file
成为 /c/path/to/file
在MSYS土地,一个这样
D:\tmp
变成 /d/tmp
。
Decompress the libjpeg sources in D:\tmp
, so you have a jpeg-8d
directory in there.
解压 中的 libjpeg 源代码D:\tmp
,这样你就有了一个jpeg-8d
目录。
Create a jpeg-build
directory inside D:\tmp
, it will hold the built library.
jpeg-build
在里面创建一个目录D:\tmp
,它将保存构建的库。
Now everything is ready for the build.
现在一切都已准备好进行构建。
4. ./configure, make, make install
4../configure, make, make install
That is the mantra of building in Unix land. An option should be added to redirect the install process to D:\tmp\jpeg-build
.
这是在 Unix 土地上建设的口头禅。应该添加一个选项以将安装过程重定向到D:\tmp\jpeg-build
.
Run the following commands in an MSYS shell (also named MinGW shell in Windows start menu):
在 MSYS shell(在 Windows 开始菜单中也称为 MinGW shell)中运行以下命令:
cd /d/tmp/jpeg-8d
./configure --prefix=/d/tmp/jpeg-build
make
make install
As an additional step, you can run make test
for safety.
作为一个额外的步骤,你可以make test
为了安全而跑步。
These commands will build both static and shared versions of libjpeg.
这些命令将构建 libjpeg 的静态和共享版本。
5. Take the goods, delete the temporaries
5.拿货,删除临时工
If everything runs fine, you can delete the D:\tmp\jpeg-8d
directory, but keep the jpeg-build
one. It contains:
如果一切正常,您可以删除该D:\tmp\jpeg-8d
目录,但保留该目录jpeg-build
。它包含了:
- an
include
directory, containing libjpeg headers. You can move them to your compiler's headers directory. - a
lib
directory, with.a
file to pass to the linker. You can move them to your compiler's library directory. - a
bin
directory, holding the libjpeg shared librarylibjpeg-8.dll
and jpeg tools. - a
share
directory, containingman
pages for the jpeg tools.
- 一个
include
目录,包含 libjpeg 头文件。您可以将它们移动到编译器的头文件目录。 - 一个
lib
目录,包含.a
要传递给链接器的文件。您可以将它们移动到编译器的库目录中。 - 一个
bin
目录,包含 libjpeg 共享库libjpeg-8.dll
和 jpeg 工具。 - 一个
share
目录,包含man
jpeg 工具的页面。
You can now build your program and link it against libjpeg by indicating the right include and library paths.
您现在可以通过指明正确的包含和库路径来构建您的程序并将其链接到 libjpeg。
You can find many details about the libjpeg building and installation process in install.txt
inside the source package.
您可以install.txt
在源代码包中找到有关 libjpeg 构建和安装过程的许多详细信息。
I hope this will be useful.
我希望这会很有用。
回答by AthanasiusOfAlex
To compile libjpeg
9 in Visual Studio 2012, here are the steps (after unzipping the archive file):
要libjpeg
在 Visual Studio 2012 中编译9,步骤如下(解压存档文件后):
Download the file
WIN32.MAK
(for example, from http://www.bvbcode.com/code/f2kivdrh-395674-down), and place a copy in the root source code directory (possiblyC:\jpeg-9
, but it depends where you unzipped it). I will refer to this directory as%jpegsrc%
from now on. Having this file is important; otherwise step 3 will produce an error.In the Visual Studio command prompt, open to
%jpegsrc%
:cd %jpegsrc%
At the same command prompt, execute the following:
NMAKE /f makefile.vc setup-v10
This will create two Visual Studio 2010 solutions in
%jpegsrc%
:jpeg.sln
andapps.sln
.Open each solution in Visual Studio 2012. Each one will prompt you to update all the projects to 2012 format. Click on “Update.” One time I did it, the prompt did not appear. In case that happens, right-click on the
jpeg
solution in the Solution Explorer, and choose “Update VC++ projects...,” which will produce the same prompt.Save and build each solution as normal. (You have to build the
jpeg.sln
solution beforeapps.sln
, since the latter depends on the former.)
下载该文件
WIN32.MAK
(例如,从http://www.bvbcode.com/code/f2kivdrh-395674-down),并在源代码根目录中放置一个副本(可能是C:\jpeg-9
,但这取决于您将其解压缩的位置)。%jpegsrc%
从现在开始,我将参考这个目录。拥有这个文件很重要;否则步骤 3 将产生错误。在 Visual Studio 命令提示符中,打开到
%jpegsrc%
:cd %jpegsrc%
在相同的命令提示符下,执行以下命令:
NMAKE /f makefile.vc setup-v10
这将在
%jpegsrc%
:jpeg.sln
和apps.sln
.在 Visual Studio 2012 中打开每个解决方案。每个解决方案都会提示您将所有项目更新为 2012 格式。点击“更新”。我做了一次,提示没有出现。如果发生这种情况,请在
jpeg
解决方案资源管理器中右键单击解决方案,然后选择“更新 VC++ 项目...”,这将产生相同的提示。像往常一样保存和构建每个解决方案。(您必须在
jpeg.sln
之前构建解决方案apps.sln
,因为后者取决于前者。)
Note: this process should work correctly in Visual Studio 2010, without the updating, but I have not tested it.
注意:此过程在 Visual Studio 2010 中应该可以正常工作,无需更新,但我尚未对其进行测试。
Update:This method still works in Visual Studio 2015 for libjpeg-9a
.
更新:此方法在 Visual Studio 2015 for libjpeg-9a
.
回答by Miguel
It is really simple to build jpeg.lib with VS10.
用 VS10 构建 jpeg.lib 真的很简单。
First, download the libjpeg source code in zip format. At the time I'm writing this you can find it here.
首先,下载 zip 格式的 libjpeg 源代码。在我写这篇文章的时候,你可以在这里找到它。
Then extract the contents of the zip file to your disk.
然后将 zip 文件的内容解压缩到您的磁盘。
Then open a VS2010 command prompt shell (or call vcvarsall.bat on any command prompt window), cd to the jpeg source directory (jpeg-8d in the download referenced above) and type the following:
然后打开一个 VS2010 命令提示符 shell(或在任何命令提示符窗口中调用 vcvarsall.bat),cd 到 jpeg 源目录(上面引用的下载中的 jpeg-8d)并键入以下内容:
nmake -f makefile.win setup-v10
This will generate two VS2010 solutions, and a bunch of project files. The solutions are:
这将生成两个 VS2010 解决方案和一堆项目文件。解决方法是:
jpeg.sln
, which buildsjpeg.lib
apps.sln
, which builds the sample applications.
jpeg.sln
, 建立jpeg.lib
apps.sln
,构建示例应用程序。
Good luck!
祝你好运!
回答by Vinz
If you don't happen to have Visual Studio 2010 installed, here is what works on Visual Studio 2017:
如果您没有安装 Visual Studio 2010,以下是适用于 Visual Studio 2017 的内容:
Basic / Common steps:
基本/常见步骤:
- Download the latest version of libjpeg from: http://www.ijg.org/(zip version) and extract it to a folder
- Open the "Developer Command Prompt for VS2017"
- Change directory (
cd
) to where you extracted the library source
- 从以下位置下载最新版本的 libjpeg:http://www.ijg.org/ (zip 版本)并将其解压缩到一个文件夹中
- 打开“VS2017的开发人员命令提示符”
- 将目录 (
cd
)更改为提取库源的位置
VS 2017 Approach:
VS 2017 方法:
Include the Windows SDK v7.1A directory(required for Win32.Mak by nmake later on) by running:
set INCLUDE=%INCLUDE%;c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include
Run
nmake /f makefile.win setup-v15
(note the v15 for VS2017 here)
通过运行包含 Windows SDK v7.1A 目录(稍后 nmake 需要 Win32.Mak):
set INCLUDE=%INCLUDE%;c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include
运行
nmake /f makefile.win setup-v15
(注意这里是 VS2017 的 v15)
From here on follow what @AthanasiusOfAlex explained to upgrade the Visual Studio 2010 solution to the Visual Studio version you are running. If you want the Debug configuration, follow what @SteveEng explained.
从这里开始,按照@AthanasiusOfAlex 的解释将 Visual Studio 2010 解决方案升级到您正在运行的 Visual Studio 版本。如果您需要调试配置,请按照@SteveEng 的说明进行操作。
Errors you might stumble across:
您可能会遇到的错误:
- If
nmake
fails and tells you it doesn't know how to make jconfig.h, manually rename the filejconfig.vc
tojconfig.h
- If
nmake
fails and tells you Win32.Mak cannot be found, manually copy it from the SDK dir mentioned in step #4 to the libjpeg source directory. If you don't happen to have that SDK version installed, download the file from a trustworthy resource. - If
nmake
fails and tells you it doesn't know how to makesetup-v15
, trial and error your way through starting withsetup-v10
,setup-v11
, etc... These are VS versions and one of them should work as long as you have any VS version later than VS 2008 installed.
- 如果
nmake
失败并告诉您它不知道如何制作 jconfig.h,请手动将文件重命名jconfig.vc
为jconfig.h
- 如果
nmake
失败并告诉您找不到 Win32.Mak,请手动将其从步骤 #4 中提到的 SDK 目录复制到 libjpeg 源目录。如果您没有安装该 SDK 版本,请从可信赖的资源下载该文件。 - 如果
nmake
失败并告诉您它不知道如何setup-v15
通过从setup-v10
,开始的方式进行尝试和错误setup-v11
...安装。
Hope this helps people going through similar pain with this.
希望这可以帮助人们经历类似的痛苦。
回答by SteveEng
If you want debug mode as well in MSVC. Follow AthanasiusOfAlex's method, build the release, then:
如果您还想在 MSVC 中使用调试模式。按照 AthanasiusOfAlex 的方法,构建发布,然后:
- Right-click on the project and select properties at the very bottom
- Click on configuration manager and on the active solution configuration drop-down select -new-
- Set the name to debug and on the drop-down select copy configuration settings from release and click OK
- Close the dialog, go to general settings and under Target Name add a d to the end so it looks like this: $(ProjectName)d
- On Whole Program Optimization drop-down select: No Whole Program Optimization
- Then click on the C/C++ under configuration properties on the left and on the Debug Information Format drop-down select C7 compatible (/Z7)
- Under optimization select disabled and select NO for both Enable Fiber-Safe Optimizations and Whole Program Optimizations
- Under preprocessor, preprocessor definitions, click on edit and use the following: WIN32 _DEBUG DEBUG _LIB _CRT_SECURE_NO_WARNINGS
- Under code generation, under runtime library select Multi-threaded Debug DLL (/MDd)
- 右键单击项目并选择最底部的属性
- 单击配置管理器,然后在活动解决方案配置下拉列表中选择 -new-
- 将名称设置为 debug 并在下拉列表中选择从 release 复制配置设置,然后单击 OK
- 关闭对话框,转到常规设置,然后在目标名称下将广告添加到最后,如下所示:$(ProjectName)d
- 在整个程序优化下拉列表中选择:无整个程序优化
- 然后点击左侧配置属性下的C/C++,在Debug Information Format下拉菜单中选择C7 compatible (/Z7)
- 在优化下选择禁用并为启用光纤安全优化和整个程序优化选择否
- 在预处理器,预处理器定义下,单击编辑并使用以下内容:WIN32 _DEBUG DEBUG _LIB _CRT_SECURE_NO_WARNINGS
- 在代码生成下,在运行时库下选择多线程调试 DLL (/MDd)
Build and you're done!
构建,你就完成了!