# How to skip link step when building ?

**URL:** https://discourse.cmake.org/t/how-to-skip-link-step-when-building/9895
**Category:** Usage
**Created:** [January 21, 2024, 5:54pm UTC](https://discourse.cmake.org/t/how-to-skip-link-step-when-building/9895 "2024-01-21T17:54:23Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Timothy\_Madden](https://discourse.cmake.org/user_avatar/discourse.cmake.org/timothy_madden/32/4211_2.png) [@Timothy\_Madden](https://discourse.cmake.org/u/Timothy_Madden)
#### Post date: [January 21, 2024, 5:54pm UTC](https://discourse.cmake.org/t/how-to-skip-link-step-when-building/9895/1 "2024-01-21T17:54:23Z")

</div>

Hello,

I want to build my project with clang, but only to setup omni completion (intellisense) in my editor (gVim). Doing this because at this time nothing else supports semantic completion with C++ modules.

Even if I fix my project to compile with this new compiler, linking still gives errors, and linking is not needed for my purpose.

Is it possible to tell CMake to skip the link step and only compile the source files ? Is it possible to some how set the link program to /bin/true, or a similiar option ?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [January 21, 2024, 9:04pm UTC](https://discourse.cmake.org/t/how-to-skip-link-step-when-building/9895/2 "2024-01-21T21:04:13Z")

</div>

There’s a plan for a similar feature in the works. Not sure of an exact deadline yet.

Well…at least the shared infrastructure. What, exactly, do you need done for this use case?

- scanning (discovering dependencies/module usages)
- module file generation (just compilation)

---

<div class="post-metadata">

### Author: ![Timothy\_Madden](https://discourse.cmake.org/user_avatar/discourse.cmake.org/timothy_madden/32/4211_2.png) [@Timothy\_Madden](https://discourse.cmake.org/u/Timothy_Madden)
#### Post date: [January 22, 2024, 8:27pm UTC](https://discourse.cmake.org/t/how-to-skip-link-step-when-building/9895/3 "2024-01-22T20:27:40Z")

</div>

All I need is to build my project without linking. Something like a ‘compile’ target for make / ninja would help. If possible I would try the -fsyntax-only option for clang as well.

Scanning for modules should happen as usual for the project.

Once I know the compilation is successfull, I want to manually copy the resulting build commands into a compile\_commands.json file. This file is used by clangd plugin in my text editor (YCM plugin for gVim) for semantic completion, and error hints during code editing.

CMake already has an option to generate the compilation database for clangd, but it only works for trivial cases. If I have a module file, like std.ixx, outside the project directory (from Visual Studio install directory, used as instructed by Microsoft), for which I create and interface library or an object library, the file and the build command will not show up in the compilation database.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [January 23, 2024, 12:50pm UTC](https://discourse.cmake.org/t/how-to-skip-link-step-when-building/9895/4 "2024-01-23T12:50:43Z")

</div>

There are plans in the work for modules support; I don’t think `compile_commands.json` will be sufficient anyways.

Note that some linking may occur anyways in order to satisfy other CMake model requirements, but executables almost certainly won’t be linked at least. I’ll keep a `compile` target in mind when the related feature gets implemented, though I think your use case better fits under the “tooling support for C++ modules” umbrella (your `compile` target just being a mechanism to hack a solution up).

---

<div class="post-metadata">

### Author: ![Timothy\_Madden](https://discourse.cmake.org/user_avatar/discourse.cmake.org/timothy_madden/32/4211_2.png) [@Timothy\_Madden](https://discourse.cmake.org/u/Timothy_Madden)
#### Post date: [January 23, 2024, 2:37pm UTC](https://discourse.cmake.org/t/how-to-skip-link-step-when-building/9895/5 "2024-01-23T14:37:28Z")

</div>

Thank you,

I already have some “good enough” semantic completion for my small project (about 10 source files), with a `.json` file that I fixed by hand. So I still think the semantic engine or language server (clangd) can do the job, with a nice `compile_commands.json` file. Also I noticed clangd needs to access my intermediate directory for the pre-compiled modules. But even without the `.json` file, the YCM plugin can use an alternative python script, that essentially provides the build flags on request when clangd needs them.

I guess my real issue is: when I switched my project to use clang (instead of msvc) I started getting some build errors, including link errors. But the link errors I do not want to fix, because my project builds fine with msvc, and I only need clang for intellisense. So I started looking for a way to skip the link step.

---

<div class="post-metadata">

### Author: ![neundorf](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neundorf/32/2075_2.png) [@neundorf](https://discourse.cmake.org/u/neundorf)
#### Post date: [January 23, 2024, 2:40pm UTC](https://discourse.cmake.org/t/how-to-skip-link-step-when-building/9895/6 "2024-01-23T14:40:05Z")

</div>

Could you fake the linking by setting the CMAKE\_C/CXX\_LINK\_EXECUTABLE variables to something that doesn’t actually link, but just “touches” the resulting file, or something like this ?

---

<div class="post-metadata">

### Author: ![Timothy\_Madden](https://discourse.cmake.org/user_avatar/discourse.cmake.org/timothy_madden/32/4211_2.png) [@Timothy\_Madden](https://discourse.cmake.org/u/Timothy_Madden)
#### Post date: [January 23, 2024, 2:44pm UTC](https://discourse.cmake.org/t/how-to-skip-link-step-when-building/9895/7 "2024-01-23T14:44:36Z")

</div>

I assume cmake needs to identify the linker version, and makes a try-compile to probe the linker is in working order … it could maybe even try to run the test executable (like I think autoconf does…).

So it’s not clear how good the fake needs to be, if it works, might be non-trivial still … and how much argument parsing and what arguments I need to support.

It would be nice if cmake could identify /bin/true as a valid linker type … and assume I do not want to link. But not sure if that is even possible in case the linker is invoked by the compiler …

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [January 26, 2024, 1:44pm UTC](https://discourse.cmake.org/t/how-to-skip-link-step-when-building/9895/8 "2024-01-26T13:44:17Z")

</div>

Any use of binaries in the graph will want a real linker (e.g., a codegen tool). Ithink just giving a handle into what is needed and letting the graph dictate what is needed from there is the most robust and general solution.
