# Code

**URL:** https://discourse.cmake.org/c/code/11.md?page=13

[Latest](https://discourse.cmake.org/latest.md) · [Categories](https://discourse.cmake.org/categories.md) · [Tags](https://discourse.cmake.org/tags.md)

**Page:** 14

---

## [Object Libraries: PREFIX, OUTPUT\_NAME, SUFFIX are not working](https://discourse.cmake.org/t/object-libraries-prefix-output-name-suffix-are-not-working/13235)

<div class="topic-metadata">

**Author:** [@miroslavbel](https://discourse.cmake.org/u/miroslavbel)\
**Replies:** 0\
**Last updated:** [December 19, 2024, 6:23pm UTC](https://discourse.cmake.org/t/object-libraries-prefix-output-name-suffix-are-not-working/13235 "2024-12-19T18:23:38Z")

</div>

I am trying to build custom crt0.o using CMake and produce a file named crt0.o. To achieve this, I have created an object library target and overwritten PREFIX, OUTPUT\_NAME, and SUFFIX target properties: add\_library(crt…

---

## [What controls the use of lib64 as CMAKE\_INSTALL\_LIBDIR?](https://discourse.cmake.org/t/what-controls-the-use-of-lib64-as-cmake-install-libdir/13212)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 1\
**Last updated:** [December 18, 2024, 6:21pm UTC](https://discourse.cmake.org/t/what-controls-the-use-of-lib64-as-cmake-install-libdir/13212 "2024-12-18T18:21:29Z")

</div>

My local build of zlib on Ubuntu installs to: /usr/local/lib/libz.a But on the same machine, the OpenSSl installs the libs to: /usr/local/lib64/?

---

## [How to handle duplicated target names](https://discourse.cmake.org/t/how-to-handle-duplicated-target-names/13225)

<div class="topic-metadata">

**Author:** [@Beanavil](https://discourse.cmake.org/u/Beanavil)\
**Replies:** 0\
**Last updated:** [December 18, 2024, 5:02pm UTC](https://discourse.cmake.org/t/how-to-handle-duplicated-target-names/13225 "2024-12-18T17:02:32Z")

</div>

I have a C++ program that depends on two packages, A and B. Now both have internally a dependency on C (so A-\>C and B-\>C). When I find\_package(A) some targets are defined as a result of it internally doing a find\_depende…

---

## [Help with shared libraries on Linux.](https://discourse.cmake.org/t/help-with-shared-libraries-on-linux/13203)

<div class="topic-metadata">

**Author:** [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Replies:** 16\
**Last updated:** [December 18, 2024, 6:11am UTC](https://discourse.cmake.org/t/help-with-shared-libraries-on-linux/13203 "2024-12-18T06:11:04Z")

</div>

My application builds and links with Qt6 picking up the Qt .so files because CMake builds some rpath “magic” into the executable when linking so that the libraries are picked up even though they are not listed in /etc/ld…

---

## [Error when linking executable](https://discourse.cmake.org/t/error-when-linking-executable/7108)

<div class="topic-metadata">

**Author:** [@Hulin\_Li](https://discourse.cmake.org/u/Hulin_Li)\
**Replies:** 1\
**Last updated:** [December 17, 2024, 11:48pm UTC](https://discourse.cmake.org/t/error-when-linking-executable/7108 "2024-12-17T23:48:43Z")

</div>

Hi, guys. I am new to cmake currently and I am rewriting the building file of my project from Makefile to cmake. When linking the executable, cmake says there has “undefined reference”, but I am sure I have added the co…

---

## ['cmake --install'/'make install'/'ninja install' doesn't install dependencies](https://discourse.cmake.org/t/cmake-install-make-install-ninja-install-doesnt-install-dependencies/13079)

<div class="topic-metadata">

**Author:** [@DKLind](https://discourse.cmake.org/u/DKLind)\
**Replies:** 22\
**Last updated:** [December 15, 2024, 11:34pm UTC](https://discourse.cmake.org/t/cmake-install-make-install-ninja-install-doesnt-install-dependencies/13079 "2024-12-15T23:34:03Z")

</div>

I’m integrating a Makefile’s functionality into CMake. The Makefile builds and installs a target. The install copies from a target’s install directory into the toolchain sysroot thus making it available for dependent tar…

---

## [Building static libraries with Fetchcontent](https://discourse.cmake.org/t/building-static-libraries-with-fetchcontent/13207)

<div class="topic-metadata">

**Author:** [@spacey-sooty](https://discourse.cmake.org/u/spacey-sooty)\
**Replies:** 1\
**Last updated:** [December 15, 2024, 11:42am UTC](https://discourse.cmake.org/t/building-static-libraries-with-fetchcontent/13207 "2024-12-15T11:42:02Z")

</div>

I’m trying to build a dependency statically to repackage it with another build system. Is there any way for me to set this to build statically? I can only find shared libraries in build/\_deps/library-build/

---

## [How to enable precompiled headers with existing header file.](https://discourse.cmake.org/t/how-to-enable-precompiled-headers-with-existing-header-file/13197)

<div class="topic-metadata">

**Author:** [@aseryukov](https://discourse.cmake.org/u/aseryukov)\
**Replies:** 0\
**Last updated:** [December 13, 2024, 8:13pm UTC](https://discourse.cmake.org/t/how-to-enable-precompiled-headers-with-existing-header-file/13197 "2024-12-13T20:13:39Z")

</div>

Hello, I have a large-ish C/C++ code base that uses static pre-compiled headers MSVC-style. The header file exists in the source tree and C files include it explicitly, as needed. Is there a way to accommodate this stru…

---

## [Check IMPORTED libraries SONAME ?](https://discourse.cmake.org/t/check-imported-libraries-soname/13177)

<div class="topic-metadata">

**Author:** [@mblanchard](https://discourse.cmake.org/u/mblanchard)\
**Replies:** 0\
**Last updated:** [December 11, 2024, 9:06am UTC](https://discourse.cmake.org/t/check-imported-libraries-soname/13177 "2024-12-11T09:06:00Z")

</div>

On UNIX platforms, the install(IMPORTED\_RUNTIME\_ARTIFACTS) relies on the IMPORTED library SONAME for proper file detection (see this comment). And because the IMPORTED libraries SONAME may not be set or may not match the…

---

## [Nested project](https://discourse.cmake.org/t/nested-project/13161)

<div class="topic-metadata">

**Author:** [@Oodini](https://discourse.cmake.org/u/Oodini)\
**Replies:** 0\
**Last updated:** [December 9, 2024, 3:57pm UTC](https://discourse.cmake.org/t/nested-project/13161 "2024-12-09T15:57:22Z")

</div>

Hello, I have a Git project, which is supposed to be a service in a SOA. But as it is possible the SOA part may be removed later, I’d like to make a library, with a wrapped SOA service. Here is the question : Could I…

---

## [WHOLE\_ARCHIVE portability](https://discourse.cmake.org/t/whole-archive-portability/13154)

<div class="topic-metadata">

**Author:** [@petk](https://discourse.cmake.org/u/petk)\
**Replies:** 0\
**Last updated:** [December 8, 2024, 5:35pm UTC](https://discourse.cmake.org/t/whole-archive-portability/13154 "2024-12-08T17:35:18Z")

</div>

Hello, Does anyone perhaps know how portable is the WHOLE\_ARCHIVE feature when linking static libraries and where it could cause issues? It uses the linker flags such as --whole-archive, /WHOLEARCHIVE etc. target\_link…

---

## [How to create tests for my Python bindings project](https://discourse.cmake.org/t/how-to-create-tests-for-my-python-bindings-project/13125)

<div class="topic-metadata">

**Author:** [@greenleaf](https://discourse.cmake.org/u/greenleaf)\
**Replies:** 2\
**Last updated:** [December 6, 2024, 6:30pm UTC](https://discourse.cmake.org/t/how-to-create-tests-for-my-python-bindings-project/13125 "2024-12-06T18:30:28Z")

</div>

I have the following CMake: cmake\_minimum\_required(VERSION 3.20) include(cmake/prelude.cmake) project( myLibPythonBindings VERSION 0.1.0 LANGUAGES CXX ) set(CMAKE\_CXX\_STANDARD 23) set(CMAKE\_CXX\_STANDARD\_R…

---

## [Having issue with while building Texgen Source code on Ubuntu 22.04LTS](https://discourse.cmake.org/t/having-issue-with-while-building-texgen-source-code-on-ubuntu-22-04lts/13130)

<div class="topic-metadata">

**Author:** [@10427788](https://discourse.cmake.org/u/10427788)\
**Replies:** 8\
**Last updated:** [December 6, 2024, 3:03pm UTC](https://discourse.cmake.org/t/having-issue-with-while-building-texgen-source-code-on-ubuntu-22-04lts/13130 "2024-12-06T15:03:41Z")

</div>

Hi, While building the TexGen source code using “make -j$(no process)” command in the terminal, I used get the following error :slight\_smile: Please let me know to overcome this problem for sucessfylly building and …

---

## [Exporting Targets from the Build Tree and immediately using find\_package()](https://discourse.cmake.org/t/exporting-targets-from-the-build-tree-and-immediately-using-find-package/10996)

<div class="topic-metadata">

**Author:** [@huiyan](https://discourse.cmake.org/u/huiyan)\
**Replies:** 1\
**Last updated:** [December 6, 2024, 1:26pm UTC](https://discourse.cmake.org/t/exporting-targets-from-the-build-tree-and-immediately-using-find-package/10996 "2024-12-06T13:26:18Z")

</div>

My problem is as follows (cmake version 3.29.4): in top CMakeLists.txt has added two subdirectories add\_subdirectory(fmt) add\_subdirectory(tests) And in file fmt/CMakeLists.txt I export a target by include(CM…

---

## [Support for generator expressions in call to set\_source\_properties() ?](https://discourse.cmake.org/t/support-for-generator-expressions-in-call-to-set-source-properties/13115)

<div class="topic-metadata">

**Author:** [@Timothy\_Madden](https://discourse.cmake.org/u/Timothy_Madden)\
**Replies:** 1\
**Last updated:** [December 5, 2024, 9:28pm UTC](https://discourse.cmake.org/t/support-for-generator-expressions-in-call-to-set-source-properties/13115 "2024-12-05T21:28:27Z")

</div>

Hello When using file(GENERATE), I normally need to use $\<CONFIG\> as part of the target file name (or path name), because file(GENERATE) will generate a file for each configuration. But when I set source properties on …

---

## [Trouble with specifying CONFIGURATIONS in installs](https://discourse.cmake.org/t/trouble-with-specifying-configurations-in-installs/13126)

<div class="topic-metadata">

**Author:** [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)\
**Replies:** 4\
**Last updated:** [December 5, 2024, 5:05pm UTC](https://discourse.cmake.org/t/trouble-with-specifying-configurations-in-installs/13126 "2024-12-05T17:05:19Z")

</div>

I’m trying to install a static library into my company’s directory structure, which has separate branches for debug and release versions of libraries. Clearly, I want the debug build to go to the debug branch and the re…

---

## [add\_library in a -config.cmake causing problem](https://discourse.cmake.org/t/add-library-in-a-config-cmake-causing-problem/13122)

<div class="topic-metadata">

**Author:** [@mdorier](https://discourse.cmake.org/u/mdorier)\
**Replies:** 6\
**Last updated:** [December 4, 2024, 9:27pm UTC](https://discourse.cmake.org/t/add-library-in-a-config-cmake-causing-problem/13122 "2024-12-04T21:27:07Z")

</div>

I have three cmake-based projects: Flock, Bedrock, and Mofka. Mofka depends on Flock and Bedrock. Bedrock depends on Flock. Flock has the following in flock-config.cmake.in (which is configured and installed as flock-con…

---

## [Managing runtime dependencies for large projects with checks](https://discourse.cmake.org/t/managing-runtime-dependencies-for-large-projects-with-checks/13121)

<div class="topic-metadata">

**Author:** [@SamCoutteauHybrid](https://discourse.cmake.org/u/SamCoutteauHybrid)\
**Replies:** 0\
**Last updated:** [December 4, 2024, 2:35pm UTC](https://discourse.cmake.org/t/managing-runtime-dependencies-for-large-projects-with-checks/13121 "2024-12-04T14:35:19Z")

</div>

Context I’ve been struggling to design a robust system within cmake for handling runtime dependencies. With runtime dependencies, I mean stuff like configuration json files, pre build dlls, and other resources which a…

---

## [The cmake preset error messages are not really helpfully?](https://discourse.cmake.org/t/the-cmake-preset-error-messages-are-not-really-helpfully/13119)

<div class="topic-metadata">

**Author:** [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Replies:** 0\
**Last updated:** [December 4, 2024, 1:39pm UTC](https://discourse.cmake.org/t/the-cmake-preset-error-messages-are-not-really-helpfully/13119 "2024-12-04T13:39:12Z")

</div>

I have a CMakeUserPreset.json which is generated based on the hostSystemName In case, the user is on a new, not yet supported, build host this happens: MINGW64 ~/Workspace/cpp/fmt-module (master) $ diff .CMakeUserPresets…

---

## [installing a SHARED IMPORTED library's symlinks and real library file](https://discourse.cmake.org/t/installing-a-shared-imported-librarys-symlinks-and-real-library-file/13112)

<div class="topic-metadata">

**Author:** [@mattp](https://discourse.cmake.org/u/mattp)\
**Replies:** 0\
**Last updated:** [December 3, 2024, 4:26pm UTC](https://discourse.cmake.org/t/installing-a-shared-imported-librarys-symlinks-and-real-library-file/13112 "2024-12-03T16:26:07Z")

</div>

My project has a core library that is generated using GraalVM’s native-image tool from Java sources. Around this we wrap some C++ classes and other convenience functionality. The core is built out of CMake’s control, and…

---

## [Problems with interactions between $\<TARGET\_OBJECTS:lib\> and $\<$\<CONFIG:Debug\>:src.c\>](https://discourse.cmake.org/t/problems-with-interactions-between-target-objects-lib-and-config-debug-src-c/13058)

<div class="topic-metadata">

**Author:** [@Glidos](https://discourse.cmake.org/u/Glidos)\
**Replies:** 3\
**Last updated:** [December 1, 2024, 8:04pm UTC](https://discourse.cmake.org/t/problems-with-interactions-between-target-objects-lib-and-config-debug-src-c/13058 "2024-12-01T20:04:38Z")

</div>

I’m combining libraries in a cmake-based project using: add\_library(combined) target\_sources(combined PRIVATE $\<TARGET\_OBJECTS:lib1\> $\<TARGET\_OBJECTS:lib2\>) This in most cases works fine, but some of the source…

---

## [How can I export symbols? (Exporting class-methods)](https://discourse.cmake.org/t/how-can-i-export-symbols-exporting-class-methods/13065)

<div class="topic-metadata">

**Author:** [@BenEngbers](https://discourse.cmake.org/u/BenEngbers)\
**Replies:** 11\
**Last updated:** [November 29, 2024, 4:27pm UTC](https://discourse.cmake.org/t/how-can-i-export-symbols-exporting-class-methods/13065 "2024-11-29T16:27:23Z")

</div>

I still consider myself a fairly novice C++ programmer and with CMake I have even less experience. In an Eclipse CMake project I have written a shared library for accessing an XML database (BaseX). In the IDE the code c…

---

## [How to structure include()-s](https://discourse.cmake.org/t/how-to-structure-include-s/13071)

<div class="topic-metadata">

**Author:** [@silverqx](https://discourse.cmake.org/u/silverqx)\
**Replies:** 6\
**Last updated:** [November 28, 2024, 9:07pm UTC](https://discourse.cmake.org/t/how-to-structure-include-s/13071 "2024-11-28T21:07:31Z")

</div>

I’m using include()-s all around even for the same module or file, eg. include(TinyHelpers), I’m including it in the main CMakeLists.txt file at the top as it’s needed there, but I’m also including it in deeper modules o…

---

## [Selecting the vc++ compiler when using the "NMake Makefiles" generator](https://discourse.cmake.org/t/selecting-the-vc-compiler-when-using-the-nmake-makefiles-generator/13059)

<div class="topic-metadata">

**Author:** [@Glidos](https://discourse.cmake.org/u/Glidos)\
**Replies:** 2\
**Last updated:** [November 26, 2024, 10:33am UTC](https://discourse.cmake.org/t/selecting-the-vc-compiler-when-using-the-nmake-makefiles-generator/13059 "2024-11-26T10:33:23Z")

</div>

If I use one of the visual studio generators, the compiler is selected automatically, but if I use “NMake Makefiles” it seems I need to set CMAKE\_C\_COMPILER and CMAKE\_CXX\_COMPILER explicitly. Some posts suggest I don’t n…

---

## [A Gtk4 CMakeLists.txt example that includes gmodule-export-2.0](https://discourse.cmake.org/t/a-gtk4-cmakelists-txt-example-that-includes-gmodule-export-2-0/13052)

<div class="topic-metadata">

**Author:** [@oDinZu](https://discourse.cmake.org/u/oDinZu)\
**Replies:** 2\
**Last updated:** [November 26, 2024, 12:55am UTC](https://discourse.cmake.org/t/a-gtk4-cmakelists-txt-example-that-includes-gmodule-export-2-0/13052 "2024-11-26T00:55:31Z")

</div>

I have a software project that works with C, Gtk4 and CMake. I am relatively new to working with these pieces and haven’t discovered much documentation on how to properly make use of CMake. I have somehow pieced togethe…

---

## [Invalid workflow step on cmake preset](https://discourse.cmake.org/t/invalid-workflow-step-on-cmake-preset/13008)

<div class="topic-metadata">

**Author:** [@greenleafone7](https://discourse.cmake.org/u/greenleafone7)\
**Replies:** 7\
**Last updated:** [November 26, 2024, 12:13am UTC](https://discourse.cmake.org/t/invalid-workflow-step-on-cmake-preset/13008 "2024-11-26T00:13:43Z")

</div>

In the following preset file: { "version": 10, "cmakeMinimumRequired": { "major": 3, "minor": 31, "patch": 0 }, "configurePresets": \[ { "name": "common-configu…

---

## [CMake toolchain file ignores setting flag CMAKE\_CXX\_COMPILE\_OPTIONS\_PIE](https://discourse.cmake.org/t/cmake-toolchain-file-ignores-setting-flag-cmake-cxx-compile-options-pie/13055)

<div class="topic-metadata">

**Author:** [@Acki](https://discourse.cmake.org/u/Acki)\
**Replies:** 2\
**Last updated:** [November 25, 2024, 4:31pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-ignores-setting-flag-cmake-cxx-compile-options-pie/13055 "2024-11-25T16:31:36Z")

</div>

In the toolchain I am trying to set the compile setting to set(CMAKE\_CXX\_COMPILE\_OPTIONS\_PIE "-fpie") small fpie. But it has no effect when set in the toolchain. Only when I set it in the project itself. Testcase: htt…

---

## [What can I replace "INSTALL" with?](https://discourse.cmake.org/t/what-can-i-replace-install-with/13050)

<div class="topic-metadata">

**Author:** [@mzlink](https://discourse.cmake.org/u/mzlink)\
**Replies:** 6\
**Last updated:** [November 25, 2024, 3:50pm UTC](https://discourse.cmake.org/t/what-can-i-replace-install-with/13050 "2024-11-25T15:50:52Z")

</div>

Hello, I have a CMakeLists.txt that I’m not entirely happy with as a user of Visual Studio 2022. Basically, I haven’t found a solution to the catch-22 that is: if i do build ALL\_BUILD the INSTALL step happens and the ap…

---

## [graphviz](https://discourse.cmake.org/t/graphviz/11701)

<div class="topic-metadata">

**Author:** [@Sea\_Sea](https://discourse.cmake.org/u/Sea_Sea)\
**Replies:** 4\
**Last updated:** [November 25, 2024, 11:17am UTC](https://discourse.cmake.org/t/graphviz/11701 "2024-11-25T11:17:46Z")

</div>

i add it on my last code, but I can’ t see any png on my build folder. add\_custom\_target(graphviz ALL COMMAND ${CMAKE\_COMMAND} "--graphviz=${PROJECT\_NAME}.dot" . COMMAND dot -Tpng ${PROJECT\_NAME}.dot -o ${PROJEC…

---

## [Problems getting CMake to install the HEADERS file set](https://discourse.cmake.org/t/problems-getting-cmake-to-install-the-headers-file-set/13048)

<div class="topic-metadata">

**Author:** [@mattp](https://discourse.cmake.org/u/mattp)\
**Replies:** 2\
**Last updated:** [November 24, 2024, 7:12pm UTC](https://discourse.cmake.org/t/problems-getting-cmake-to-install-the-headers-file-set/13048 "2024-11-24T19:12:34Z")

</div>

Given the following CMakeLists.txt: cmake\_minimum\_required(VERSION 3.27) project(gubbins) set(CMAKE\_CXX\_STANDARD 14) set(CMAKE\_CXX\_VISIBILITY\_PRESET hidden) set(CMAKE\_VISIBILITY\_INLINES\_HIDDEN YES) add\_library(gubbins…

[Previous page](https://discourse.cmake.org/c/code/11.md?page=12)

[Next page](https://discourse.cmake.org/c/code/11.md?page=14)
