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

Added reference to .lib project - project not using .cpp file?

本文关键字:项目 文件 cpp 引用 lib 添加      更新时间:2023-10-16

我对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 .ReleaseMainProject.lib and object .ReleaseMainProject.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>.ReleaseMainProject.exe : fatal error LNK1120: 6 unresolved externals
您需要

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

为此,您需要指定在何处查找文件,该文件是下的一个条目

链接器/常规/附加库目录

之后,您将库添加到链接器输入下

链接器/输入/其他依赖项