问题描述
正在一切就绪的时候发现好多的错误,刚开始以为是没有引用头文件目录找不到,然而在看到 pro 中对引用后就知道不是这个问题。
奇怪的是在 Windows 下编译运行也是正常的,按照这种逻辑想下去完全没有头绪。
D:\software\Java\sdk\ndk\21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++ -target armv7a-linux-androideabi21 -fno-limit-debug-info -Wl,-rpath,'$ORIGIN' -Wl,--build-id=sha1 -Wl,--no-undefined -Wl,-z,noexecstack -shared -Wl,-soname,libmachine_armeabi-v7a.so -o libmachine_armeabi-v7a.so @..\..\..\winupcnc\output_android\debug\tmp\obj\machine\object_script..Armeabi-v7a -LE:/winupcnc/cncbase/global/../../output_android/debug/bin/ -lupcore_armeabi-v7a D:/software/Qt/5.15.2/android/lib/libQt5Widgets_armeabi-v7a.so D:/software/Qt/5.15.2/android/lib/libQt5Gui_armeabi-v7a.so D:/software/Qt/5.15.2/android/lib/libQt5Sql_armeabi-v7a.so D:/software/Qt/5.15.2/android/lib/libQt5Core_armeabi-v7a.so -lGLESv2 -llog -lz -lm -ldl -lc
..\..\..\winupcnc\cncmachine\machine\src/machinec53.cpp:27: error: undefined reference to 'IMachine::~IMachine()'
..\..\..\winupcnc\cncmachine\machine\src/machinec53.cpp:27: error: undefined reference to 'IMachine::~IMachine()'
..\..\..\winupcnc\cncmachine\machine\src/machinec53.cpp:35: error: undefined reference to 'IMachine::~IMachine()'
..\..\..\winupcnc\cncmachine\machine\src/machinec53.cpp:35: error: undefined reference to 'IMachine::~IMachine()'
..\..\..\winupcnc\cncmachine\machine\include/IMachine.h:0: error: undefined reference to 'vtable for IMachine'
D:\software\Java\sdk\ndk\21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: the vtable symbol may be undefined because the class is missing its key function
../../../winupcnc/output_android/debug/tmp/obj/machine/machinec53.obj:machinec53.cpp:typeinfo for MachineC53: error: undefined reference to 'typeinfo for IMachine'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [Makefile:160: ..\..\..\winupcnc\output_android\debug\bin\libmachine_armeabi-v7a.so] Error 1
make[1]: Leaving directory 'E:/build-winupcnc-Android_Qt_5_15_2_Clang_Multi_Abi-Debug/cncmachine/machine'
make: *** [Makefile:533: sub-cncmachine-machine-make_first-ordered] Error 2
14:06:01: 进程"D:\software\Java\sdk\ndk\21.3.6528147\prebuilt\windows-x86_64\bin\make.exe"退出,退出代码 2 。
Error while building/deploying project winupcnc (kit: Android Qt 5.15.2 Clang Multi-Abi)
解决方案
正在我一筹莫展的时候,领导发现了问题所在,原来 IMachine 这个类作为一个接口类,居然有一个 IMahine.cpp 文件,而该文件中只存在一个析构函数的实现,再无其他内容。
- 直接删除 IMahine.cpp 文件。
- 修改 machine.pro 中将 IMahine.cpp 从 SOURCES 中去掉。
- 将 IMahine.h 中析构函数加上 {}。