title: Cmake undefined references when using the external library Poco (installed via vcpkg) in Visual Studio Code
body: <p>I'm currently trying to develop a C++ cross-platform project in VSCode which should include the Poco library which I downloaded using vcpkg. I then followed this tutorial: <a href="https://www.codeproject.com/Articles/252566/Learning-Poco-GET-with-HTTP" rel="nofollow noreferrer">https://www.codeproject.com/Articles/252566/Learning-Poco-GET-with-HTTP</a> but I cannot resolve the undefined references errors that also the article shows.
  Here is my <strong>main (httpGet.cpp)</strong> (which I copied from the link above):</p>
  
  <pre><code>#include &lt;Poco/Net/HTTPClientSession.h&gt;
  #include &lt;Poco/Net/HTTPRequest.h&gt;
  #include &lt;Poco/Net/HTTPResponse.h&gt;
  #include &lt;Poco/StreamCopier.h&gt;
  #include &lt;Poco/Path.h&gt;
  #include &lt;Poco/URI.h&gt;
  #include &lt;Poco/Exception.h&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace Poco::Net;
  using namespace Poco;
  using namespace std;
  
  int main(int argc, char **argv)
  {
    if (argc != 2)
    {
      cout &lt;&lt; "Usage: " &lt;&lt; argv[0] &lt;&lt; " &lt;uri&gt;" &lt;&lt; endl;
      cout &lt;&lt; "       fetches the resource identified by &lt;uri&gt; and print it" &lt;&lt; endl;
      return -1;
    }
  
    try
    {
      // prepare session
      URI uri(argv[1]);
      HTTPClientSession session(uri.getHost(), uri.getPort());
  
      // prepare path
      string path(uri.getPathAndQuery());
      if (path.empty()) path = "/";
  
      // send request
      HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
      session.sendRequest(req);
  
      // get response
      HTTPResponse res;
      cout &lt;&lt; res.getStatus() &lt;&lt; " " &lt;&lt; res.getReason() &lt;&lt; endl;
  
      // print response
      istream &amp;is = session.receiveResponse(res);
      StreamCopier::copyStream(is, cout);
    }
    catch (Exception &amp;ex)
    {
      cerr &lt;&lt; ex.displayText() &lt;&lt; endl;
      return -1;
    }
  
    return 0;
  }
  </code></pre>
  
  <p>Here is my <strong>CMakeLists.txt</strong>:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.16)
  
  set(CMAKE_CXX_STANDARD 11)
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
  
  set(PocoNet_DIR "C:/vcpkg/installed/x64-windows/share/poco")
  set(PocoFoundation_DIR "C:/vcpkg/installed/x64-windows/share/poco")
  
  set(VCPKG_TARGET_TRIPLET "x64-windows"
        CACHE STRING "")
  set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
        CACHE STRING "")
  project(TryPOCO)
  
  find_package(Poco CONFIG REQUIRED Net)
  find_package(PocoNet REQUIRED)
  
  include_directories("C:/vcpkg/installed/x64-windows/include")
  link_directories("C:/vcpkg/installed/x64-windows/lib")
  
  add_executable(${PROJECT_NAME} httpGet.cpp)
  
  target_link_libraries(${PROJECT_NAME} PRIVATE PocoNet)
  </code></pre>
  
  <p>And here is the error I get:</p>
  
  <pre><code>[build] CMakeFiles\TryPOCO.dir/objects.a(httpGet.cpp.obj): In function `main':
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:27: undefined reference to `Poco::URI::URI(char const*)'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:28: undefined reference to `Poco::URI::getPort() const'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:28: undefined reference to `Poco::Net::HTTPClientSession::HTTPClientSession(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, unsigned short)'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:31: undefined reference to `Poco::URI::getPathAndQuery[abi:cxx11]() const'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:35: undefined reference to `Poco::Net::HTTPRequest::HTTPRequest(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:36: undefined reference to `Poco::Net::HTTPClientSession::sendRequest(Poco::Net::HTTPRequest&amp;)'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:39: undefined reference to `Poco::Net::HTTPResponse::HTTPResponse()'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:43: undefined reference to `Poco::Net::HTTPClientSession::receiveResponse(Poco::Net::HTTPResponse&amp;)'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:44: undefined reference to `Poco::StreamCopier::copyStream(std::istream&amp;, std::ostream&amp;, unsigned long long)'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:39: undefined reference to `Poco::Net::HTTPResponse::~HTTPResponse()'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:35: undefined reference to `Poco::Net::HTTPRequest::~HTTPRequest()'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:28: undefined reference to `Poco::Net::HTTPClientSession::~HTTPClientSession()'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:27: undefined reference to `Poco::URI::~URI()'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:39: undefined reference to `Poco::Net::HTTPResponse::~HTTPResponse()'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:35: undefined reference to `Poco::Net::HTTPRequest::~HTTPRequest()'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:28: undefined reference to `Poco::Net::HTTPClientSession::~HTTPClientSession()'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:27: undefined reference to `Poco::URI::~URI()'
  [build] C:/TesiMag/ProveVSCode/TryPOCO/httpGet.cpp:48: undefined reference to `Poco::Exception::displayText[abi:cxx11]() const'
  [build] CMakeFiles\TryPOCO.dir/objects.a(httpGet.cpp.obj): In function `Poco::Net::Impl::IPv4SocketAddressImpl::host() const':
  [build] C:/vcpkg/installed/x64-windows/include/Poco/Net/SocketAddressImpl.h:81: undefined reference to `Poco::Net::IPAddress::IPAddress(void const*, int)'
  [build] CMakeFiles\TryPOCO.dir/objects.a(httpGet.cpp.obj): In function `Poco::Net::Impl::IPv6SocketAddressImpl::host() const':
  [build] C:/vcpkg/installed/x64-windows/include/Poco/Net/SocketAddressImpl.h:143: undefined reference to `Poco::Net::IPAddress::IPAddress(void const*, int, unsigned int)'
  [build] CMakeFiles\TryPOCO.dir/objects.a(httpGet.cpp.obj):httpGet.cpp:(.rdata$_ZTVN4Poco3Net4Impl21IPv6SocketAddressImplE[_ZTVN4Poco3Net4Impl21IPv6SocketAddressImplE]+0x50): undefined reference to `Poco::Net::Impl::IPv6SocketAddressImpl::toString[abi:cxx11]() const'
  [build] CMakeFiles\TryPOCO.dir/objects.a(httpGet.cpp.obj): In function `Poco::Net::Impl::IPv6SocketAddressImpl::~IPv6SocketAddressImpl()':
  [build] C:/vcpkg/installed/x64-windows/include/Poco/Net/SocketAddressImpl.h:118: undefined reference to `Poco::Net::Impl::SocketAddressImpl::~SocketAddressImpl()'
  [build] CMakeFiles\TryPOCO.dir/objects.a(httpGet.cpp.obj):httpGet.cpp:(.rdata$_ZTVN4Poco3Net4Impl21IPv4SocketAddressImplE[_ZTVN4Poco3Net4Impl21IPv4SocketAddressImplE]+0x50): undefined reference to `Poco::Net::Impl::IPv4SocketAddressImpl::toString[abi:cxx11]() const'
  [build] CMakeFiles\TryPOCO.dir/objects.a(httpGet.cpp.obj): In function `Poco::Net::Impl::IPv4SocketAddressImpl::~IPv4SocketAddressImpl()':
  [build] C:/vcpkg/installed/x64-windows/include/Poco/Net/SocketAddressImpl.h:56: undefined reference to `Poco::Net::Impl::SocketAddressImpl::~SocketAddressImpl()'
  [build] CMakeFiles\TryPOCO.dir/objects.a(httpGet.cpp.obj):httpGet.cpp:(.rdata$.refptr._ZN4Poco3Net11HTTPRequest8HTTP_GETB5cxx11E[.refptr._ZN4Poco3Net11HTTPRequest8HTTP_GETB5cxx11E]+0x0): undefined reference to `Poco::Net::HTTPRequest::HTTP_GET[abi:cxx11]'
  [build] CMakeFiles\TryPOCO.dir/objects.a(httpGet.cpp.obj):httpGet.cpp:(.rdata$.refptr._ZN4Poco3Net11HTTPMessage8HTTP_1_1B5cxx11E[.refptr._ZN4Poco3Net11HTTPMessage8HTTP_1_1B5cxx11E]+0x0): undefined reference to `Poco::Net::HTTPMessage::HTTP_1_1[abi:cxx11]'
  [build] collect2.exe: error: ld returned 1 exit status
  [build] mingw32-make.exe[2]: *** [CMakeFiles\TryPOCO.dir\build.make:86: TryPOCO.exe] Error 1
  [build] mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:75: CMakeFiles/TryPOCO.dir/all] Error 2
  [build] mingw32-make.exe: *** [Makefile:83: all] Error 2
  [build] Compilazione terminata con codice di uscita 2
  </code></pre>
  
  <p>The compiler I am using is <strong>g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0</strong>.</p>
  
  <p>I suppose it's a linker error, but I am new to CMake so I don't really know if there are any other libraries that I should add to <em>target_link_libraries</em> or somewhere else in the <strong>CMakeLists.txt</strong>.
  Also I don't know if the <strong>CMakeLists.txt</strong> is written in a good manner since it's the first time ever I use CMake.</p>
  
  <p>Thank you in advance for your answers.</p>