Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facing "unable to find string literal operator" error when compiling ui code with C++11

Tags:

c++

c++11

qt

I am compiling a QTGUI Application (version 4) with my own GNU makefile. Everything worked nice when I used the C++03 standard with the gcc compiler.

Now I need the C++11 standard and get the error:

unable to find string literal operator 'operator"" __ FILE__' "

at the following lines in my window.cpp

connect(ui->myGLWidget, SIGNAL(xRotationChanged(int)), ui->rotXSlider, SLOT(setValue(int)));
connect(ui->myGLWidget, SIGNAL(yRotationChanged(int)), ui->rotYSlider, SLOT(setValue(int)));
connect(ui->myGLWidget, SIGNAL(zRotationChanged(int)), ui->rotZSlider, SLOT(setValue(int)));

I tried to compile my .ui file with the UIC version 4 and 5 and nothing changed. The result of the UIC, ui_window.h has the same errors whenever Qbject::connect(.....) is used.

I can't go back to the old C++ standard and both UIC compilers produces the same ui_window.h file.

How can I get rid of it?

like image 275
Daniel R. Avatar asked May 29 '15 13:05

Daniel R.


1 Answers

Before C++11, the syntax "foo"__FILE__ would compile as "foo""filename.cpp", resulting in the concatenated string "foofilename.cpp". C++11 added a new feature, user-defined string literals, that uses suffixes at the end of a string literal "foo"_bar to perform a conversion of the string "foo" to some other type. As a consequence, "foo"__FILE__ now compiles as an attempt to invoke the user-defined string literal operator __FILE__ on "foo".

Presumably SIGNAL and SLOT are both macros on the source lines indicated - I know little about QT - and one or both of their expansions result in "foo"__FILE__ being present after preprocessing, resulting in the error you observe. If upgrading to a more recent QT is not an option for you, you could trace the definition of the MACROS and ensure there is a space between the tokens resulting in the "foo"__FILE__. Simply inserting a space may be sufficient, but if the macro definitions involve heavy token-pasting then sometimes forcing a token break with a comment /**/ is needed.

like image 142
Casey Avatar answered Oct 07 '22 10:10

Casey