未定义的引用.在 cmake 中:lib 到 lib [英] Undefined reference to. In cmake: lib to lib

查看:63
本文介绍了未定义的引用.在 cmake 中:lib 到 lib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 7 x86,cmake 版本 3.15.2、4.10 qtcreator、Qt5.12.4 MinGW.我用两个库构建了一个项目,在其中一个库中,我从另一个调用了一个类.结果,我得到了一个错误.

Windows 7 x86, cmake version 3.15.2, 4.10 qtcreator, Qt5.12.4 MinGW. I build a project with two libraries, and in one of them I call a class from the other. As a result, I get an error.

...file2.cpp:-1: ошибка: undefined reference to `MyClass1::MyClass1()'
collect2.exe:-1: ошибка: error: ld returned 1 exit status

[ 91%] Linking CXX executable flasher.exe
lib2/liblib2.a(file2.cpp.obj):file2.cpp:(.text+0x18): undefined reference to `MyClass1::MyClass1()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [CMakeFiles\my.dir\build.make:107: flasher.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:83: CMakeFiles/my.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2

最小可重现示例:githab.com Src.

推荐答案

链接器无法解析 myclass1 的构造函数.这可能意味着没有定义或您没有链接库.确保您有构造函数的函数体,并且给定的库文件已链接.

The Linker can not resolve the constructor for myclass1. This could mean no definition or you did not Link the library. Make sure you have a function body for the constructor and that the given library file is linked.

这篇关于未定义的引用.在 cmake 中:lib 到 lib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆