When you encounter the error message “undefined reference to `typeinfo for testing::test'”, it means that the linker is unable to find the definition of the type `testing::test’, which is typically a class or a function in the namespace `testing’. This error commonly occurs when using C++ classes with virtual functions or when working with dynamic polymorphism.
The problem can be resolved by ensuring that the definition of the `testing::test’ class or function is included in the code and is properly linked during the compilation process. Here are a few possible causes and solutions for this error:
-
Missing or incorrect definition: Check if the declaration and definition of the `testing::test’ class or function are consistent. Make sure that the definition matches the declaration in terms of its return type, parameters, and constness. Ensure that the definition is included in the code, either in the same file or through a header file.
// Example of incorrect declaration // testing.hpp namespace testing { class test; } // Example of correct definition // testing.cpp #include "testing.hpp" namespace testing { class test { // Class implementation... }; }
-
Missing or incorrect linkage: If the definition of `testing::test’ exists in a separate source file, ensure that it is being linked properly during the compilation process. Link all necessary object files together to resolve any undefined references.
// Example of incorrect compilation // Compile only the main source file, missing definition source file g++ main.cpp -o output // Example of correct compilation // Compile all necessary source files together g++ main.cpp test.cpp -o output
-
Missing or incorrect compile flags: If you are using certain features of C++ that require additional compile flags, make sure to include them during the compilation process. For example, if you are using multiple source files with virtual functions, include the “-std=c++11” flag to enable polymorphic behavior.
// Example of correct compilation with C++11 flag g++ -std=c++11 main.cpp test.cpp -o output
By addressing any of the above causes, you should be able to resolve the “undefined reference to `typeinfo for testing::test'” error. Remember to ensure consistency between declarations and definitions, properly link object files, and include any necessary compile flags.
Read more interesting post
- No module named ‘keras.layers.advanced_activations’
- Valueerror: excel file format cannot be determined, you must specify an engine manually.
- Typedef redefinition with different types (‘uint8_t’ (aka ‘unsigned char’) vs ‘enum clockid_t’)
- Unable to process parts as no multi-part configuration has been provided
- Uncaught (in promise) error: a listener indicated an asynchronous response by returning true, but the message channel closed before a response was received