Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [Solved] Linker Error

[Solved] Linker Error

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
19 Posts 4 Posters 6.3k Views 1 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.
  • C Charon117

    @Christian-Ehrlicher said in Linker Error:

    @Charon117 said in Linker Error:

    Is there something else i can provide to troubleshoot this ?

    Post the correct error message and the compiler you use.

    C:\Users\Name\Desktop\Neuer Ordner\build-SoftwareKursC-Desktop_Qt_5_15_2_MinGW_64_bit-Debug..\SoftwareKursC\main.c:114: error: undefined reference to ExercisesWeek2' debug/main.o: In function main':
    C:\Users\Name\Desktop\Neuer Ordner\build-SoftwareKursC-Desktop_Qt_5_15_2_MinGW_64_bit-Debug/../SoftwareKursC/main.c:114: undefined reference to `ExercisesWeek2'

    ExercisesWeek2() is the first function that is called in main.

    Compiler is MingW 64 bit, version 7.3 i believe.!

    Unbenannt6.png

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #9

    @Charon117 said in Linker Error:

    ExercisesWeek2() is the first function that is called in main.

    And where is it defined? As the error messages says linker can't find its definition. Means: you either did not implement ExercisesWeek2, or you do not link the lib/object file containing ExercisesWeek2.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    C 1 Reply Last reply
    0
    • jsulmJ jsulm

      @Charon117 said in Linker Error:

      ExercisesWeek2() is the first function that is called in main.

      And where is it defined? As the error messages says linker can't find its definition. Means: you either did not implement ExercisesWeek2, or you do not link the lib/object file containing ExercisesWeek2.

      C Offline
      C Offline
      Charon117
      wrote on last edited by
      #10

      @jsulm said in Linker Error:

      @Charon117 said in Linker Error:

      ExercisesWeek2() is the first function that is called in main.

      And where is it defined? As the error messages says linker can't find its definition. Means: you either did not implement ExercisesWeek2, or you do not link the lib/object file containing ExercisesWeek2.

      The question clarifies that replacing the header file *.h with the appropriate *.c files works. This is the content of the header file:

      #ifndef SOFTWAREKURSC_H
      #define SOFTWAREKURSC_H

      void Rechteck(void);
      int ExercisesWeek1(void);
      int ExercisesWeek2(void);

      #endif // SOFTWAREKURSC_H

      and Christian Ehrlicher already said that it compiles for him on his system and that the pro file is correct.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Charon117
        wrote on last edited by
        #11

        OK, so i am convinced by now that this is a compiler error, because MingW seems to generate the other *.o objects in %TEMP%, wherever that is. If that is correct, how do i point the Qt Creator to check for %TEMP% ? Also, im not convinced that the object files are actually named correctly ?

        So i am not even sure if the compiler generates the object files, where they are, how they are named and how to tell Qt Creator where to find them.

        jsulmJ 1 Reply Last reply
        0
        • C Charon117

          OK, so i am convinced by now that this is a compiler error, because MingW seems to generate the other *.o objects in %TEMP%, wherever that is. If that is correct, how do i point the Qt Creator to check for %TEMP% ? Also, im not convinced that the object files are actually named correctly ?

          So i am not even sure if the compiler generates the object files, where they are, how they are named and how to tell Qt Creator where to find them.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #12

          @Charon117 said in Linker Error:

          i am convinced by now that this is a compiler error

          "undefined reference to" - is a linker error.

          Please post the pro file and the whole build log of a complete rebuild.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          C 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Charon117 said in Linker Error:

            i am convinced by now that this is a compiler error

            "undefined reference to" - is a linker error.

            Please post the pro file and the whole build log of a complete rebuild.

            C Offline
            C Offline
            Charon117
            wrote on last edited by
            #13

            @jsulm said in Linker Error:

            @Charon117 said in Linker Error:

            i am convinced by now that this is a compiler error

            "undefined reference to" - is a linker error.

            Please post the pro file and the whole build log of a complete rebuild.

            the drive link i posted contains the whole project. Can you see it ?

            I dont know what the whole build log is, or where to find it, but i posted a picture here

            Unbenannt6.png

            jsulmJ 1 Reply Last reply
            0
            • C Charon117

              @jsulm said in Linker Error:

              @Charon117 said in Linker Error:

              i am convinced by now that this is a compiler error

              "undefined reference to" - is a linker error.

              Please post the pro file and the whole build log of a complete rebuild.

              the drive link i posted contains the whole project. Can you see it ?

              I dont know what the whole build log is, or where to find it, but i posted a picture here

              Unbenannt6.png

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #14

              @Charon117 said in Linker Error:

              the drive link i posted contains the whole project

              I can't access it. pro file is just text, easy to post here...
              Build log: all compiler and linker calls during the build. In QtCreator see "4 Compile Output" tab at the bottom.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              C 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Charon117 said in Linker Error:

                the drive link i posted contains the whole project

                I can't access it. pro file is just text, easy to post here...
                Build log: all compiler and linker calls during the build. In QtCreator see "4 Compile Output" tab at the bottom.

                C Offline
                C Offline
                Charon117
                wrote on last edited by
                #15

                @jsulm said in Linker Error:

                @Charon117 said in Linker Error:

                the drive link i posted contains the whole project

                I can't access it. pro file is just text, easy to post here...
                Build log: all compiler and linker calls during the build. In QtCreator see "4 Compile Output" tab at the bottom.

                Why cant you access it ?

                SoftwareKursC.pro:
                TEMPLATE = app
                CONFIG += console
                CONFIG -= app_bundle
                CONFIG -= qt

                INCLUDEPATH +=
                %TEMP%

                SOURCES +=
                ExercisesWeek1.c
                ExercisesWeek2.c
                Rechteck.c
                main.c

                HEADERS +=
                SoftwareKursC.h

                Tab4 output:
                15:10:25: Running steps for project SoftwareKursC...
                15:10:25: Configuration unchanged, skipping qmake step.
                15:10:25: Starting: "C:\Coding\Qt\Tools\mingw810_64\bin\mingw32-make.exe" -j4
                C:/Coding/Qt/Tools/mingw810_64/bin/mingw32-make -f Makefile.Debug
                mingw32-make[1]: Entering directory 'C:/Users/Name/Desktop/Neuer Ordner/build-SoftwareKursC-Desktop_Qt_5_15_2_MinGW_64_bit-Debug'
                gcc -c -fno-keep-inline-dllexport -g -Wall -Wextra -Wextra -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_QML_DEBUG -I..\SoftwareKursC -I. -I%TEMP% -IC:\Coding\Qt\5.15.2\mingw81_64\mkspecs\win32-g++ -o debug\main.o ..\SoftwareKursC\main.c
                ..\SoftwareKursC\main.c: In function 'inputSales':
                ..\SoftwareKursC\main.c:18:25: warning: unused parameter 'ABC' [-Wunused-parameter]
                void inputSales(double* ABC){
                ^
                ..\SoftwareKursC\main.c: In function 'readText':
                ..\SoftwareKursC\main.c:106:9: warning: unused variable 'symbol' [-Wunused-variable]
                int symbol = getchar();
                ^
                ~
                ..\SoftwareKursC\main.c:104:20: warning: unused parameter 'smallLettersCount' [-Wunused-parameter]
                void readText(int *smallLettersCount, int *capitalLettersCount, int *whiteSpaceCount){
                ~^
                ~~~~~~~~~~
                ..\SoftwareKursC\main.c:104:44: warning: unused parameter 'capitalLettersCount' [-Wunused-parameter]
                void readText(int *smallLettersCount, int *capitalLettersCount, int *whiteSpaceCount){
                ~^~~~~~~~~~~~~~~
                ..\SoftwareKursC\main.c:104:70: warning: unused parameter 'whiteSpaceCount' [-Wunused-parameter]
                void readText(int *smallLettersCount, int *capitalLettersCount, int *whiteSpaceCount){
                ~^~~~~~~~~~~
                ..\SoftwareKursC\main.c: In function 'main':
                ..\SoftwareKursC\main.c:136:19: warning: format '%ld' expects a matching 'long int' argument [-Wformat=]
                printf("%ld" );
                ^
                ..\SoftwareKursC\main.c:136:19: warning: format '%ld' expects a matching 'long int' argument [-Wformat=]
                ..\SoftwareKursC\main.c: In function 'Exercise':
                ..\SoftwareKursC\main.c:74:5: warning: 'i' is used uninitialized in this function [-Wuninitialized]
                for(int i; i < count;){
                ^

                g++ -Wl,-subsystem,console -mthreads -o debug\SoftwareKursC.exe debug/main.o
                debug/main.o: In function main': C:\Users\\Desktop\Neuer Ordner\build-SoftwareKursC-Desktop_Qt_5_15_2_MinGW_64_bit-Debug/../SoftwareKursC/main.c:114: undefined reference to ExercisesWeek2'
                C:\Users\Name\Desktop\Neuer Ordner\build-SoftwareKursC-Desktop_Qt_5_15_2_MinGW_64_bit-Debug/../SoftwareKursC/main.c:116: undefined reference to `ExercisesWeek1'
                collect2.exe: error: ld returned 1 exit status
                mingw32-make[1]: *** [Makefile.Debug:68: debug/SoftwareKursC.exe] Error 1
                mingw32-make[1]: Leaving directory 'C:/Users/Name/Desktop/Neuer Ordner/build-SoftwareKursC-Desktop_Qt_5_15_2_MinGW_64_bit-Debug'
                mingw32-make: *** [Makefile:45: debug] Error 2
                15:10:26: The process "C:\Coding\Qt\Tools\mingw810_64\bin\mingw32-make.exe" exited with code 2.
                Error while building/deploying project SoftwareKursC (kit: Desktop Qt 5.15.2 MinGW 64-bit)
                When executing step "Make"
                15:10:26: Elapsed time: 00:01.

                jsulmJ 1 Reply Last reply
                0
                • C Charon117

                  @jsulm said in Linker Error:

                  @Charon117 said in Linker Error:

                  the drive link i posted contains the whole project

                  I can't access it. pro file is just text, easy to post here...
                  Build log: all compiler and linker calls during the build. In QtCreator see "4 Compile Output" tab at the bottom.

                  Why cant you access it ?

                  SoftwareKursC.pro:
                  TEMPLATE = app
                  CONFIG += console
                  CONFIG -= app_bundle
                  CONFIG -= qt

                  INCLUDEPATH +=
                  %TEMP%

                  SOURCES +=
                  ExercisesWeek1.c
                  ExercisesWeek2.c
                  Rechteck.c
                  main.c

                  HEADERS +=
                  SoftwareKursC.h

                  Tab4 output:
                  15:10:25: Running steps for project SoftwareKursC...
                  15:10:25: Configuration unchanged, skipping qmake step.
                  15:10:25: Starting: "C:\Coding\Qt\Tools\mingw810_64\bin\mingw32-make.exe" -j4
                  C:/Coding/Qt/Tools/mingw810_64/bin/mingw32-make -f Makefile.Debug
                  mingw32-make[1]: Entering directory 'C:/Users/Name/Desktop/Neuer Ordner/build-SoftwareKursC-Desktop_Qt_5_15_2_MinGW_64_bit-Debug'
                  gcc -c -fno-keep-inline-dllexport -g -Wall -Wextra -Wextra -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_QML_DEBUG -I..\SoftwareKursC -I. -I%TEMP% -IC:\Coding\Qt\5.15.2\mingw81_64\mkspecs\win32-g++ -o debug\main.o ..\SoftwareKursC\main.c
                  ..\SoftwareKursC\main.c: In function 'inputSales':
                  ..\SoftwareKursC\main.c:18:25: warning: unused parameter 'ABC' [-Wunused-parameter]
                  void inputSales(double* ABC){
                  ^
                  ..\SoftwareKursC\main.c: In function 'readText':
                  ..\SoftwareKursC\main.c:106:9: warning: unused variable 'symbol' [-Wunused-variable]
                  int symbol = getchar();
                  ^
                  ~
                  ..\SoftwareKursC\main.c:104:20: warning: unused parameter 'smallLettersCount' [-Wunused-parameter]
                  void readText(int *smallLettersCount, int *capitalLettersCount, int *whiteSpaceCount){
                  ~^
                  ~~~~~~~~~~
                  ..\SoftwareKursC\main.c:104:44: warning: unused parameter 'capitalLettersCount' [-Wunused-parameter]
                  void readText(int *smallLettersCount, int *capitalLettersCount, int *whiteSpaceCount){
                  ~^~~~~~~~~~~~~~~
                  ..\SoftwareKursC\main.c:104:70: warning: unused parameter 'whiteSpaceCount' [-Wunused-parameter]
                  void readText(int *smallLettersCount, int *capitalLettersCount, int *whiteSpaceCount){
                  ~^~~~~~~~~~~
                  ..\SoftwareKursC\main.c: In function 'main':
                  ..\SoftwareKursC\main.c:136:19: warning: format '%ld' expects a matching 'long int' argument [-Wformat=]
                  printf("%ld" );
                  ^
                  ..\SoftwareKursC\main.c:136:19: warning: format '%ld' expects a matching 'long int' argument [-Wformat=]
                  ..\SoftwareKursC\main.c: In function 'Exercise':
                  ..\SoftwareKursC\main.c:74:5: warning: 'i' is used uninitialized in this function [-Wuninitialized]
                  for(int i; i < count;){
                  ^

                  g++ -Wl,-subsystem,console -mthreads -o debug\SoftwareKursC.exe debug/main.o
                  debug/main.o: In function main': C:\Users\\Desktop\Neuer Ordner\build-SoftwareKursC-Desktop_Qt_5_15_2_MinGW_64_bit-Debug/../SoftwareKursC/main.c:114: undefined reference to ExercisesWeek2'
                  C:\Users\Name\Desktop\Neuer Ordner\build-SoftwareKursC-Desktop_Qt_5_15_2_MinGW_64_bit-Debug/../SoftwareKursC/main.c:116: undefined reference to `ExercisesWeek1'
                  collect2.exe: error: ld returned 1 exit status
                  mingw32-make[1]: *** [Makefile.Debug:68: debug/SoftwareKursC.exe] Error 1
                  mingw32-make[1]: Leaving directory 'C:/Users/Name/Desktop/Neuer Ordner/build-SoftwareKursC-Desktop_Qt_5_15_2_MinGW_64_bit-Debug'
                  mingw32-make: *** [Makefile:45: debug] Error 2
                  15:10:26: The process "C:\Coding\Qt\Tools\mingw810_64\bin\mingw32-make.exe" exited with code 2.
                  Error while building/deploying project SoftwareKursC (kit: Desktop Qt 5.15.2 MinGW 64-bit)
                  When executing step "Make"
                  15:10:26: Elapsed time: 00:01.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #16

                  @Charon117 said in Linker Error:

                  INCLUDEPATH +=
                  %TEMP%

                  Remove these two lines.

                  For some reason only main.c file is built. Did you try a complete rebuild:

                  • Delete build folder
                  • Run qmake
                  • Build

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  C 1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mchinand
                    wrote on last edited by
                    #17

                    You have to escape (add a backslash, \) the newlines so the list of source files will be treated as a single input line. See the SOURCES example here: https://doc.qt.io/qt-5/qmake-project-files.html#variables

                    Christian EhrlicherC 1 Reply Last reply
                    0
                    • M mchinand

                      You have to escape (add a backslash, \) the newlines so the list of source files will be treated as a single input line. See the SOURCES example here: https://doc.qt.io/qt-5/qmake-project-files.html#variables

                      Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #18

                      I really wonder why you upload a project but then don't use the pro-file which is in there which is correct...

                      TEMPLATE = app
                      CONFIG += console
                      CONFIG -= app_bundle
                      CONFIG -= qt
                      
                      SOURCES += \
                              ExercisesWeek1.c \
                              ExercisesWeek2.c \
                              Rechteck.c \
                              main.c
                      
                      HEADERS += \
                          SoftwareKursC.h
                      

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @Charon117 said in Linker Error:

                        INCLUDEPATH +=
                        %TEMP%

                        Remove these two lines.

                        For some reason only main.c file is built. Did you try a complete rebuild:

                        • Delete build folder
                        • Run qmake
                        • Build
                        C Offline
                        C Offline
                        Charon117
                        wrote on last edited by
                        #19

                        @jsulm said in Linker Error:

                        @Charon117 said in Linker Error:

                        INCLUDEPATH +=
                        %TEMP%

                        Remove these two lines.

                        For some reason only main.c file is built. Did you try a complete rebuild:

                        • Delete build folder
                        • Run qmake
                        • Build

                        Ok, so the weirdest thing happened. It works now.

                        No clue how that happened, or what i did to change it. But ... lol ... check this out.

                        I delete the whole build folder, eg.
                        build-SoftwareKursC-Desktop_Qt_5_15_2_MinGW_64_bit-Debug

                        Then i compile with Qt Creator, and i only use #include *.c files. Then i comment out the *.c includes and enable the *.h includes. This leads us to exactly the error i described.

                        Another delete later:
                        I compile this time with *.h files and then change them to *.c files. I get a completely different linker error, but a linker error nonetheless.

                        Another delete:
                        I only compile with *.h includes and it works. No changing afterwards.

                        Another delete:
                        I only compile with *.c includes and it works. No changing afterwards.

                        Conclusion:
                        Changing compilation from *.h to *.c includes leads to linker errors, as well as changes from *.c to *.h includes. Deleting the build folder in both cases is the solution.

                        What kind of clusterfucking mindblowing error is this ?

                        Thanks for the help, i guess i will mark this as solved. Thanks to @jsulm for suggesting the correct solution. I will make a note that in case of mysterious bugs deleting the build folder is priority number one. If somebody has an explanation of why this is happening they can add it as another post.

                        Thank you all for participating in this discussion.

                        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