c++ - 未定义的成员函数引用

标签 c++ include header undefined-reference

我刚刚以为我解决了a problem ,但似乎又出现了另一个问题——或者至少以另一种形式出现了同样的问题。现在,当我尝试按照该问题的答案中的建议重建所有内容时,所有 Qt Creator 在构建问题中显示的是一行 collect2: ld returned 1 exit status

这是我认为可能相关的一些编译输出:

Running build steps for project Othello-cmd...
Starting: "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" clean -w
[snipped]
C:/Qt/2010.05/mingw/bin/mingw32-make -f Makefile.Release clean

Could Not Find C:\Users\Amos Ng\My Dropbox\School\College\2010.. Fall\CS 3A\Othello-cmd-build-desktop\debug\main.o           //this was in red

mingw32-make[1]: Entering directory `C:/Users/Amos Ng/My Dropbox/School/College/2010.. Fall/CS 3A/Othello-cmd-build-desktop'

del release\main.o release\board.o release\player.o release\referee.o release\misc.o release\humanplayer.o release\computerplayer.o release\chatter.o release\chatserver.o release\location.o
mingw32-make[1]: Leaving directory `C:/Users/Amos Ng/My Dropbox/School/College/2010.. Fall/CS 3A/Othello-cmd-build-desktop'

mingw32-make: Leaving directory `C:/Users/Amos Ng/My Dropbox/School/College/2010.. Fall/CS 3A/Othello-cmd-build-desktop'

Could Not Find C:\Users\Amos Ng\My Dropbox\School\College\2010.. Fall\CS 3A\Othello-cmd-build-desktop\release\main.o

//these next 3 lines are in blue
The process "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" exited normally.
Configuration unchanged, skipping qmake step.
Starting: "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `C:/Users/Amos Ng/My Dropbox/School/College/2010.. Fall/CS 3A/Othello-cmd-build-desktop'
[snipped]
//A bunch of lines similar to
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"c:\Qt\2010.05\qt\include\QtCore" -I"c:\Qt\2010.05\qt\include" -I"c:\Qt\2010.05\qt\include\ActiveQt" -I"debug" -I"\\psf\Dropbox\School\College\2010.. Fall\CS 3A\Othello-cmd" -I"." -I"c: "filepath of .o file" "filepath of .cpp file"

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl -o debug\Othello-cmd.exe object_script.Othello-cmd.Debug  -L"c:\Qt\2010.05\qt\lib" -lQtCored4

 //everything's red starting here...

./debug\board.o://psf/Dropbox/School/College/2010.. Fall/CS 3A/Othello-cmd/board.cpp:29: undefined reference to `OPiece::OPiece(int)'

./debug\board.o://psf/Dropbox/School/College/2010.. Fall/CS 3A/Othello-cmd/board.cpp:39: undefined reference to `OPiece::flip()'

./debug\board.o://psf/Dropbox/School/College/2010.. Fall/CS 3A/Othello-cmd/board.cpp:76: undefined reference to `OPiece::display()'

./debug\board.o://psf/Dropbox/School/College/2010.. Fall/CS 3A/Othello-cmd/board.cpp:110: undefined reference to `OPiece::display()'

./debug\board.o://psf/Dropbox/School/College/2010.. Fall/CS 3A/Othello-cmd/board.cpp:159: undefined reference to `OPiece::OPiece(int)'

//couple more lines just like the above

collect2: ld returned 1 exit status

//...finally things are black again

mingw32-make[1]: Leaving directory `C:/Users/Amos Ng/My Dropbox/School/College/2010.. Fall/CS 3A/Othello-cmd-build-desktop'

mingw32-make: Leaving directory `C:/Users/Amos Ng/My Dropbox/School/College/2010.. Fall/CS 3A/Othello-cmd-build-desktop'

//everything's red again

mingw32-make[1]: *** [debug\Othello-cmd.exe] Error 1

mingw32-make: *** [debug] Error 2

The process "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project Othello-cmd (target: Desktop)
When executing build step 'Make'

关于可能导致此错误的原因有什么想法吗?

编辑:我还想指出,我确实在调试目录中找到了“main.o”...

解决方案(不是真的):我改为在 Netbeans 中重新编译所有内容(虽然在 Mac 上,所以链接器可能不同......)。现在程序运行正常了……再见Qt Creator

最佳答案

我会试着猜测。您要么使用了错误的 namespace (即将 #include 指令放在 namespace 的主体中)。或者您没有按照建议完全删除 debug 和 release 目录。

关于c++ - 未定义的成员函数引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4057100/

相关文章:

c++ - Qlineedit边界

php - 如何为 PHP 包含文件设置根文件夹

php - 在php脚本内提交后重定向

c++ - 无法在其他类 C++ 之前访问类

c++ - 我的代码的 Boost 更新问题

C++ printf 的奇怪输出

c - 编译时是否可以指定相对于用户当前目录的#include 文件路径?

php - 如何在 php 包含文件中设置 html 内容的样式?

c++ - 重载 = 运算符

c++ - 无效的基类 T 错误