'How to link external libraries to my C++ program in Visual studio code (version 1.54)?

I am programming a game in C++ with SDL2 API's, I was using code blocks but now i am shifting to visual studio code February 2021 (version 1.54) update, but I am having issues with linking my SDL2 libraries in visual studio code, In code block we had a build option to do that, visual studio code 2019 had a same features but in this new update I am not sure how to do that. I have gone through the documentation of C++ with visual studio code and have done what ever I could have but nothing solved the issue. ( I have gone through this - https://code.visualstudio.com/docs/cpp/config-mingw a number of time so please do not recommend me this as a solution), and please do not suggest that I should edit "includepath" in c_cpp_properties.json, as it is just for IntelliSense to auto complete stuff form that included files. I have done my research and after that only I am reaching out here.



Solution 1:[1]

You can use msys2 package manager to include cpp libraries in your code in vs code(windows) .Iam assuming you are using GCC compiler.

  1. install msys2 and then install SDL2 library using command on msys2 webpage.
  2. add bin folder of msys64(if your using 64 bit version) to system variables which has SDL dlls.
  3. include folder of msys64 contains header files of SDL2.
  4. lib folder contains libsdl.a file.
  5. using them , configure your build tasks in vscode to include them in your code like adding "-lsdl2" to args in task.json file

Youtube video : include external cpp libraries in vs code using msys2

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeevan sammes