title: Visual Studio Code settings for C++ (a) static and (b) dynamic library linking
body: <p>Can I have some assistance configuring Visual Code (not Visual Studio) to build a C++ library?  Both static and most importantly a dynamic library?  Visual Code requires that you create a tasks.json file to tell VS Code how to build (compile) the program. This task will invoke the Microsoft C++ compiler to create an executable file based on the source code.</p>
  <p>My current tasks.json is as follows:</p>
  <pre><code>{
      &quot;version&quot;: &quot;2.0.0&quot;,
      &quot;tasks&quot;: [
        {
          &quot;type&quot;: &quot;shell&quot;,
          &quot;label&quot;: &quot;cl.exe build active file&quot;,
          &quot;command&quot;: &quot;cl.exe&quot;,
          &quot;args&quot;: [
            &quot;/Zi&quot;,
            &quot;/EHsc&quot;,
            &quot;/Fe:&quot;,
            &quot;${fileDirname}\\${fileBasenameNoExtension}.exe&quot;,
            &quot;${file}&quot;
          ],
          &quot;problemMatcher&quot;: [&quot;$msCompile&quot;],
          &quot;group&quot;: {
            &quot;kind&quot;: &quot;build&quot;,
            &quot;isDefault&quot;: true
          }
        }
      ]
    }
  </code></pre>
  <p>In some scenarios, I need to link my main.cpp file dynamically (DLL) or statically (LIB).  My library code is very simple - just two functions:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &quot;helloworld.h&quot;
  
  void connect()
  {
      printf(&quot;Connected to C extension...\n&quot;);
  }
  
  //return random value in range of 0-50
  int randNum()
  {
      int nRand = rand() % 50; 
      return nRand;
  }
   
  //add two number and return value
  int addNum(int a, int b)
  {
      int nAdd = a + b;
      return nAdd;
  }
  </code></pre>
  <p>I did my due diligence by doing a Google and Bing search but only landed on (a) Visual Studio and (b) .NET equivalents per the links below.  I'm in need of a solution for C++ static and dynamic libaries.</p>
  <p><a href="https://docs.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp</a>
  <a href="https://code.visualstudio.com/docs/cpp/config-msvc" rel="nofollow noreferrer">https://code.visualstudio.com/docs/cpp/config-msvc</a></p>
  <p>Thanks everyone.</p>
  <p><strong>FWIW</strong>....the contents of the helloworld.h at the top of my source code contains the following content:</p>
  <pre><code> extern &quot;C&quot; __declspec(dllexport) void connect();
   extern &quot;C&quot; __declspec(dllexport) int randNum();
   extern &quot;C&quot; __declspec(dllexport) int addNum(int a, int b);
  </code></pre>
  <p>...yet the build tools chain configured in VSCode (i.e. build tools for VS 2019, no IDE included) reports:</p>
  <pre><code>cl.exe /Zi /EHsc /nologo /Fe: C:\Users\foorbar\projects\CPP\helloworld.exe C:\Users\foobar\projects\CPP\helloworld.cpp
  helloworld.cpp
     Creating library C:\Users\foobar\projects\CPP\helloworld.lib and object C:\Users\foobar\projects\CPP\helloworld.exp
  LINK : fatal error LNK1561: entry point must be defined
  </code></pre>