void* qMalloc(size_t sz) {return malloc(sz);}
void qFree(void* ptr) {free(ptr);}
void* qRealloc(void* ptr, size_t sz) {return realloc(ptr, sz);}
I make a static library from this file
1) g++ -fPIC -c myStubs.cpp -o lib_mylib.o
2) ar rcs libMyLib.a lib_mylib.o
In Qt Core we have file qglobal.cpp
2 ) File is qt-x11-opensource-src-4.3.3/src/corelib/global/qglobal.cpp and same functions as above in this file are
/*
These functions make it possible to use standard C++ functions with
a similar name from Qt header files (especially template classes).
*/
Q_CORE_EXPORT void *qMalloc(size_t size);
Q_CORE_EXPORT void qFree(void *ptr);
Q_CORE_EXPORT void *qRealloc(void *ptr, size_t size);
When I link the static library libMyLib.a and static library of QtCore (libQtCore.a) and QtGui (libQtGui.a) . I am getting following build error
lib/libQtCore.a(qglobal.o): In function `qMalloc(unsigned long)':
qglobal.cpp:(.text+0x170): multiple definition of `qMalloc(unsigned long)'
libMyLib.a(myStubs.o):myStubs.cpp:(.text+0x0): first defined here
Questions
1) If I remove qMalloc , qFree and qRealloc from file myStubs.cpp, I do not get the build error , Is this correct way of solving this problem