Solved C++ <complex> yielding strange behavior
-
make: Circular complex.o <- complex dependency dropped.
@mzimmers I don't fully understand what happened, but I'm guessing that
make
got confused by multiple things called "complex" in your project and its dependencies (#include <complex>)What happens if you delete your build folder, make sure your file is not called complex.cpp, and run qmake again?
-
Move your executable out of your source tree! ;)
#include <complex>
This includes your executable (as the current dir is first to be searched) instead of the standard header, thus you get the weird errors. Use a separate folder for building and you'll be fine.
-
Thanks for the replies, guys. The problem was indeed linked to a filename confusion. I renamed the project to "complex_test" and it worked just fine. You see something new every day...
kshegunov: I was using a shadow build, so I didn't expect the executable to be found. Is it temporarily in the source directory before the build finishes?
-
@mzimmers said in C++ <complex> yielding strange behavior:
Is it temporarily in the source directory before the build finishes?
No, but if your output (build) directory is in the include path then that'd do it.
-
@kshegunov Hmm...it's almost certainly not, at least not explicitly by anything I did. Perhaps some more experimentation is in order. I'm curious as to whether this would occur with other libraries.
-
@mzimmers said in C++ <complex> yielding strange behavior:
Hmm...it's almost certainly not, at least not explicitly by anything I did. Perhaps some more experimentation is in order. I'm curious as to whether this would occur with other libraries.
Do you use the widgets module? If you do try to determine the
.ui
file's output dir, this might be a reason why the build dir may be added to the include path. Can you share the project file? -
No widgets. Here's the project file:
TEMPLATE = app CONFIG += console c++11 CONFIG -= app_bundle CONFIG -= qt SOURCES += \ main.cpp
Weird, huh? I'm not sure whether it's the .cpp file or the project file that's getting in the way, but we're definitely on the right track.
-
@mzimmers said in C++ <complex> yielding strange behavior:
Weird, huh?
Indeed. What about the compile and link line? There should be some clue somewhere why this is being included.
-
Here's the compile line, and a little output:
09:40:59: Starting: "/usr/bin/make" g++ -c -pipe -g -std=gnu++11 -Wall -W -fPIC -DQT_QML_DEBUG -I../complex_test -I. -I/opt/Qt/5.9/5.9.1/gcc_64/mkspecs/linux-g++ -o main.o ../complex_test/main.cpp In file included from ../complex_test/main.cpp:2:0: ./complex:1:1: error: stray ‘\177’ in program
Another data point: I tried it with the source file named "main.cpp" but the project file still "complex.pro" and it failed.
-
@mzimmers said in C++ <complex> yielding strange behavior:
g++ ... -I.
This is what does it. I'm not sure where it comes from though. As a workaround rename your executable, so it doesn't conflict:
TARGET = complex_app
-
OK, that makes sense. I imagine this same problem would occur with other libraries as well. Good lesson learned. Thanks for the help.
PS: I wonder whether this would happen on Windows. I'd expect the .exe suffix to prevent it, but who knows...
-
@mzimmers said in C++ <complex> yielding strange behavior:
I'd expect the .exe suffix to prevent it, but who knows...
Yes, that is correct, it's a linux/mac peculiarity.