Qt错误:LNK1120:1个未解决的外部 main.obj:-1:错误:LNK2019 运行Qmake

3
我无法弄清楚为什么会出现以下错误: main.obj:-1: 错误:LNK2019: 无法解析的外部符号 "public: __thiscall Standbywindow::Standbywindow(void)" (??0Standbywindow@@QAE@XZ),该符号在函数 _main 中被引用 和 debug\pointer_test.exe:-1: 错误:LNK1120: 1 个无法解析的外部命令
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

编译输出

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.

你是否将 standby.cpp 添加到可编译文件列表中了? - vsoftco
@Mike 请问 standby.cpp 已经编译了吗?然后 standby.o 是否已经被包含在链接器输入中了呢? - Rudolfs Bundulis
vsoftco 我不确定如何回答这个问题。我应该在哪里查找? - Mike
Rudolfs Bundulis 再次道歉,不确定在哪里可以找到这个。 - Mike
似乎您使用QtCreator作为集成开发环境(IDE),并且使用MSVC作为编译器,不使用MSVC作为IDE有什么特别的原因吗?这可能会解决您的问题,因为项目生成可能对您的特定设置不正确。 - m.s.
1个回答

3

请确保standby.cpp在您的.pro文件中列为源文件,然后尝试再次运行QMake(构建 -> 运行 qmake),然后尝试进行编译。您还可以尝试清理/重建您的项目。


我在 standby.cpp 上面添加了我的 pro 文件。 - Mike
抱歉,我发帖后才看到。你尝试重新运行QMake了吗?即使所有源文件都在.pro文件中,构建之前仍需要更新makefile。 - Carlton
当我运行clean时出现错误。找不到[path] main.obj,pointer_test.exp,pointer_test.exp,pointer_test.ilk,pointer_test.idb。 - Mike
1
我无法告诉你我为此浪费了多少时间去追踪晦涩的链接器错误。如果Qt Creator在尝试构建而没有更新QMake时警告你,那将是很好的。 - Carlton
我也遇到了这个问题,我以为点击“重建”也会触发qmake,但实际上并没有。 - Emmanuel Oga
Qt Creator在添加新类后不会自动重新运行qmake?什么鬼? - zwcloud

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接