Search code examples
g++cygwinpoco

How did Cygwin g++ resolve it?


I am puzzled how a mere g++ -o testpoco testpoco.cpp -lPocoFoundation was able to compile successfully in my Cygwin environment. The complete C++ code is below:

#include <Poco/File.h>

int main (int argc, char *argv[])
{
    Poco::File f("/tmp/test.log");
    if (f.exists()) {
        return 1;
    }
    return 0;
}

I installed the cygwin Poco development headers and libraries and I verified they are in:

  • /usr/include/Poco/ (the header files)
  • /usr/lib/ (the libraries)

But without specifying those include and library path in g++ how did it was able to compile and produce the exe? I checked the output of g++ -v and did not see any routes to Poco.


Solution

  • The compiler has default search paths for include files and for libraries. (Actually the latter applies to the linker, not the compiler, but the g++ command invokes both.)

    /usr/include and /usr/lib are in those default search paths.

    You specified #include <Poco/File.h>, so the compiler found /usr/include/Poco/File.h.

    You specified -lPocoFoundation, so the linker found /usr/lib/libPocoFoundation.dll.a, the file that contains the code implementing the PocoFoundation library under Cygwin.