简体   繁体   English

如何在Cygwin和MinGW中告诉C ++库路径

[英]How to tell C++ library path in Cygwin and MinGW

I develop C++ programs using a Cygwin installation on top of Windows XP. 我在Windows XP上使用Cygwin安装开发C ++程序。

I also have MinGW installed, because I want to use it's version of g++, not the one that comes with Cygwin. 我也安装了MinGW,因为我想使用它的g ++版本,而不是Cygwin附带的版本。

That part seems to be set up correctly. 那部分似乎设置正确。 When I start a Cygwin session I see this: 当我开始Cygwin会话时,我看到了这个:

$ which g++ $ g ++
/cygdrive/c/MinGW/bin/g++ / cygdrive / C / MinGW的/ bin中/克++

This is correct, g++ is pointing to my MinGW install. 这是正确的,g ++指向我的MinGW安装。

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? 我不明白的是当我编写包含库代码的代码(例如,来自`Winsock / BerkleySockets API的头文件)时,如何判断编译器在哪里找到头文件?

For example, if I have #include "winsock.h" in my code, where does the compiler find that header file? 例如,如果我的代码中有#include "winsock.h" ,编译器在哪里找到该头文件?

If I do a general search for winsock.h on my computer, I get this: 如果我在计算机上搜索winsock.h,我会得到:

C:\\MinGW\\include C:\\ MinGW的\\包括
C:\\cygwin\\usr\\include\\w32api C:\\ Cygwin的的\\ usr \\包括\\ 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). 两者都有winsock.h的副本(虽然这些文件的大小不完全相同,所以它们不能完全相同)。

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. 我还应该指出,我的Windows PATH环境变量中有C:\\MinGW\\bin ,以及我在Cygwin中的/etc/profile file配置的相同路径。

I'm guessing the g++ compiled for MingW has the same command line arguments as the standard g++ . 我猜测为MingW编译的g ++与标准g ++具有相同的命令行参数。 Check out the g++ manual page . 查看g ++手册页

To add include paths to your compilation, use the -I flag. 要向编译添加包含路径,请使用-I标志。

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

To add library paths to your linking, use the -L flag. 要将库路径添加到链接,请使用-L标志。

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. MingW网站解释了包含文件搜索如何在MingW上运行,以及如何修改它。

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. 该站点还说,如果要在编译期间查看包含文件搜索,请将详细标志( -v )传递给编译器。

g++ -v -o prog src.cpp

I believe it's referring to the one in MinGW/include. 我相信它指的是MinGW / include中的那个。 Take a look at the Minigw documentation for include paths . 查看包含路径Minigw文档

If you are using an eclipse environment you can specify the include paths in the project settings along with specifying your choice of compiler ie mingw in your case. 如果您正在使用eclipse环境,则可以在项目设置中指定包含路径,同时指定您选择的编译器,即在您的情况下使用mingw。 Let us know if you still have a problem. 如果您还有问题,请告诉我们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM