3

I am a python dev who is learning C++. I have a question:

I would like to install an external library libxlsxwriter. In VS Code terminal I do:

a) I create and empty folder C:\dev. I install there vcpkg using:

 `cd C:\dev`

 `git clone https://github.com/Microsoft/vcpkg.git`

 `.\vcpkg\bootstrap-vcpkg.bat`

b) Now when I try to download the library, I got this message:

`.\vcpkg install libxlsxwriter:x64-windows`

Computing installation plan...

The following packages will be built and installed:

libxlsxwriter[core]:x64-windows -> 0.9.4

zlib[core]:x64-windows -> 1.2.11#10

Additional packages (*) will be modified to complete this operation.

**No suitable Visual Studio instances were found**

Can you please explain to me, where is the problem? Is the problem in the settings of my VS Code? Thanks a lot.

vojtam
  • 1,157
  • 9
  • 34
  • 3
    It's a bit weird to use vcpkg with VSC. If your compiler is MSVC, then you might as well use VS instead of VSC. If your compiler is MinGW, then there are package managers that specialize on it (MSYS2). – HolyBlackCat Jul 25 '21 at 09:29
  • 1
    @HolyBlackCat thanks for your reply, as I wrote, I am new to C++, so every advice is valuable for me :). I use g++ compiler. Do you recommend any other way, not vcpkg, for installing external libraries in c++? – vojtam Jul 25 '21 at 10:00
  • 3
    I'd recommend MSYS2 (and reinstalling GCC from its package manager). – HolyBlackCat Jul 25 '21 at 12:53
  • @HolyBlackCat thanks a lot for your help. Just to be sure: when I successfully install MSYS2 then I can install a c++ library `libxlsxwriter` simply using a command `pacman -S libxlsxwriter` ? – vojtam Jul 25 '21 at 14:15
  • 2
    The package name is different. You want `pacman -S mingw-w64-x86_64-libxlsxwriter`. Make sure all compilers and libraries you use have this prefix (`mingw-w64-x86_64-gcc` for GCC and **not** just `gcc`, and so on). Make sure you run MSYS2 using `mingw64.exe`, otherwise the compiler won't be in the `PATH` (if done correctly, terminal prompt should say `MINGW64` in magenta letters). [See this](https://stackoverflow.com/a/66751525/2752075) for more info about different package prefixes (or lack of them). – HolyBlackCat Jul 25 '21 at 14:20
  • 2
    Also make sure you update MSYS2 (`pacman -Syuu`) after installing, and then regularly. If it closes itself during an update, restart it and repeat the same command. – HolyBlackCat Jul 25 '21 at 14:23

1 Answers1

1

This may be because you haven't use the command to integrate the installation in your system, which is after using the bat, inside the folder of vcpkg run (btw I'm using PowerShell)

.\vcpkg.exe integrate install

According to docs: Make installed packages available user-wide. Requires admin privileges on first use.

After this according to my readings is configuring the triplet try using:

.\vcpkg.exe help triplets

your system seems to be "x64-windows" which is mine as well.

Then you'll go to and read some of it: https://vcpkg.io/en/docs/users/triplets.html

the section of windows is important, open Environment variables and create varaibles just like the so used Path or TEMP, press New and write:

VCPKG_TARGET_ARCHITECTURE and x64

VCPKG_TARGET_ARCHITECTURE x64

VCPKG_CMAKE_SYSTEM_NAME WindowsStore

And now add to the Path variable the folder where is vcpkg.exe, heres mine: C:\src\vcpkg\

close and start the shell again, now you have the ability to cast vcpkg anywhere, just write in your shell

vcpkg

Next you need to install libraries (search takes a while),

vcpkg search

to update this list it's a github in your vcpkg folder, run:

git pull

Let's say I choose sqlite3

vcpkg search sqlite
vcpkg install sqlite3
vcpkg list

very likely that detected the triplet ("Detecting compiler hash for triplet x64-windows...") There's a detail and it's supossed that vcpkg runs on a clean environment so depending on factors the previous variables may not have been set in your system so I recommend reading a little bit about this.

From here on there's just too much information and ways of going on, I recommend CMake, see (2) in references section, used in so many places, learning about this and how libs work on C++ will make you learn a lot in very little time.

Resuming:

.\vcpkg integrate install

and add the vcpkg folder to path. I recommend (1) in list of references. Give it a read to the next things, there's an atomic header inside of C++ (yeah, is THAT level)

References

(1) Michael Forest - C++ Libraries For Beginners https://youtu.be/a5kUr-u2UNo

(2) CMake Integration - https://vcpkg.io/en/docs/users/buildsystems/cmake-integration.html

(3) Env. Variables for VCPKG - https://vcpkg.io/en/docs/users/config-environment.html

(4) C libraries you have acces already - https://cplusplus.com/reference/

(5) History of C++ - https://cplusplus.com/info/history/