3

I can not figure out why I am getting the errors: main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall Standbywindow::Standbywindow(void)" (??0Standbywindow@@QAE@XZ) referenced in function _main and debug\pointer_test.exe:-1: error: LNK1120: 1 unresolved externals

Main.cpp

  #include <QCoreApplication>
  #include <QDebug>
  #include "standby.h"

  Standbywindow *standby_window;

  int main(int argc, char *argv[])
  {
  QCoreApplication a(argc, argv);
     standby_window = new Standbywindow;
  return a.exec();
  }

standby.h

 #ifndef STANDBY_H
 #define STANDBY_H
 #include <QDebug>
 class Standbywindow{
 public:
 Standbywindow();
 };

 #endif // STANDBY_H

standby.cpp

#include "standby.h"
Standbywindow::Standbywindow(){
}

pointer_test.pro

  #-------------------------------------------------
  #
  # Project created by QtCreator 2015-05-10T11:08:06
  #
  #-------------------------------------------------

  QT       += core

  QT       -= gui

  TARGET = pointer_test
  CONFIG   += console
  CONFIG   -= app_bundle

  TEMPLATE = app


  SOURCES += main.cpp \
     standby.cpp

  HEADERS += \
     standby.h

compile output

09:08:23: Running steps for project pointer_test...
09:08:23: Configuration unchanged, skipping qmake step.
09:08:23: Starting: "C:\Qt\Tools\QtCreator\bin\jom.exe" 
C:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Debug  
cl -c -nologo -Zm200 -Zc:wchar_t -Zi -MDd -GR -W3 -w34100 -w34189 -EHsc        /Fddebug\pointer_test.pdb -DUNICODE -DWIN32 -DQT_CORE_LIB -I"..\pointer_test" -         I"."  -I"C:\Qt\5.4\msvc2010_opengl\include" -I"C:\Qt\5.4\msvc2010_opengl\include\QtCore" -I"debug" -I"C:\Qt\5.4\msvc2010_opengl\mkspecs\win32-msvc2010" -Fodebug\ @C:\Users\Mike\AppData\Local\Temp\main.obj.10328.16.jom
   main.cpp
   echo 1 /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ "debug\\pointer_test.exe.embed.manifest">debug\pointer_test.exe_manifest.rc
   if not exist debug\pointer_test.exe if exist   debug\pointer_test.exe.embed.manifest del debug\pointer_test.exe.embed.manifest
     if exist debug\pointer_test.exe.embed.manifest copy /Y debug\pointer_test.exe.embed.manifest debug\pointer_test.exe_manifest.bak
     link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32'      name='Microsoft.Windows.Common-Controls' version='6.0.0.0'      publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST /MANIFESTFILE:debug\pointer_test.exe.embed.manifest /OUT:debug\pointer_test.exe @C:\Users\Mike\AppData\Local\Temp\pointer_test.exe.10328.2250.jom
    main.obj : error LNK2019: unresolved external symbol "public: __thiscall Standbywindow::Standbywindow(void)" (??0Standbywindow@@QAE@XZ) referenced in      function _main
    debug\pointer_test.exe : fatal error LNK1120: 1 unresolved externals
     jom: C:\Users\Mike\Documents\QT\build-pointer_test-  Desktop_Qt_5_4_1_MSVC2010_OpenGL_32bit-Debug\Makefile.Debug [debug\pointer_test.exe] Error 1120
   jom: C:\Users\Mike\Documents\QT\build-pointer_test-  Desktop_Qt_5_4_1_MSVC2010_OpenGL_32bit-Debug\Makefile [debug] Error 2
 09:08:26: The process "C:\Qt\Tools\QtCreator\bin\jom.exe" exited with code 2.
 Error while building/deploying project pointer_test (kit: Desktop Qt 5.4.1 MSVC2010 OpenGL 32bit)
 When executing step "Make"
 09:08:26: Elapsed time: 00:03.
Mike
  • 33
  • 1
  • 5
  • Did you add `standby.cpp` to your list of compilable files? – vsoftco May 11 '15 at 13:26
  • @Mike is the standby.cpp compiled and then standby.o included in the linker inputs? – Rudolfs Bundulis May 11 '15 at 13:26
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – NathanOliver May 11 '15 at 13:36
  • vsoftco I'm not sure how to answer this. Where do I look. – Mike May 11 '15 at 13:43
  • Rudolfs Bundulis agian sorry not sure where to find this. – Mike May 11 '15 at 13:45
  • Seems like you use QtCreator as the IDE and MSVC as compiler, is there a particular reason NOT to use MSVC as the IDE as well? This might solve your problem since it could be that the project generation was not correct for your specific setup. – m.s. May 11 '15 at 14:01

1 Answers1

3

Make sure standby.cpp is listed as a source file in your .pro file, then try running QMake again (build -> run qmake), THEN try to build. You can also try cleaning/rebuilding your project.

Carlton
  • 4,217
  • 2
  • 24
  • 40
  • I added my pro file above standby.cpp is listed. – Mike May 11 '15 at 14:22
  • Yeah, saw that after I posted. Sorry. Did you try re-running QMake though? Even if the source files are all in the .pro file, you still need to update the makefile before building. – Carlton May 11 '15 at 14:24
  • When I run clean it errors. Could not find [path] main.obj,pointer_test.exp,pointer_test.exp,pointer_test.ilk,pointer_test.idb – Mike May 11 '15 at 14:24
  • 1
    I can't tell you how much time I've wasted chasing cryptic linker errors for this reason. It would be nice if Qt Creator warned you when you try to build without updating QMake... – Carlton May 11 '15 at 14:30
  • I was hitting this problem too, I thought that hitting "Rebuild" was gonna trigger a qmake too, but it did not. – Emmanuel Oga Jul 13 '17 at 03:38
  • Qt creator doesn't re-run qmake automatically after a new class was added? WTF – zwcloud Aug 07 '19 at 03:13