在 Windows 上安装 C/C++ 库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2164001/
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
Installing C/C++ libraries on Windows
提问by Enrico Tuvera Jr
I'm studying (well, trying to) C right now, but I'm limited to working in Windows XP. I've managed to set up and learn how to use Emacs and can compile simple C programs with gcc (from Emacs no less!), but I'm getting to the point where I'd like to install something like SDL to play around with it.
我现在正在学习(嗯,正在尝试)C,但我仅限于在 Windows XP 中工作。我已经设法设置并学习了如何使用 Emacs,并且可以使用 gcc 编译简单的 C 程序(来自 Emacs 不少!)用它。
The thing is that the installation instructions for SDL indicate that, on a Win32 environment using MingW, I would need to use MSYS to run ./configure and make/make install to install SDL, like one would do on Linux. I noticed that when I unzipped the SDL-dev package (forgot the exact name, sorry) there were folders there that corresponded to a folder in the MinGW directory (SDL/include -> MinGW/include).
问题是 SDL 的安装说明表明,在使用 MingW 的 Win32 环境中,我需要使用 MSYS 来运行 ./configure 和 make/make install 来安装 SDL,就像在 Linux 上所做的那样。我注意到当我解压 SDL-dev 包时(忘记了确切的名称,抱歉)那里有一些文件夹对应于 MinGW 目录中的一个文件夹(SDL/include -> MinGW/include)。
Am I right in saying that all the ./configure and make commands do is move these files from one directory to another? Couldn't I just move those files by hand and spare myself the trouble of installing and configuring MSYS (which, to be honest, confuses me greatly)?
我说所有 ./configure 和 make 命令所做的都是将这些文件从一个目录移动到另一个目录是否正确?难道我不能手动移动这些文件,省去安装和配置 MSYS 的麻烦(老实说,这让我很困惑)?
回答by sepp2k
The build process usually works like this: the configure script finds the appropriate settings for the compilation (like which features to enable, the paths to the required libraries, which compiler to use etc.) and creates a Makefile accordingly. make then compiles the source code to binaries. make install copies the created binaries, the headers, and the other files that belong to the library to the appropriate places.
构建过程通常是这样工作的:配置脚本为编译找到合适的设置(比如启用哪些功能、所需库的路径、使用哪个编译器等)并相应地创建一个 Makefile。make 然后将源代码编译为二进制文件。make install 将创建的二进制文件、头文件和属于库的其他文件复制到适当的位置。
You can't just copy the files from the source archive, because the source archive does not contain the binary files (or any other files that are created during the make step), so all you'd copy would be the headers, which aren't enough to use the library.
您不能只从源存档中复制文件,因为源存档不包含二进制文件(或在 make 步骤中创建的任何其他文件),因此您要复制的只是标题,它们不是不足以使用图书馆。
回答by Gant
In most case, configure and make will discover the compiler/environment of your machine and build the suitable binary, respectively. Therefore, unfortunately, it will not be easy as moving/copying header files to new locations.
在大多数情况下,configure 和 make 将分别发现您机器的编译器/环境并构建合适的二进制文件。因此,不幸的是,将头文件移动/复制到新位置并不容易。
However, in some cases, the library can be the "header only" library. Which means you need only header files to use it.
但是,在某些情况下,库可以是“仅标头”库。这意味着您只需要头文件即可使用它。
I have no experience with MSYS and SDL. But the basics of configure and make is worth learning (especially if you are going to program any C/C++ in non-Windows environment.)
我没有 MSYS 和 SDL 的经验。但是 configure 和 make 的基础知识是值得学习的(特别是如果您要在非 Windows 环境中编写任何 C/C++ 程序。)