如何判断Cygwin和MinGW中的C ++库路径 [英] How to tell C++ library path in Cygwin and MinGW

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

问题描述

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



我也安装了MinGW,因为我想使用它的g ++版本,一个与Cygwin一起来。



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


$其中g ++

/ cygdrive / c / MinGW / bin / g ++


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



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



例如,如果我在我的代码中有 #includewinsock.h,编译器在哪里找到头文件?



如果我在电脑上搜索winsock.h,我会得到:


C:\MinGW\includegoogle
C:\cygwin\usr\include\w32api


两者都有一个winsock.h的副本(虽然这些文件的大小不完全相同,因此它们不能相同)。



感谢您的帮助。



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


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



要添加包含您的编译路径,请使用 -I 标志。

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

要为链接添加库路径,请使用 -L 标志。

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


$ b b

MingW网站说明了包含文件搜索在MingW上的工作原理,以及如何对其进行修改。



该网站还表示,如果要在编译期间查看包含文件搜索,请传递 verbose 标志( -v )。

  g ++ -v -o prog src.cpp 


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

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

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

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

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

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?

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

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

C:\MinGW\include
C:\cygwin\usr\include\w32api

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

Thanks for the help.

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

解决方案

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

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

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

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

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

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

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 ++库路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆