So I wanted to play around with custom new/delete a bit and followed this answer. I have a MWE that works nicely, but once I include a Qt header (even without using it), all I get is a segmentation fault. The segfault occurs before entering main() and I don't know whats going on. Here is the code:
/* main.cpp */
#include <iostream>
//#include <QString> // uncommenting this line causes the segfault
int main() {
int* ref = new int(42);
std::cout << ref << ", " << *ref << std::endl;
delete ref;
}
/* custom_new.cpp */
#include <iostream>
void* operator new(size_t n) {
void* result = malloc(n);
std::cout << "Allocating " << n << " bytes at position " << result << std::endl;
return result;
}
void operator delete(void* p) {
std::cout << "Deleting memory at position " << p << std::endl;
free(p);
}
# CMakeLists.txt
find_package(Qt5Core CONFIG REQUIRED)
add_library(custom_new custom_new.cpp)
add_executable(mwe main.cpp)
target_link_libraries(mwe Qt5::Core custom_new)