0
$\begingroup$

CMakeLists.txt

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

in my shader.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

$\endgroup$
2
  • $\begingroup$ This is usually the result of missing a library in the build. In this case it is probably the libraries associated with shaderc. $\endgroup$
    – pmw1234
    Commented Apr 20 at 19:03
  • $\begingroup$ 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 ? $\endgroup$ Commented Apr 20 at 22:22

1 Answer 1

0
$\begingroup$

Have a look at the cmake FindVulkan 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.

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$ Commented Apr 22 at 10:06
  • $\begingroup$ Happy to help. Please accept the answer such that the question is not marked as unanswered. $\endgroup$
    – Tare
    Commented Apr 22 at 10:22
  • $\begingroup$ 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 $\endgroup$ Commented Apr 22 at 10:35
  • $\begingroup$ 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 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. $\endgroup$
    – Tare
    Commented Apr 22 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.