Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. C++ <complex> yielding strange behavior
Forum Updated to NodeBB v4.3 + New Features

C++ <complex> yielding strange behavior

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 3.0k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi -

    I don't know whether this is a Qt issue or not, but I'm getting some weird behavior from Qt Creator. I created a new plain C++ project, and wrote the main routine thus:

    #include <iostream>
    #include <complex>
    
    using namespace std;
    
    int main()
    {
        complex<double> a(2.0, 3.0);
        complex<double> b(4.0, 5.0);
        complex<double> c;
    
        c = a + b;
        cout << "a + b = " << c <<endl;
    
        c = a * b;
        cout << "a * b = " << c <<endl;
    
        c = b - a;
        cout << "b - a = " << c <<endl;
    
        c = b / a;
        cout << "b / a = " << c <<endl;
    
        return 0;
    }
    

    Built and run, and it worked (I swear).

    Renamed main.cpp to complex.cpp and got a bunch of build errors:

    18:56:36: Running steps for project complex...
    18:56:36: Configuration unchanged, skipping qmake step.
    18:56:36: Starting: "/usr/bin/make" 
    make: Circular complex.o <- complex dependency dropped.
    g++ -c -pipe -g -std=gnu++11 -Wall -W -fPIC -DQT_QML_DEBUG -I../complex -I. -I/opt/Qt/5.9/5.9.1/gcc_64/mkspecs/linux-g++ -o complex.o ../complex/complex.cpp
    In file included from ../complex/complex.cpp:2:0:
    ./complex:1:1: error: stray ‘\177’ in program
    

    Renamed the file back to complex.cpp and now I get this:

    /opt/Qt/5.9/5.9.1/gcc_64/bin/qmake -o Makefile ../complex/complex.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug
    rm -f main.o
    rm -f *~ core *.core
    18:57:56: The process "/usr/bin/make" exited normally.
    18:57:56: Configuration unchanged, skipping qmake step.
    18:57:56: Starting: "/usr/bin/make" 
    make: Circular main.o <- complex dependency dropped.
    g++ -c -pipe -g -std=gnu++11 -Wall -W -fPIC -DQT_QML_DEBUG -I../complex -I. -I/opt/Qt/5.9/5.9.1/gcc_64/mkspecs/linux-g++ -o main.o ../complex/main.cpp
    In file included from ../complex/main.cpp:2:0:
    ./complex:1:1: error: stray ‘\177’ in program
     ELF          >    `@     @       �{          @ 8  @ $ !       @       @ @     @ @     �      �                           @      @                                          @   
    

    ...and a lot more.

    Running Creator 4.3.1 on Linux, using GCC. Ran the program on a Mac and got similar results (with CLANG).

    I have no idea whatsoever what's going on. Anyone? Thanks.

    kshegunovK 1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      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?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      3
      • mzimmersM mzimmers

        Hi -

        I don't know whether this is a Qt issue or not, but I'm getting some weird behavior from Qt Creator. I created a new plain C++ project, and wrote the main routine thus:

        #include <iostream>
        #include <complex>
        
        using namespace std;
        
        int main()
        {
            complex<double> a(2.0, 3.0);
            complex<double> b(4.0, 5.0);
            complex<double> c;
        
            c = a + b;
            cout << "a + b = " << c <<endl;
        
            c = a * b;
            cout << "a * b = " << c <<endl;
        
            c = b - a;
            cout << "b - a = " << c <<endl;
        
            c = b / a;
            cout << "b / a = " << c <<endl;
        
            return 0;
        }
        

        Built and run, and it worked (I swear).

        Renamed main.cpp to complex.cpp and got a bunch of build errors:

        18:56:36: Running steps for project complex...
        18:56:36: Configuration unchanged, skipping qmake step.
        18:56:36: Starting: "/usr/bin/make" 
        make: Circular complex.o <- complex dependency dropped.
        g++ -c -pipe -g -std=gnu++11 -Wall -W -fPIC -DQT_QML_DEBUG -I../complex -I. -I/opt/Qt/5.9/5.9.1/gcc_64/mkspecs/linux-g++ -o complex.o ../complex/complex.cpp
        In file included from ../complex/complex.cpp:2:0:
        ./complex:1:1: error: stray ‘\177’ in program
        

        Renamed the file back to complex.cpp and now I get this:

        /opt/Qt/5.9/5.9.1/gcc_64/bin/qmake -o Makefile ../complex/complex.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug
        rm -f main.o
        rm -f *~ core *.core
        18:57:56: The process "/usr/bin/make" exited normally.
        18:57:56: Configuration unchanged, skipping qmake step.
        18:57:56: Starting: "/usr/bin/make" 
        make: Circular main.o <- complex dependency dropped.
        g++ -c -pipe -g -std=gnu++11 -Wall -W -fPIC -DQT_QML_DEBUG -I../complex -I. -I/opt/Qt/5.9/5.9.1/gcc_64/mkspecs/linux-g++ -o main.o ../complex/main.cpp
        In file included from ../complex/main.cpp:2:0:
        ./complex:1:1: error: stray ‘\177’ in program
         ELF          >    `@     @       �{          @ 8  @ $ !       @       @ @     @ @     �      �                           @      @                                          @   
        

        ...and a lot more.

        Running Creator 4.3.1 on Linux, using GCC. Ran the program on a Mac and got similar results (with CLANG).

        I have no idea whatsoever what's going on. Anyone? Thanks.

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        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.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        4
        • mzimmersM Offline
          mzimmersM Offline
          mzimmers
          wrote on last edited by
          #4

          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?

          kshegunovK 1 Reply Last reply
          0
          • mzimmersM mzimmers

            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?

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @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.

            Read and abide by the Qt Code of Conduct

            mzimmersM 1 Reply Last reply
            0
            • kshegunovK kshegunov

              @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.

              mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by
              #6

              @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.

              kshegunovK 1 Reply Last reply
              0
              • mzimmersM mzimmers

                @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.

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by kshegunov
                #7

                @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?

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                0
                • mzimmersM Offline
                  mzimmersM Offline
                  mzimmers
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #9

                    @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.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    0
                    • mzimmersM Offline
                      mzimmersM Offline
                      mzimmers
                      wrote on last edited by
                      #10

                      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.

                      kshegunovK 1 Reply Last reply
                      0
                      • mzimmersM mzimmers

                        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.

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by
                        #11

                        @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
                        

                        Read and abide by the Qt Code of Conduct

                        1 Reply Last reply
                        2
                        • mzimmersM Offline
                          mzimmersM Offline
                          mzimmers
                          wrote on last edited by mzimmers
                          #12

                          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...

                          kshegunovK 1 Reply Last reply
                          0
                          • mzimmersM mzimmers

                            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...

                            kshegunovK Offline
                            kshegunovK Offline
                            kshegunov
                            Moderators
                            wrote on last edited by
                            #13

                            @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.

                            Read and abide by the Qt Code of Conduct

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved