Breakpoint does not fall into global static initialized class in statically linked lib

I experienced strange behavior on the part of VS2010.

I added this simple code to two .cpp files and put a breakpoint on the specified line of code

namespace {
   class TestClass
   {
   public:
      TestClass ()
      {
         printf (""); // ### BREAKPOINT_HERE
      }
   };
}
TestClass a;

The strange thing is that after compiling and starting the program, the breakpoint in one of the files is correct, and in the other it is automatically turned off with a warning: "At the moment, the breakpoint will not be deleted. No characters have been loaded for this document.

.cpp . , , , , , ​​ - , .

- , ?

Cheers,

+3
6

, , . , . , .

, , ++. , , , . , . , , ; , , .

, , A - B, B , . - , , .

+1

, LIB. , ! , " " . . , - ? , . , - , . ( Visual ++ ...)

Update: , . LIB , . , .

, :

// Registrations.cpp
#ifdef EXPORT_REGISTRATIONS
#define REGISTRATION_CODE(theClass) \
       void register_##theClass##_function() { \
           // Code for registering your class \
       }
#else
#define REGISTRATION_CODE(theClass) \
       // Declare a function prototype for the function in LIB \
       void register_##theClass##_function(); \
       struct theClass##importer { \
           theClass##importer() { \
               // Call into LIB \
               register_##theClass##_function(); \
           } \
       } g_##theClass##importerInstance; \
#endif

REGISTRATION_CODE(MyClass);
REGISTRATION_CODE(MyOtherClass);

LIB , EXPORT_REGISTRATIONS . , , . , EXPORT_REGISTRATIONS . #include "<path to lib project>\Registrations.cpp" . (, ), , LIB.

. .:)

+1

a . , , .

, , .

( TestClass : -, , - , , , .)

+1

, main()

, , . , .

0

, , , . ( , 10.15.)

-, , getClassesRegistry? - , , ?

0

I found some new facts that can shed light on the situation and edit the main message.

Try disabling the optimization of the entire program and see what happens. You may need to do something so that the optimizer does not treat these objects as dead code.

The general solution is compiled in debug mode with optimization turned off. The project in which the files are located is compiled as a static library.

-1
source

Source: https://habr.com/ru/post/1782636/


All Articles