我对 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/