title: VS 2015: The breakpoint will not currently be hit. No symbols have been loaded for this document
body: <h2>The problem</h2>
  
  <p>I have a C++ (*.cpp) file, which is part of a static library project that I can't put an active breakpoint. When I do, it gives me the notification seen in the title of this post. <strong><em>I can put breakpoints in any other C++ file in that same project and it will be hit during debugging</em></strong>. There's nothing special about this C++ file. I use CMake to generate the projects and I also refer to the class in the executable project. There are no linking errors, just that debugger says that no debug symbols have been loaded for that source file. I have tried several ways to try and diagnose what's wrong and I don't have a good answer as to what's going on in my case.</p>
  
  <h2>What I have tried</h2>
  
  <ol>
  <li><strong>Compare this file with other *.cpp files in the same project</strong>: I cross-check the compiler flags between this and other files that I tested to verify are able to put a valid breakpoint. There's nothing different.</li>
  <li><strong>Rebuild the entire solution</strong>: As you might've guess, this didn't help</li>
  <li><strong>Recreate the entire solution using CMake</strong>: This didn't make any difference either.</li>
  <li><strong>Included the file in the source file that had main() and referred to the class in that file</strong>: This made the difference. I was able to put breakpoint in the class and its code was getting executed, while previously, it wasn't.</li>
  </ol>
  
  <h2>More Information about code</h2>
  
  <ul>
  <li>The C++ file I'm referring to is <a href="https://github.com/ViteFalcon/RokLegend/blob/8644d99322f5d0a8ebb80dc8a052ac69d831d423/source/network/packets/RoCreateCharacterSuccess.cpp#L4" rel="nofollow"><code>RoCreateCharacterSuccess.cpp</code></a></li>
  <li>The job of <a href="https://github.com/ViteFalcon/RokLegend/blob/8644d99322f5d0a8ebb80dc8a052ac69d831d423/source/network/packets/RoPacket.h#L163-L166" rel="nofollow"><code>roREGISTER_PACKET</code></a> is to register this packet class with another class (<a href="https://github.com/ViteFalcon/RokLegend/blob/8644d99322f5d0a8ebb80dc8a052ac69d831d423/source/network/packets/RoPacketTranslator.h#L17-L18" rel="nofollow"><code>RoPacketTranslator</code></a>) when the application initializes.</li>
  <li>The <a href="https://github.com/ViteFalcon/RokLegend/blob/8644d99322f5d0a8ebb80dc8a052ac69d831d423/source/network/packets/RoCreateCharacterSuccess.cpp#L6-L9" rel="nofollow">constructor of <code>RoCreateCharacterSuccess</code></a> gets invoked when registering the packet class.</li>
  <li>When the breakpoint isn't active, this constructor doesn't get invoked. I know this because this packet class doesn't exist in the class that it's supposed to be registered with. It's like <code>RoCreateCharacterSuccess.cpp</code> is never part of the static library it's supposed to be in. But if I purposefully change the file to introduce a syntax error, the library fails to build.</li>
  <li>To make this file be able to have active breakpoints, I have to manually register the packet with the translator in the application.</li>
  </ul>
  
  <p>Has anyone else seen such an issues? I'm stumped at this point trying to understand what's happening. Any help in shedding light into what's happening here would be great! Thanks for your time reading this question.</p>
  
  <p><strong>EDIT</strong>: I forgot to mention that this problem was diagnosed because I was trying to diagnose why the character creation packet didn't get translated into <code>RoCreateCharacterSuccess</code> object when <a href="https://github.com/ViteFalcon/RokLegend/blob/8644d99322f5d0a8ebb80dc8a052ac69d831d423/source/application/services/RoCharacterServerInterface.cpp#L170-L182" rel="nofollow">the character gets successfully created</a>. I later found that <code>RoCreateCharacterSuccess</code> class was not getting registered with <code>RoPacketTranslator</code> class. Trying to put a breakpoint to check if the constructor was called lead to this question.</p>
  
  <hr>
  
  <h3>Solution</h3>
  
  <p>Thanks to @user1, I figured out what was happening. So, in my executable, <a href="https://github.com/ViteFalcon/RokLegend/blob/8644d99322f5d0a8ebb80dc8a052ac69d831d423/source/application/services/RoCharacterServerInterface.cpp#L170-L182" rel="nofollow">where I refer to this class (or an instance of it)</a>, I was only accessing <a href="https://github.com/ViteFalcon/RokLegend/blob/8644d99322f5d0a8ebb80dc8a052ac69d831d423/source/network/packets/RoCreateCharacterSuccess.h#L12-L15" rel="nofollow"><code>RoCreateCharacterSuccess::getCharacter()</code></a>, which is in the header-file and probably got inline'd by the compiler into the executable. As far as the compiler could see, that was my only interaction with that class. I wasn't invoking its <a href="https://github.com/ViteFalcon/RokLegend/blob/8644d99322f5d0a8ebb80dc8a052ac69d831d423/source/network/packets/RoCreateCharacterSuccess.cpp#L6-L9" rel="nofollow">constructor, which was defined in the <code>cpp</code> file</a>. This means that the compiler has the opportunity to optimize that part of the code away (I did have that option turned on).</p>
  
  <p><strong>The solution</strong>: I moved the definition of the only method I interact with, <code>RoCreateCharacterSuccess::getCharacter()</code>, into the cpp file, therefore avoiding inline'ing and forcing the compiler to link to that part of the static library that defined <code>RoCreateCharacterSuccess</code> class, thereby triggering the act of registering <code>RoCreateCharacterSuccess</code> class with the translator class.</p>