title: Error making const correct Vulkan CreateDebugMessenger function
body: <p>I seem to have run into a bit of a pickle.  I was attempting to modify some functions I made while following a Vulkan tutorial, which is essentially the function below but minus the function parameters and return type.  Everything worked just fine creating an instance, so I thought there wouldn't be a problem doing this with VkDebugUtilsMessengerEXT.</p>
  
  <p>Well, the linker kept stopping me and telling me "Undefined symbol: _vkCreateDebugUtilsMessengerEXT", and after confirming it was not a header loop issue or type mismatch, I was thoroughly confused.  It now works, but only because I made it inline, which shouldn't have changed anything right?  If anyone can explain why inlining changed anything, and how to make it work normally I would be very appreciative.</p>
  
  <pre><code>VkDebugUtilsMessengerEXT* ApplicationComponentConstructor::setupDebugMessenger(VkInstance* const instance) const
  {
      if (!enableValidationLayers) return nullptr;
  
      VkDebugUtilsMessengerEXT* newDebugMessenger = new VkDebugUtilsMessengerEXT;
  
      VkDebugUtilsMessengerCreateInfoEXT createInfo {};
      createInfo = generateDebugMessengerCreateInfo();
  
      if (vkCreateDebugUtilsMessengerEXT(*instance, &amp;createInfo, nullptr, newDebugMessenger) != VK_SUCCESS)
          throw std::runtime_error("Failed to setup debug messenger!");
  
      return newDebugMessenger;
  }
  </code></pre>
  
  <p>This function definition is in a file called "componentConstructor.cpp" and is a post-definition of a member of the "ApplicationComponentConstructor" class in "componentConstructor.hpp".  Here is the class for reference:</p>
  
  <pre><code>#pragma clang diagnostic push
  #pragma clang diagnostic ignored "-Wdocumentation"
  
  #define GLFW_INCLUDE_VULKAN
  #include &lt;GLFW/glfw3.h&gt;
  
  #ifndef componentConstructor_hpp
  #define componentConstructor_hpp
  
  #include &lt;stdio.h&gt;
  #include &lt;vector&gt;
  
  #ifdef NDEBUG
      const bool enableValidationLayers = false;
  #else
      const bool enableValidationLayers = true;
  #endif
  
  const int WINDOW_WIDTH = 750;
  const int WINDOW_HEIGHT = 750;
  
  class ApplicationComponentConstructor
  {
  public:
      friend class GameApplication;
  
  private:
      // Start of static helper functions
      using VkDUMessageSeverity = VkDebugUtilsMessageSeverityFlagBitsEXT;
      using VkDUMessageType = VkDebugUtilsMessageTypeFlagsEXT;
      using VkDUMCallBackData = VkDebugUtilsMessengerCallbackDataEXT;
  
      static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDUMessageSeverity messageSeverity, VkDUMessageType messageType, const VkDUMCallBackData* pCallBackData, void* pUserData);
  
      static std::vector&lt;char&gt; readFile(const std::string &amp;fileName);
      // End of static helper functions
  
      // INSTANCE CREATION FUNCTIONS
      VkInstance* createInstance() const;
  
      // DEBUG MESSENGER CREATION FUNCTIONS
      VkDebugUtilsMessengerEXT* setupDebugMessenger(VkInstance* const instance) const;
  
      VkDebugUtilsMessengerCreateInfoEXT generateDebugMessengerCreateInfo() const;
  
      // SURFACE CREATION FUNCTIONS
      VkSurfaceKHR* createSurface();
  
      // LOGICAL DEVICE CREATION FUNCTIONS
      VkDevice* createLogicalDevice();
  };
  
  #endif /* componentConstructor_hpp */
  </code></pre>
  
  <p>And last, but not least, here is the build log from Xcode:</p>
  
  <pre><code>
  Showing Recent Messages
  
  Prepare build
  note: Using new build system
  note: Building targets in parallel
  note: Planning build
  note: Using build description from memory
  
  
  
  Build target VulkanProject of project VulkanProject with configuration Debug
  
  CompileC /Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/Objects-normal/x86_64/componentConstructor.o /Users/ksbilodeau/Desktop/Xcode\ Projects/VulkanProject/VulkanProject/componentConstructor.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'VulkanProject' from project 'VulkanProject')
      cd /Users/ksbilodeau/Desktop/Xcode\ Projects/VulkanProject
      export LANG=en_US.US-ASCII
      /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -target x86_64-apple-macos10.15 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu++1z -stdlib=libc++ -fmodules -gmodules -fmodules-cache-path=/Users/ksbilodeau/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/ksbilodeau/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wdocumentation -Wunreachable-code -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DDEBUG=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -g -fvisibility-inlines-hidden -Wno-sign-conversion -Winfinite-recursion -Wmove -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wrange-loop-analysis -Wno-semicolon-before-method-body -Wunguarded-availability -index-store-path /Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Index/DataStore -iquote /Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/VulkanProject-generated-files.hmap -I/Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/VulkanProject-own-target-headers.hmap -I/Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/VulkanProject-all-target-headers.hmap -iquote /Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/VulkanProject-project-headers.hmap -I/Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Products/Debug/include -I/usr/local/include -I/Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/DerivedSources-normal/x86_64 -I/Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/DerivedSources/x86_64 -I/Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/DerivedSources -F/Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Products/Debug -F/Library/Frameworks -MMD -MT dependencies -MF /Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/Objects-normal/x86_64/componentConstructor.d --serialize-diagnostics /Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/Objects-normal/x86_64/componentConstructor.dia -c /Users/ksbilodeau/Desktop/Xcode\ Projects/VulkanProject/VulkanProject/componentConstructor.cpp -o /Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/Objects-normal/x86_64/componentConstructor.o
  
  Ld /Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Products/Debug/VulkanProject normal x86_64 (in target 'VulkanProject' from project 'VulkanProject')
      cd /Users/ksbilodeau/Desktop/Xcode\ Projects/VulkanProject
      /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target x86_64-apple-macos10.15 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -L/Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Products/Debug -L/usr/local/lib -L/usr/local/Cellar/glfw/HEAD-e65de29/lib -F/Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Products/Debug -F/Library/Frameworks -filelist /Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/Objects-normal/x86_64/VulkanProject.LinkFileList -Xlinker -object_path_lto -Xlinker /Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/Objects-normal/x86_64/VulkanProject_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -stdlib=libc++ -lvulkan.1 -framework vulkan -lglfw.3.4 -Xlinker -dependency_info -Xlinker /Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Intermediates.noindex/VulkanProject.build/Debug/VulkanProject.build/Objects-normal/x86_64/VulkanProject_dependency_info.dat -o /Users/ksbilodeau/Library/Developer/Xcode/DerivedData/VulkanProject-gbxmwgztncvnifafqcyuyrehhkxs/Build/Products/Debug/VulkanProject
  
  Undefined symbols for architecture x86_64:
    "_vkCreateDebugUtilsMessengerEXT", referenced from:
        ApplicationComponentConstructor::setupDebugMessenger(VkInstance_T**) const in componentConstructor.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  
  
  
  Build failed    4/15/20, 11:39 PM    0.6 seconds
  </code></pre>
  
  <p>Heres a link to the tutorial I followed, if it helps somehow: <a href="https://vulkan-tutorial.com" rel="nofollow noreferrer">https://vulkan-tutorial.com</a>.</p>