Specify library path in Visual Studio Code?
Asked Answered
I

1

13

How do I specify the library path, i.e., where to look up static/shared libraries in Visual Studio Code (C++)?

I've already specified the include path (header files) as follows:

   "includePath": [
        "${workspaceRoot}",
        "/usr/include/x86_64-linux-gnu/c++/6",
        "/usr/include/c++/6",
        "/usr/local/include",
        "/usr/include/x86_64-linux-gnu",
        "/usr/include"
    ]

I've been searching for a JSON property called "libraryPath", but cannot find any.

Irishman answered 14/7, 2017 at 10:48 Comment(5)
Do you mean additiaonal library path? For example; to include a .lib file in $(ProjectDir)\3rdParty\WpdPack\Lib\x64 folder <AdditionalLibraryDirectories>$(ProjectDir)\3rdParty\WpdPack\Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>Hassi
Does you comment apply to Visual Studio Code? If so, where should I put this?Irishman
Actually , these settings are configured from Visual Studio->Project Properties in graphical interface , I have written the content of .vcxproj that is modified automaticallyHassi
I'm not asking about Visual Studio, but Visual Studio Code!Irishman
Did find a solution for that?Raleighraley
F
0

The property includePath, referenced in your question, resides in the file c_cpp_properties.json, primarily utilized by the Microsoft C/C++ extension to configure IntelliSense, which provides functionalities such as code completion, syntax highlighting, etc. It's important to note that in VSCode, this is decoupled from compiling and linking, which are typically handled in tasks.json. For instance, includePath does not affect the behavior of the compiler called in tasks.json. Instead, one must manually pass command-line arguments to the compiler within the args section of tasks.json. The same applies to libraries. There is no property like libraryPath in c_cpp_properties.json because IntelliSense typically does not require that kind of information to perform its tasks.

For a specific example, consider compiling a single-file C++ program dependent on a library named foo, residing in /usr/lib (one of the standard directories). In this scenario, appending -lfoo (-l<library>) to the args in the auto-generated tasks.json suffices:

{
  "tasks": [
    {
      "type": "cppbuild",
      "label": "C/C++: g++ build active file",
      "command": "/usr/sbin/g++",
      "args": [
        "-fdiagnostics-color=always",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}",
        "-lfoo" // <- Instruct GCC to search libfoo.a or libfoo.so
      ],
      // Other auto-generated fields omitted
    }
  ],
  "version": "2.0.0"
}

In cases where libraries are not located in standard search directories, the option -L<dir> can be used to specify additional search directories. Often, the above process is considered verbose and error-prone, especially for larger projects, and a build system such as CMake is a better choice.

Forde answered 28/5 at 2:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.