Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
607 views
in Technique[技术] by (71.8m points)

compiler construction - How to tell C++ library path in Cygwin and MinGW

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:MinGWinclude
C:cygwinusrincludew32api

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:MinGWin in my Windows PATH Environment Variable, as well as that same path configured in my/etc/profile file within Cygwin.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...