如何在 Cygwin 和 MinGW 中判断 C++ 库路径

How to tell C++ library path in Cygwin and MinGW(如何在 Cygwin 和 MinGW 中判断 C++ 库路径)

本文介绍了如何在 Cygwin 和 MinGW 中判断 C++ 库路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows XP 上使用 Cygwin 安装开发 C++ 程序.

I develop C++ programs using a Cygwin installation on top of Windows XP.

我也安装了 MinGW,因为我想使用它的 g++ 版本,而不是 Cygwin 自带的那个.

I also have MinGW installed, because I want to use it's version of g++, not the one that comes with Cygwin.

这部分似乎设置正确.当我开始 Cygwin 会话时,我看到:

That part seems to be set up correctly. When I start a Cygwin session I see this:

$哪个g++
/cygdrive/c/MinGW/bin/g++

$ which g++
/cygdrive/c/MinGW/bin/g++

这是正确的,g++ 指向我的 MinGW 安装.

This is correct, g++ is pointing to my MinGW install.

我不明白的是,当我编写包含库代码的代码时(例如,来自 `Winsock/BerkleySockets API 的头文件),我如何知道编译器在哪里找到该头文件?

What I don't understand is when I write code that includes library code (for example, header files from the `Winsock/BerkleySockets API), how can I tell where the compiler is finding that header file?

例如,如果我的代码中有 #include "winsock.h",那么编译器在哪里找到那个头文件?

For example, if I have #include "winsock.h" in my code, where does the compiler find that header file?

如果我在我的计算机上对 winsock.h 进行一般搜索,我会得到:

If I do a general search for winsock.h on my computer, I get this:

C:MinGWinclude
C:cygwinusrincludew32api

C:MinGWinclude
C:cygwinusrincludew32api

两者都有一个 winsock.h 的副本(尽管它们的文件大小并不完全相同,因此它们不可能完全相同).

Both have a copy of winsock.h (though the file sizes of these aren't exactly the same, so they can't be identical).

感谢您的帮助.

我还应该指出,我的 Windows PATH 环境变量中有 C:MinGWin,以及在我的/etc/profile 文件中配置的相同路径 在 Cygwin 中.

I should also point out, I have the C:MinGWin in my Windows PATH Environment Variable, as well as that same path configured in my/etc/profile file within Cygwin.

推荐答案

我猜为 MingW 编译的 g++ 具有与标准 g++ 相同的命令行参数.查看 g++ 手册页.

I'm guessing the g++ compiled for MingW has the same command line arguments as the standard g++. Check out the g++ manual page.

要将包含路径添加到您的编译中,请使用 -I 标志.

To add include paths to your compilation, use the -I flag.

g++ -I/include/path/here -I/another/include/path -o prog src.cpp

要将库路径添加到您的链接,请使用 -L 标志.

To add library paths to your linking, use the -L flag.

g++ -L/lib/path/here -L/another/lib/path -o prog src.cpp

MingW 站点解释了包含文件搜索如何在 MingW 上工作,以及如何修改它.

The MingW site explains how the include file search works on MingW, and how to modify it.

该网站还说,如果您想在编译期间查看包含文件搜索,请将 verbose 标志 (-v) 传递给编译器.

The site also says that if you want to view the include file search while it happens during the compilation, pass the verbose flag (-v) to the compiler.

g++ -v -o prog src.cpp

这篇关于如何在 Cygwin 和 MinGW 中判断 C++ 库路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 Cygwin 和 MinGW 中判断 C++ 库路径

基础教程推荐