Open Iuliean opened 5 months ago
The compile error cannot bind non-const lvalue reference of type ‘std::__cxx11::basic_string<char>&’ to an rvalue of type ‘std::__cxx11::basic_string<char>’
is caused by your source code passing rvalue where lvalue is needed.
This is not a problem with your use of CMake.
And we cannot help you if you do not provide source code to the source of the error.
I found a code that may be the cause of the error.
It appears to be a known problem (specification): fmtlib/fmt#3596
if(received == -1)
{
- m_logger.error("Failed to receive data: {}", utils::getErrorFromErrno());
+ std::string err = utils::getErrorFromErrno();
+ m_logger.error("Failed to receive data: {}", err);
exit(1);
}
Hmm interesting this worked untill recently for me, that's why i kinda dismissed the reference error. I thought i might have screwed something up when changing the cmake files.
Also i dont see where this issue is mentioned
It appears to me that this change has caused the return value of utils::getErrorFromErrno()
to be recognized as the format argument by fmt library.
And since the changed code is written in a header file, it is possible that the compiler did not build the code it deemed unreachable. Could it be that the compiler evaluated the changed code for the first time in an application that uses that library, resulting in a compile error?
If i understood correctly what you said the yes that is a possibility. but you can find plenty of examples throughout the code where i do the same thing but not in a header file and it did not happen.
https://github.com/Iuliean/SFW/blob/2d1bf050fcb98ea8feb94295edec91d43ee85f95/src/Connection.cpp#L26
This has pretty much always been there but no issues before.
My assumption is that the cmake files are fucked somehow since when i build the code with the above mentioned cmake files and project structure it also tries to tries to build the spdlog cpp files.
Also even weirder is that for me the change you mentioned works, it builds fine. if i revet back to the old one then yes it starts to fail again
As soon as i add it in the context of the other app mc-server it starts to fail again. It seems defines are not passed through i think includes are not there even though they should be i think
The compiler may change the scope of optimization depending on the compile-time options and the code that could be recognized on a per-translation basis.
I don't know what changes you have made to CMakeList.txt
, but if the compiler's optimization behavior has changed, compile errors can occur that appear to be contrary to human intuition.
Such problems are not under the jurisdiction of spdlog, but are either compiler specifications or bugs.
I can only suggest that if the change from rvalue to lvalue does not cause compile errors, then apply that change to all. That is the only way I know of to avoid the problem.
EDIT: Sometimes a non-standard feature causes the compiler to treat an rvalue as an lvalue, as in the following question: https://stackoverflow.com/questions/11508607/rvalue-to-lvalue-conversion-visual-studio This kind of compiler behavior is not something that can be managed by spdlog.
I found fmtlib/fmt#3589 that clearly explains the fmt changes related to this issue.
I keep getting this error when building with cmake and i cant figure out what is happening
My project structure goes like this.
And these are the cmake files.
I hope i am not completely misusing cmake though