<p>Have a look at the cmake <a href="https://cmake.org/cmake/help/latest/module/FindVulkan.html" rel="nofollow noreferrer">FindVulkan</a> page. It mentions a shaderc_combined component. With it, you can find the package plus the component:</p>
<pre><code>find_package(Vulkan REQUIRED COMPONENTS shaderc_combined)
</code></pre>
<p>This will fill <code>Vulkan_shaderc_combined_LIBRARY</code> variable.
In my project I went on to change this one for debug, apparently something was off for me (so ymmv):</p>
<pre><code>string(REPLACE &quot;.lib&quot; &quot;d.lib&quot; SHADERC_DEBUG ${Vulkan_shaderc_combined_LIBRARY})
</code></pre>
<p>Now it's just a matter of adding these to your target link libraries, like you did with Vulkan</p>
<pre><code>target_link_libraries(<span class="math-container">${PROJECT_NAME} PUBLIC
    debug $</span>{SHADERC_DEBUG}
    optimized ${Vulkan_shaderc_combined_LIBRARY})
</code></pre>
<p>With all that said, the above mentioned cmake page also mentions <code>Vulkan::shaderc_combined</code>, so perhaps it's even sufficient to use</p>
<pre><code>target_link_libraries(${PROJECT_NAME} INTERFACE Vulkan::Vulkan Vulkan::shaderc_combined)
</code></pre>
<p>but I have not tested that.</p>

CC BY-SA 4.0
2024-04-22T10:06:16.690Z
Thanks men you method works i literally could my have figured this out my own also what else worked for me for a successful compile was this ```target_link_libraries(${PROJECT_NAME} INTERFACE vulkan-1 shaderc_shared)``` i added the vulkanSDK manually using env.cmake an used the above to link the library idk if that's a correct approach but it also worked.
GloriousDemonFist
CC BY-SA 4.0
2024-04-22T10:22:50.060Z
Happy to help. Please accept the answer such that the question is not marked as unanswered.
Tare
CC BY-SA 4.0
2024-04-22T10:35:01.733Z
btw do you know how do i add spriv iam alos getting the same error when i try to link the spriv cross ```target_link_libraries(${PROJECT_NAME} INTERFACE vulkan-1 shaderc_shared spirv-cross-core)``` getting the same error with spriv
GloriousDemonFist
CC BY-SA 4.0
2024-04-22T10:47:59.633Z
The cmake page abouf vulkan at least doess not list spirv-cross-core. I don't know if it is part of the SPIRV-Tools they mention. The [Khronos SPIRV-Cross](https://github.com/KhronosGroup/SPIRV-Cross) repository has a section about linking to it. You need to use the repository as a submodule (or pull it as a third party dependency in whichever way your system does it) and then use the `add_subdirectory` command with this as an input.
Tare
CC BY-SA 4.0
2024-04-22T09:31:16.427Z
2024-04-22T09:31:16.427Z
Tare
<p>CMakeLists.txt</p>
<pre class="lang-cpp prettyprint-override"><code>find_package(Vulkan REQUIRED)
target_link_libraries(${PROJECT_NAME} INTERFACE Vulkan::Vulkan)
</code></pre>
<p>in my shader.cpp</p>
<pre class="lang-cpp prettyprint-override"><code>void OpenGLShader::Compile(const std::unordered_map&lt;GLenum, std::string&gt;&amp; shaderSources)
    {       
        vk::Buffer;
        shaderc::Compiler compiler;
        shaderc::CompileOptions options;
    }
</code></pre>
<p>what iam try to do is testing if this works for shaderc but ima getting these error</p>
<pre><code>out\build\x64-debug\GLContext.lib(OpenGLShader.cpp.obj) : error LNK2019: unresolved external symbol shaderc_compiler_release referenced in function &quot;public: __cdecl shaderc::Compiler::~Compiler(void)&quot; (??1Compiler@shaderc@@QEAA@XZ)
out\build\x64-debug\GLContext.lib(OpenGLShader.cpp.obj) : error LNK2019: unresolved external symbol shaderc_compile_options_initialize referenced in function &quot;public: __cdecl shaderc::CompileOptions::CompileOptions(void)&quot; (??0CompileOptions@shaderc@@QEAA@XZ)
\out\build\x64-debug\GLContext.lib(OpenGLShader.cpp.obj) : error LNK2019: unresolved external symbol shaderc_compile_options_initialize referenced in function &quot;public: __cdecl shaderc::CompileOptions::CompileOptions(void)&quot; (??0CompileOptions@shaderc@@QEAA@XZ)
\out\build\x64-debug\GLContext.lib(OpenGLShader.cpp.obj) : error LNK2019: unresolved external symbol shaderc_compile_options_release referenced in function &quot;public: __cdecl shaderc::CompileOptions::~CompileOptions(void)&quot; (??1CompileOptions@shaderc@@QEAA@XZ)

</code></pre>
<p><code>vk::Buffer;</code>
this work fine but adding ```shaderc<span class="math-container">```</span> causes these errors can someone explain me what am i missing</p>

CC BY-SA 4.0
2024-04-20T19:03:57.037Z
This is usually the result of missing a library in the build. In this case it is probably the libraries associated with shaderc.
pmw1234
CC BY-SA 4.0
2024-04-20T22:22:19.113Z
You mean to say the lib present in the vulkan folder that i may have missed, also i am just using Vulkan::Vulkan to link. Is there a similar alias for shaderc ?
GloriousDemonFist
<opengl><vulkan>
Getting linking error while testing to add vulkan shaderc in my project
GloriousDemonFist
# Getting linking error while testing to add vulkan shaderc in my project

(Asked by: username_0 on 2024-04-20)

CMakeLists.txt

```cpp
find_package(Vulkan REQUIRED)
target_link_libraries(${PROJECT_NAME} INTERFACE Vulkan::Vulkan)

```

in my shader.cpp

```cpp
void OpenGLShader::Compile(const std::unordered_map<GLenum, std::string>& shaderSources)
    {       
        vk::Buffer;
        shaderc::Compiler compiler;
        shaderc::CompileOptions options;
    }

```

what iam try to do is testing if this works for shaderc but ima getting these error

```
out\build\x64-debug\GLContext.lib(OpenGLShader.cpp.obj) : error LNK2019: unresolved external symbol shaderc_compiler_release referenced in function "public: __cdecl shaderc::Compiler::~Compiler(void)" (??1Compiler@shaderc@@QEAA@XZ)
out\build\x64-debug\GLContext.lib(OpenGLShader.cpp.obj) : error LNK2019: unresolved external symbol shaderc_compile_options_initialize referenced in function "public: __cdecl shaderc::CompileOptions::CompileOptions(void)" (??0CompileOptions@shaderc@@QEAA@XZ)
\out\build\x64-debug\GLContext.lib(OpenGLShader.cpp.obj) : error LNK2019: unresolved external symbol shaderc_compile_options_initialize referenced in function "public: __cdecl shaderc::CompileOptions::CompileOptions(void)" (??0CompileOptions@shaderc@@QEAA@XZ)
\out\build\x64-debug\GLContext.lib(OpenGLShader.cpp.obj) : error LNK2019: unresolved external symbol shaderc_compile_options_release referenced in function "public: __cdecl shaderc::CompileOptions::~CompileOptions(void)" (??1CompileOptions@shaderc@@QEAA@XZ)

```

`vk::Buffer;`
this work fine but adding ```shaderc``` causes these errors can someone explain me what am i missing

**Tags:** opengl, vulkan

> **Comments:**
> **username_1**: This is usually the result of missing a library in the build. In this case it is probably the libraries associated with shaderc.  
> **username_0**: You mean to say the lib present in the vulkan folder that i may have missed, also i am just using Vulkan::Vulkan to link. Is there a similar alias for shaderc ?  

---

## 1 answers

### Answer by username_2 on 2024-04-22. Score: 0 | Accepted answer

Have a look at the cmake [FindVulkan](https://cmake.org/cmake/help/latest/module/FindVulkan.html) page. It mentions a shaderc\_combined component. With it, you can find the package plus the component:

```
find_package(Vulkan REQUIRED COMPONENTS shaderc_combined)

```

This will fill `Vulkan_shaderc_combined_LIBRARY` variable.
In my project I went on to change this one for debug, apparently something was off for me (so ymmv):

```
string(REPLACE ".lib" "d.lib" SHADERC_DEBUG ${Vulkan_shaderc_combined_LIBRARY})

```

Now it's just a matter of adding these to your target link libraries, like you did with Vulkan

```
target_link_libraries(${PROJECT_NAME} PUBLIC
    debug ${SHADERC_DEBUG}
    optimized ${Vulkan_shaderc_combined_LIBRARY})

```

With all that said, the above mentioned cmake page also mentions `Vulkan::shaderc_combined`, so perhaps it's even sufficient to use

```
target_link_libraries(${PROJECT_NAME} INTERFACE Vulkan::Vulkan Vulkan::shaderc_combined)

```

but I have not tested that.

> **Comments:**
> **username_0**: Thanks men you method works i literally could my have figured this out my own also what else worked for me for a successful compile was this ```target_link_libraries(${PROJECT_NAME} INTERFACE vulkan-1 shaderc_shared)``` i added the vulkanSDK manually using env.cmake an used the above to link the library idk if that's a correct approach but it also worked.  
> **username_2**: Happy to help. Please accept the answer such that the question is not marked as unanswered.  
> **username_0**: btw do you know how do i add spriv iam alos getting the same error when i try to link the spriv cross ```target_link_libraries(${PROJECT_NAME} INTERFACE vulkan-1 shaderc_shared spirv-cross-core)``` getting the same error with spriv  
> **username_2**: The cmake page abouf vulkan at least doess not list spirv-cross-core. I don't know if it is part of the SPIRV-Tools they mention. The [Khronos SPIRV-Cross](https://github.com/KhronosGroup/SPIRV-Cross) repository has a section about linking to it. You need to use the repository as a submodule (or pull it as a third party dependency in whichever way your system does it) and then use the `add_subdirectory` command with this as an input.  

---

