1

I'm trying to install libwebsockets C library with vcpkg according to the instruction. And don't understand something. OS - Ubuntu 20.04

git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg install [library-name]

Library is installed and what to do next? How to compile test files with the library?

The question is more about how to use vcpkg on linux. You can give an example of another library installed with vcpkg.

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
tehkonst
  • 185
  • 2
  • 8
  • this is quite dated, but likely applies in both its "just install the OS's -dev version" ([looks like 4.0 is the latest](https://launchpad.net/ubuntu/+source/libwebsockets)) and also general build instructions! [How can I install the libwebsocket library in Ubuntu?](https://stackoverflow.com/questions/29470447/how-can-i-install-the-libwebsocket-library-in-ubuntu) – ti7 Oct 14 '21 at 15:09
  • I've never used this libwebsockets, but will offer a few pointers. At the bottom of the main github page for the project, it suggests joining the mailing list. That's always a good idea when using any free software. The project includes an examples directory that can be built with cmake, and API documentation generated with Doxygen. I would suggest you build the examples and study them and, if you're still baffled, ask on the mailing list. – James K. Lowden Oct 14 '21 at 15:10
  • I understand how to install the library with Cmake without vcpkg. I just try to figure out how vcpkg is useful for linux. – tehkonst Oct 15 '21 at 07:08
  • 1
    vcpkg is useful if you want a single tool chain manager for Windows, Linux, and MacOS, assuming that the libraries you care about are supported by it. You can use the installed libraries either with cmake, or, if you can figure out where it installs the libraries, by using the `-I` and `-L` options to tell the compiler where the respective include and library directories are. – user10489 Oct 16 '21 at 12:21

3 Answers3

2

Here is another example:

I want to install gtkmm4 in ubuntu 20.04 LTS, since gtkmm4 is not available for apt download I'm installing it with vcpkg.

for simplification, I'm setting VCPKG_DIR to the vcpkg directory I cloned.

export VCPKG_DIR=/path/to/vckpg

Then for a C++ program, you can write CMake file like below

PROJECT(gtkmmtest)
cmake_minimum_required(VERSION 3.10)

set(VCPKG_DIR $ENV{VCPKG_DIR})
include(${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake) # --> important

# Use the package PkgConfig to detect GTK+ headers/library files
FIND_PACKAGE(PkgConfig REQUIRED)
FIND_PACKAGE(Threads REQUIRED)

pkg_check_modules(GTK4 REQUIRED gtk4)
PKG_CHECK_MODULES(GTKMM gtkmm-4.0)
include_directories(${GTK4_INCLUDE_DIRS})
include_directories(${GTKMM_INCLUDE_DIRS})

link_directories(${VCPKG_DIR}/packages/gtk_x64-linux/lib)
link_directories(${GTK4_LIBRARY_DIRS})

add_definitions(${GTK4_CFLAGS_OTHER})

target_link_libraries(${GTKMMTEST} PRIVATE  ${GTK4_LIBRARIES} ${GTKMM_LIBRARIES} pthread)

Complete CMake file can be found here

You can still use the the standard include_directories and link_directories if there is no PkgConfig avilable.

eg:

include_directories(${VCPKG_DIR}/packages/gtkmm_x64-linux/include/gtkmm-4.0/)
Renju Ashokan
  • 428
  • 6
  • 18
1

Library is installed and what to do next? How to compile test files with the library?
The question is more about how to use vcpkg on linux.

The answer to this question really depends on your buildsystem and the port/library you want to use and not the platform itself.

In the case of libwebsockets libwebsockets-config.cmake get installed so you could use CMake and do a find_package(libwebsockets CONFIG REQUIRED) to get the imported targets the port exports within LibwebsocketsTargets.cmake. Of course this requires setting CMAKE_TOOLCHAIN_FILE to the vcpkg toolchain (<vcpkg_root>/scripts/buildsystems/vcpkg.cmake) or including it before the first project() in your CMakeLists.txt (more details are mentioned in the vcpkg docs which you hopefully read....)

Other libraries/ports might export *.pc files. For these FindPkgConfig.cmake can be used directly (see CMake docs) or you can setup PKG_CONFIG_PATH and prepend <vcpkg_root>/installed/<triplet (here probably: x64-linux)>/(debug/)lib/pkgconfig for other buildsystems like autotools or manual makefiles etc.

In the end how to use vcpkg or more precisly the libraries from it depends on what buildsystem you intend to use.

Alexander Neumann
  • 1,479
  • 8
  • 17
1

vcpkg is a C/C++ package manager, it is very necessary in windows.

However, in ubuntu, itself provides a very complete package management mechanism.

Therefore, even if you are building a cross platform software system, do not use vcpkg in ubuntu :)

You can try this:

$> sudo apt install libwebsockets-dev

In this way, the libwebsockets header files and library files you need have been installed and can be used directly.

gary133
  • 301
  • 1
  • 6