c++ - 添加了对 .lib 项目的引用 - 项目不使用 .cpp 文件?

标签 c++ visual-studio reference static-libraries

我对 C++ 还是相当陌生,所以如果我误解了什么,请原谅我。

我有一个包含 sql 连接类的 C++ 库,我想在项目中使用它。我有:

  • 将其添加到同一个解决方案中
  • 在“框架和引用”中添加了对它的引用
  • 包含在主工程的stdafx.cpp中的库的头文件中
  • 将库项目的目录作为包含目录添加到主项目

但是在编译项目时,我仍然遇到一些unresolved external symbol错误。

如果我包含库项目的 *.cpp 文件,它工作正常,但我认为您不必这样做。


这些是我得到的确切错误:

2>Link:
2>  sqlConnector.obj : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
2>     Creating library .\Release\MainProject.lib and object .\Release\MainProject.exp
2>LINK : warning LNK4098: defaultlib 'mfc100u.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
2>LINK : warning LNK4098: defaultlib 'mfcs100u.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
2>MainProject.obj : error LNK2001: unresolved external symbol "public: bool __thiscall SQLQuery::AddParameter(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > >)" (?AddParameter@SQLQuery@@QAE_NV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z)
2>MainProject.obj : error LNK2001: unresolved external symbol "public: void __thiscall SQLQuery::SetQuery(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > >)" (?SetQuery@SQLQuery@@QAEXV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z)
2>MainProject.obj : error LNK2001: unresolved external symbol "public: bool __thiscall SQLQuery::Open(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > >)" (?Open@SQLQuery@@QAE_NV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z)
2>MainProject.obj : error LNK2001: unresolved external symbol "public: void __thiscall SQLQuery::SetConnectionString(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > >)" (?SetConnectionString@SQLQuery@@QAEXV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z)
2>sqlConnector.obj : error LNK2001: unresolved external symbol "public: void __thiscall CAMTrace::SetEXEName(wchar_t const *)" (?SetEXEName@CAMTrace@@QAEXPB_W@Z)
2>sqlConnector.obj : error LNK2001: unresolved external symbol "public: void __thiscall CAMTrace::Trace(wchar_t const *,int,int)" (?Trace@CAMTrace@@QAEXPB_WHH@Z)
2>.\Release\MainProject.exe : fatal error LNK1120: 6 unresolved externals

最佳答案

您需要做的是将库二进制文件(*.lib)添加到项目的链接器输入中。

为了做到这一点,您需要指定在哪里查找文件,该文件是

下的一个条目

链接器/通用/附加库目录

然后将库添加到

下的链接器输入

链接器/输入/附加依赖项

关于c++ - 添加了对 .lib 项目的引用 - 项目不使用 .cpp 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20677788/

相关文章:

c++ - extern"C"与 extern 的区别

c++ - 何时在 C++11 中使类型不可 move ?

c++ - 使用 Visual Studio 2005 在 C++ 中绘图

sql - 警告 SQL71502 - 过程 <名称> 具有对对象 <名称> 的未解析引用

pointers - 范围引用而不是值

c# - 如何将 "reference"分配给 C# 中的类字段?

perl - 如何反转数组引用并将其存储在 Perl 中的另一个数组引用中?

c++ - 使用自定义模式序列化和使用 Boost 随机访问

c++ - 将高阶贝塞尔曲线拆分为多条三次曲线

c# - 设计架构,分离项目。我是 "over thinking"吗?