title: How to cross compile a C++ library from Windows to Linux? (C++17) Using VS 2019
body: <p>I have a C++ library and I need to make a <code>.a</code>.  I use a <code>.lib</code> for the windows build of my project and need a <code>.a</code> for the linux build.</p>
  <p>VS says it can do this with a CMake project but I haven't been able to create anything from the documentation (<a href="https://docs.microsoft.com/en-us/cpp/linux/cmake-linux-configure?view=msvc-160" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/cpp/linux/cmake-linux-configure?view=msvc-160</a>).</p>
  <p>When I create the <code>.lib</code> I use cmake to create a Visual Studio solution.  Then I use MSVC 2019 to create the .lib.</p>
  <p>EDIT: My current CMakeLists.txt for the windows library.</p>
  <pre><code>cmake_minimum_required (VERSION 3.9)
  
  add_definitions(-DNOT_USING_CMAKE=0)
  
  SET(CMAKE_INSTALL_PREFIX &quot;...&quot; CACHE PATH &quot;...&quot;)
  
  project(...)
  
  include_directories (...)
  
  #create base library
  add_library (${PROJECT_NAME} STATIC &quot;&quot;)
  
  set_target_properties (${PROJECT_NAME}
    PROPERTIES
    CXX_STANDARD 17
    CXX_STANDARD_REQUIRED ON
    CXX_EXTENSIONS OFF
  )
  
  add_subdirectory (...)
  ...
  add_subdirectory (...)
  
    install (TARGETS ${PROJECT_NAME}
           RUNTIME DESTINATION bin
           LIBRARY DESTINATION lib
           ARCHIVE DESTINATION lib/archive )
             
  </code></pre>