not enough arguments for function-like macro invocation 'realloc'
-
I have a problem, including some QtCore libraries in my project. I am using CMake and Visual Studio Qt 5.15. In my CMakeLists.txt I include QtCore like this:
find_package(Qt5 REQUIRED COMPONENTS Core) target_link_libraries(${projectName} PRIVATE Qt5::Core)
Then I add:
#include <qstring.h> #include <qfile.h>
in my code and some errors will show up:
C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(103): warning C4003: not enough arguments for function-like macro invocation 'realloc' C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(316): error C2059: syntax error: 'constant' C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(327): note: see reference to class template instantiation 'QVector<T>' being compiled C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(411): warning C4003: not enough arguments for function-like macro invocation 'realloc' C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(420): warning C4003: not enough arguments for function-like macro invocation 'realloc' C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(700): error C2988: unrecognizable template declaration/definition C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(700): error C2059: syntax error: 'constant' C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(1071): warning C4003: not enough arguments for function-like macro invocation 'realloc'
This error is probably issue of defining realloc two times, first in the qstring.h, then in the qfile.h.
I tried deleting CMake cache, but with no result. This problem most probably has started since migrating from Visual Studio solution to CMake.
-
Your dev environment is wrong. Fix it. No Qt specfic problem I would guess. Create a simple main.cpp and see if it compiles when you include a Qt header. If not remove the Qt header and try to call realloc() directly by yourself. I would guess you get the same errors then.
-
@gragas said in not enough arguments for function-like macro invocation 'realloc':
Then I add:
#include <qstring.h>
#include <qfile.h>This error is probably issue of defining realloc two times, first in the qstring.h, then in the qfile.h.
Because you are not suppose to include the .h files. They are internal to the framework. You include the <QFile> and <QString> headers.
-
@Kent-Dorfman said in not enough arguments for function-like macro invocation 'realloc':
you are not suppose to include the .h files. They are internal to the framework. You include the <QFile> and <QString> headers.
But this can't lead to the compiler errors.
-
I think it could, and very well may be. constant is obviously an undefined macro and the not enough arguements is probably a consequence of stringing together macro definitions where some are missing and are null or default empty strings.
-
@Kent-Dorfman said in not enough arguments for function-like macro invocation 'realloc':
I think it could, and very well may be.
No, there is no difference when I include
qcolor.h
orQColor
:> cat /usr/include/qt5/QtGui/QColor #include "qcolor.h"
-
The reason this happened was, redefinition of realloc keyword. I had to do push/pop realloc macro for new keyword as well. I Think this issue was solved in Qt 6, but thanks anyway. Refference: https://bugreports.qt.io/browse/QTBUG-40575.
-
Hi,
Adding link to the corresponding code review.
-
Hi and welcome to devnet,
@KIMI2023 said in not enough arguments for function-like macro invocation 'realloc':I met the same question, (Debug version NG, release version OK)
Solution:
find file[crtdbg.h]:D:\Windows Kits\10\Include\10.0.19041.0\ucrt\crtdbg.h
to commet follow:
//#define realloc(p, s) _realloc_dbg(p, s, _NORMAL_BLOCK, FILE, LINE)Changing a file in the Windows development framework is not the correct way to handle that situation. As was done in the patch I linked, fixing the code is.