Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:\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.

like image 581
dvanaria Avatar asked Oct 13 '12 00:10

dvanaria


People also ask

Can MinGW and Cygwin coexist?

Operation Modes. The MSYS2 and CYGWIN can be used with different operation modes: You can use them together with MinGW to build Windows-native software. You can use them together with any other compiler to build Windows-native software, even with Visual Studio.

Are Cygwin and MinGW the same?

MinGW is higher performance than Cygwin, but it's also 32-bit which may be a problem with your applications. There is a 64-bit environment similar to MinGW but it's a different project. MinGW-w64 is in all senses the successor to MinGW.


1 Answers

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
like image 146
Geoff Montee Avatar answered Oct 01 '22 02:10

Geoff Montee