# uuid library linking

**URL:** https://discourse.cmake.org/t/uuid-library-linking/14924
**Category:** Usage
**Created:** [August 6, 2025, 2:05pm UTC](https://discourse.cmake.org/t/uuid-library-linking/14924 "2025-08-06T14:05:56Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![SS\_SS](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ss_ss/32/5731_2.png) [@SS\_SS](https://discourse.cmake.org/u/SS_SS)
#### Post date: [August 6, 2025, 2:05pm UTC](https://discourse.cmake.org/t/uuid-library-linking/14924/1 "2025-08-06T14:05:56Z")

</div>

Hello,  
I’m learning how to use cmake for future projects. So far, i built a sample executable, library and linked them together. Wrote a ctest test case, ran code coverage, memcheck and generated a html report, all good up to this point. Next, I wanted to link to an existing library on my ubuntu machine like UUID, I found the uuid.h file and the libuuid.so.

I tried everything recommended by google AI search and nothing seem to work, when compiling, my include \<uuid/uuid\> is never found. I checked the generated Makefile and it has no mention of uuid. Tried to locate a simple compile/linking example with cmake.

Thanks!

---

<div class="post-metadata">

### Author: ![LegalizeAdulthood](https://discourse.cmake.org/user_avatar/discourse.cmake.org/legalizeadulthood/32/5282_2.png) [@LegalizeAdulthood](https://discourse.cmake.org/u/LegalizeAdulthood)
#### Post date: [August 6, 2025, 2:56pm UTC](https://discourse.cmake.org/t/uuid-library-linking/14924/2 "2025-08-06T14:56:40Z")

</div>

Once you start consuming third-party libraries is where things get a little “interesting”, shall we say.

IMO, the easiest thing to do is to start using a package manager like [vcpkg](https://vcpkg.io/) to get access to third party libraries like uuid.

Also, I note that the library you’re using is only available on linux through vcpkg, whereas there are other uuid libraries that are supported by linux, macOS and Windows, such as [stduuid](https://github.com/mariusbancila/stduuid).

I gave a [presentation on vcpkg](https://www.youtube.com/watch?v=gpBDHh47w-I) a few years ago and there is plenty of documentation on how to [get started with vcpkg](https://vcpkg.io/en/getting-started).

If you’re not willing to use vcpkg, then your next step would be to write a CMake find module that locates uuid and sets up an imported target that you can link against with `target_link_libraries`. This isn’t much more complicated than the CMake you’ve already been writing, but there’s lots of little things that can go wrong and you’re more likely to gain more by learning a package manager like vcpkg than by learning how to write find modules.

---

<div class="post-metadata">

### Author: ![vito.gamberini](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vito.gamberini/32/4376_2.png) [@vito.gamberini](https://discourse.cmake.org/u/vito.gamberini)
#### Post date: [August 6, 2025, 2:59pm UTC](https://discourse.cmake.org/t/uuid-library-linking/14924/3 "2025-08-06T14:59:15Z")

</div>

There’s no need to do any of that and there’s nothing complex about this use case.

If they want to build with libuuid, installed from their standard upstream distro repositories, it will be as trivial as `target_link_libraries(<tgt> PRIVATE uuid)`

If they want to get very fancy with it, uuid ships a `pkg-config` file, so one can use the various pkg-config support mechanism in CMake to construct an imported target from that.

---

<div class="post-metadata">

### Author: ![vito.gamberini](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vito.gamberini/32/4376_2.png) [@vito.gamberini](https://discourse.cmake.org/u/vito.gamberini)
#### Post date: [August 6, 2025, 3:32pm UTC](https://discourse.cmake.org/t/uuid-library-linking/14924/4 "2025-08-06T15:32:15Z")

</div>

Here’s an example of building, linking, and testing against `libuuid` on Ubuntu. Check the Github CI workflow for details on how CMake is being invoked:

> **[GitHub - nickelpro/uuid-example](https://github.com/nickelpro/uuid-example)**
>
> Contribute to nickelpro/uuid-example development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![SS\_SS](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ss_ss/32/5731_2.png) [@SS\_SS](https://discourse.cmake.org/u/SS_SS)
#### Post date: [August 6, 2025, 4:37pm UTC](https://discourse.cmake.org/t/uuid-library-linking/14924/5 "2025-08-06T16:37:52Z")

</div>

@vito.gamberini - Thank you for taking the time to put this example together.

I cloned and tried to build on my system but i’m on an older cmake version 3.22. I updated accordingly, and got a successful build. 3.22 doesn’t support FILE\_SET.

➜ build git:(main) ✗ ldd example-test  
linux-vdso.so.1 (0x00007fff27f77000)  
libuuid.so.1 =\> /lib/x86\_64-linux-gnu/libuuid.so.1 (0x000079a12d158000)  
libc.so.6 =\> /lib/x86\_64-linux-gnu/libc.so.6 (0x000079a12ce00000)  
/lib64/ld-linux-x86-64.so.2 (0x000079a12d182000)

cmake\_minimum\_required(VERSION 3.22.1)

project(cmake-uuid-example)

add\_library(example)

target\_sources(example  
PRIVATE  
src/lib.cpp  
)

target\_link\_libraries(example  
PUBLIC  
uuid  
)

target\_include\_directories(example PUBLIC  
src  
)

add\_executable(example-test)  
target\_sources(example-test  
PRIVATE  
test/test.cpp  
)  
target\_link\_libraries(example-test  
PRIVATE  
example  
)

enable\_testing()  
add\_test(NAME example-test COMMAND example-test)

---

<div class="post-metadata">

### Author: ![LegalizeAdulthood](https://discourse.cmake.org/user_avatar/discourse.cmake.org/legalizeadulthood/32/5282_2.png) [@LegalizeAdulthood](https://discourse.cmake.org/u/LegalizeAdulthood)
#### Post date: [August 6, 2025, 6:54pm UTC](https://discourse.cmake.org/t/uuid-library-linking/14924/6 "2025-08-06T18:54:52Z")

</div>

> [@vito.gamberini](#):
>
> There’s no need to do any of that and there’s nothing complex about this use case.

Yes and no.

Just slapping it onto the link libraries may or may not work because it makes assumptions about the host environment.

---

<div class="post-metadata">

### Author: ![SS\_SS](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ss_ss/32/5731_2.png) [@SS\_SS](https://discourse.cmake.org/u/SS_SS)
#### Post date: [August 6, 2025, 7:03pm UTC](https://discourse.cmake.org/t/uuid-library-linking/14924/7 "2025-08-06T19:03:30Z")

</div>

yup.

I tried repeating the step in my example and it doesn’t work (given I’m on cmake 3.22).

---

<div class="post-metadata">

### Author: ![SS\_SS](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ss_ss/32/5731_2.png) [@SS\_SS](https://discourse.cmake.org/u/SS_SS)
#### Post date: [August 6, 2025, 7:07pm UTC](https://discourse.cmake.org/t/uuid-library-linking/14924/8 "2025-08-06T19:07:13Z")

</div>

i see vcpkg does make it easy. reminds me of NuGet, let me play with this a bit.

A quick test based on the directions here

> **[Install and use packages with CMake](https://learn.microsoft.com/en-us/vcpkg/get_started/get-started?source=recommendations&pivots=shell-bash)**
>
> Tutorial guides the user through the process of installing and using packages with CMake.

example built/ran just fine…will spend time to see how this can be good.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 6, 2025, 8:18pm UTC](https://discourse.cmake.org/t/uuid-library-linking/14924/9 "2025-08-06T20:18:59Z")

</div>

**One note** : you assume `libuuid` is installed on your system and your compiler use` -std=C++17` as default?

```cmake
cmake_minimum_required(VERSION 3.28...4.1)

project(cmake-uuid-example LANGUAGES CXX)

add_library(example)
target_sources(example
  PRIVATE
    src/lib.cpp

  INTERFACE
    FILE_SET HEADERS
    BASE_DIRS
      src
    FILES
      src/lib.hpp
)
target_compile_features(example PUBLIC cxx_std_17)
find_library(UUID_LIB uuid REQUIRED NAMES libuuid)
target_link_libraries(example
  PUBLIC
    ${UUID_LIB}
)

add_executable(example-test)
target_sources(example-test
  PRIVATE
    test/test.cpp
)
target_link_libraries(example-test
  PRIVATE
    example
)

enable_testing()
add_test(NAME example-test COMMAND example-test)

```

---

<div class="post-metadata">

### Author: ![vito.gamberini](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vito.gamberini/32/4376_2.png) [@vito.gamberini](https://discourse.cmake.org/u/vito.gamberini)
#### Post date: [August 6, 2025, 8:20pm UTC](https://discourse.cmake.org/t/uuid-library-linking/14924/10 "2025-08-06T20:20:25Z")

</div>

They didn’t specify a C++ version, relying on the compiler default is fine. And yes they explicitly stated they wanted to use their system libuuid from Ubuntu.

---

<div class="post-metadata">

### Author: ![SS\_SS](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ss_ss/32/5731_2.png) [@SS\_SS](https://discourse.cmake.org/u/SS_SS)
#### Post date: [August 7, 2025, 11:20am UTC](https://discourse.cmake.org/t/uuid-library-linking/14924/11 "2025-08-07T11:20:20Z")

</div>

I’m on c++ version (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

---

<div class="post-metadata">

### Author: ![SS\_SS](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ss_ss/32/5731_2.png) [@SS\_SS](https://discourse.cmake.org/u/SS_SS)
#### Post date: [August 7, 2025, 1:08pm UTC](https://discourse.cmake.org/t/uuid-library-linking/14924/12 "2025-08-07T13:08:25Z")

</div>

target\_link\_libraries and target\_include\_directories on latest cmake version support full paths, but 3.22 cmake does not mention such usage.

cmake latest says:

If an imported library has the [`IMPORTED_NO_SONAME`](https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_NO_SONAME.html#prop_tgt:IMPORTED_NO_SONAME) target property set, CMake may ask the linker to search for the library instead of using the full path (e.g. `/usr/lib/libfoo.so` becomes `-lfoo`).

The full path to the target’s artifact will be quoted/escaped for the shell automatically.
