C++ 错误LNK2019:未解析的外部符号,排除了所有典型原因

C++ 错误LNK2019:未解析的外部符号,排除了所有典型原因,c++,visual-studio-2012,linker,linker-errors,project-properties,C++,Visual Studio 2012,Linker,Linker Errors,Project Properties,在我的案例中,这个问题的每一个答案(从我所看到的,这是很多)都得到了解决,我仍然处于僵局。我使用的是遗留代码,必须通过设置一个正确连接的开发环境来破解。使用VS 2012,我有一个包含22个项目的解决方案,其中有一个蜘蛛网(spiderweb)相互依赖。1个项目,phtranscript,依赖于另一个项目的代码,而phtranscript的代码反过来又被第三个项目SpeechRecognitor所需要。以下是相关文件和编译器/链接器输出: 在项目记录中: phc.h: #ifndef _phTr

在我的案例中,这个问题的每一个答案(从我所看到的,这是很多)都得到了解决,我仍然处于僵局。我使用的是遗留代码,必须通过设置一个正确连接的开发环境来破解。使用VS 2012,我有一个包含22个项目的解决方案,其中有一个蜘蛛网(spiderweb)相互依赖。1个项目,phtranscript,依赖于另一个项目的代码,而phtranscript的代码反过来又被第三个项目SpeechRecognitor所需要。以下是相关文件和编译器/链接器输出:

在项目记录中:

phc.h:

#ifndef _phTranscript_h__
#define _phTranscript_h__

#include <vector>
#include <string>
#include <map>
#include "config.h"
#include "character.h"
...
class hunspellMorph{
public:
    static hunspellMorph *instance();
protected:
    hunspellMorph();

private:
    hunspellMorph(const hunspellMorph &);
    hunspellMorph& operator=(const hunspellMorph &);

public:
    ~hunspellMorph();

    void Morph(const std::string &in,std::vector<std::string> &out);

private:
    class impl;
    impl *pImpl_;
};


#endif
hunspell.cxx:

#include "license.hunspell"
#include "license.myspell"

#ifndef MOZILLA_CLIENT
#include <cstdlib>
#include <cstring>
#include <cstdio>
#else
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#endif

#include "hunspell.hxx"
#include "./config.h"
#include "./treeNode.h"
#include "cache.h"

#include <string>
#include <vector>

#ifndef MOZILLA_CLIENT
#ifndef W32
using namespace std;
#endif
#endif

Hunspell::Hunspell(const char * affpath, const char * dpath, const char * key)
{
    ...
}

Hunspell::~Hunspell()
{
    ...
}

int Hunspell::analyze(char ***slst,const char *word,int d){
    ...
}
#包括“许可证.拼写”
#包括“license.myspell”
#ifndef MOZILLA_客户端
#包括
#包括
#包括
#否则
#包括
#包括
#包括
#恩迪夫
#包括“hunspell.hxx”
#包括“/config.h”
#包括“/treeNode.h”
#包括“cache.h”
#包括
#包括
#ifndef MOZILLA_客户端
#IFNDEFW32
使用名称空间std;
#恩迪夫
#恩迪夫
Hunspell::Hunspell(const char*affpath、const char*dpath、const char*key)
{
...
}
Hunspell::~Hunspell()
{
...
}
int Hunspell::analyze(字符***slst,常量字符*单词,int d){
...
}
csutil.cxx:

#include "license.hunspell"
#include "license.myspell"

#ifndef MOZILLA_CLIENT
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#else
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#endif

#include "csutil.hxx"
#include "atypes.hxx"
#include "langnum.hxx"

#ifdef OPENOFFICEORG
#  include <unicode/uchar.h>
#else
#  ifndef MOZILLA_CLIENT
#    include "utf_info.cxx"
#    define UTF_LST_LEN (sizeof(utf_lst) / (sizeof(unicode_info)))
#  endif
#endif

#ifdef MOZILLA_CLIENT
#include "nsCOMPtr.h"
#include "nsServiceManagerUtils.h"
#include "nsIUnicodeEncoder.h"
#include "nsIUnicodeDecoder.h"
#include "nsICaseConversion.h"
#include "nsICharsetConverterManager.h"
#include "nsUnicharUtilCIID.h"
#include "nsUnicharUtils.h"

static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
#endif

#ifdef MOZILLA_CLIENT
#ifdef __SUNPRO_CC // for SunONE Studio compiler
using namespace std;
#endif
#else
#ifndef W32
using namespace std;
#endif
#endif

...

void freelist(char *** list, int n) {
    if (list && (n > 0)) {
        for (int i = 0; i < n; i++) if ((*list)[i]) free((*list)[i]);
        free(*list);
        *list = NULL;
    }
}
#包括“许可证.拼写”
#包括“license.myspell”
#ifndef MOZILLA_客户端
#包括
#包括
#包括
#包括
#否则
#包括
#包括
#包括
#包括
#恩迪夫
#包括“csutil.hxx”
#包括“atypes.hxx”
#包括“langnum.hxx”
#ifdef OPENOFFICEORG
#包括
#否则
#ifndef MOZILLA_客户端
#包括“utf_info.cxx”
#定义UTF_LST_LEN(sizeof(UTF_LST)/(sizeof(unicode_info)))
#恩迪夫
#恩迪夫
#ifdef MOZILLA_客户端
#包括“nsCOMPtr.h”
#包括“NSServiceManagerRutils.h”
#包括“NSIunicoder.h”
#包括“nsidecoder.h”
#包括“nsICaseConversion.h”
#包括“nsICharsetConverterManager.h”
#包括“nsunicharutilcid.h”
#包括“nsUnicharUtils.h”
静态NS_定义_CID(KCharsetConverterManagerId、NS_ICHARSETCONVERTERMANAGER_CID);
静态NS_DEFINE_CID(kUnicharUtilCID,NS_UNICHARUTIL_CID);
#恩迪夫
#ifdef MOZILLA_客户端
#用于SunONE Studio编译器的ifdef\uuu SUNPRO\u CC//
使用名称空间std;
#恩迪夫
#否则
#IFNDEFW32
使用名称空间std;
#恩迪夫
#恩迪夫
...
无效自由列表(字符***列表,整数n){
如果(列表和(n>0)){
对于(inti=0;i
以下是不同项目之间干净构建的输出:

6>------ Build started: Project: hunspell, Configuration: Debug Win32 ------
...
6>  hunspell.vcxproj -> C:\temp\speech\divided_rm_speech_proj\Debug\hunspell.exe
...
10>------ Build started: Project: phtranscript, Configuration: Debug Win32 ------
...
10>  phtranscript.vcxproj -> C:\temp\speech\divided_rm_speech_proj\Debug\phtranscript.exe
...
19>------ Build started: Project: speechRecognizer, Configuration: Debug Win32 ------
...
19>  Generating Code...
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "void __cdecl freelist(char * * *,int)" (?freelist@@YAXPAPAPADH@Z) referenced in function "public: void __thiscall hunspellMorph::impl::Morph(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &)" (?Morph@impl@hunspellMorph@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z)
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::Hunspell(char const *,char const *,char const *)" (??0Hunspell@@QAE@PBD00@Z) referenced in function "public: __thiscall hunspellMorph::impl::impl(void)" (??0impl@hunspellMorph@@QAE@XZ)
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::~Hunspell(void)" (??1Hunspell@@QAE@XZ) referenced in function "public: __thiscall hunspellMorph::impl::~impl(void)" (??1impl@hunspellMorph@@QAE@XZ)
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "public: int __thiscall Hunspell::analyze(char * * *,char const *,int)" (?analyze@Hunspell@@QAEHPAPAPADPBDH@Z) referenced in function "public: void __thiscall hunspellMorph::impl::Morph(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &)" (?Morph@impl@hunspellMorph@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z)
19>C:\temp\speech\divided_rm_speech_proj\Debug\speechRecognizer.exe : fatal error LNK1120: 4 unresolved externals
6>----构建已启动:项目:Hunspill,配置:调试Win32------
...
6> hunspell.vcxproj->C:\temp\speech\divided\u rm\u speech\u proj\Debug\hunspell.exe
...
10> ----构建已启动:项目:phtranscript,配置:调试Win32------
...
10> phtranscript.vcxproj->C:\temp\speech\divided\u rm\u speech\u proj\Debug\phtranscript.exe
...
19> ----构建已启动:项目:SpeechRecognitor,配置:调试Win32------
...
19> 正在生成代码。。。
19> hunspellmorp.obj:错误LNK2019:未解析的外部符号“void u cdecl freelist(char***,int)”(?freelist@@YAXPAPAPADH@Z)函数“public:void _uthiscall hunspellmorp::impl::morp(类std::basic\u字符串常量&,类std::vector&)”中引用(?Morph@impl@hunspellMorph@@QAEXABV?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@AAV$vector@V?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@V$allocator@V?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@@2@@4@@Z)
19> hunspellmorp.obj:错误LNK2019:未解析的外部符号“public:u thiscall Hunspell::Hunspell(char const*,char const*,char const*)”(??0Hunspell@@QAE@PBD00@Z) 在函数“public:u thiscall:impl::impl::impl(void)”中引用(?)??0impl@hunspellMorph@@QAE@XZ)
19> hunspellmorp.obj:错误LNK2019:未解析的外部符号“public:u thiscall Hunspell::~Hunspell(void)”(??1Hunspell)@@QAE@XZ)在函数“public:u thiscall hunspellMorph::impl::~impl(void)”中引用(?)??1impl@hunspellMorph@@QAE@XZ)
19> hunspellmorp.obj:错误LNK2019:未解析的外部符号“public:int u thiscall Hunspell::analyze(char***,char const*,int)”(?analyze@Hunspell@@QAEHPAPAPADPBDH@Z)函数“public:void _uthiscall hunspellmorp::impl::morp(类std::basic\u字符串常量&,类std::vector&)”中引用(?Morph@impl@hunspellMorph@@QAEXABV?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@AAV$vector@V?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@V$allocator@V?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@@2@@4@@Z)
19> C:\temp\speech\divided\u rm\u speech\u proj\Debug\speechRecognizer.exe:致命错误LNK1120:4个未解析的外部
请记住,有很多代码被删除,因此如果缺少一些重要的代码,请告诉我,我将更新此描述

在Visual Studio 2012的环境设置中,phtranscript的项目属性在“公共属性”下建立了一个hunspell引用,“包含目录”字段包括hunspell包含目录,“库目录”字段包括hunspell库输出文件夹(这都在VC++目录下),C/C++附加包含目录也列出了包含目录。由于我得到了“已声明的符号”,所以我没有使用Linker->Input additional libraries字段当我同时指定了链接器和VC++目录时,链接器出现错误。在“项目依赖项”下,我检查hunspell并确保它在生成顺序中位于phtranscript之前。最后,我手动添加了现有hunspell库(在编译它们之后)在speechrecognizer项目中,我采取了与phtranscript项目依赖项对应的相同步骤

代码在我看来简直是一场噩梦。修复这个问题所需的最小更改量是多少?最好只是在IDE端更改/添加一些东西,而不是代码更改(altho
#include "license.hunspell"
#include "license.myspell"

#ifndef MOZILLA_CLIENT
#include <cstdlib>
#include <cstring>
#include <cstdio>
#else
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#endif

#include "hunspell.hxx"
#include "./config.h"
#include "./treeNode.h"
#include "cache.h"

#include <string>
#include <vector>

#ifndef MOZILLA_CLIENT
#ifndef W32
using namespace std;
#endif
#endif

Hunspell::Hunspell(const char * affpath, const char * dpath, const char * key)
{
    ...
}

Hunspell::~Hunspell()
{
    ...
}

int Hunspell::analyze(char ***slst,const char *word,int d){
    ...
}
#include "license.hunspell"
#include "license.myspell"

#ifndef MOZILLA_CLIENT
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#else
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#endif

#include "csutil.hxx"
#include "atypes.hxx"
#include "langnum.hxx"

#ifdef OPENOFFICEORG
#  include <unicode/uchar.h>
#else
#  ifndef MOZILLA_CLIENT
#    include "utf_info.cxx"
#    define UTF_LST_LEN (sizeof(utf_lst) / (sizeof(unicode_info)))
#  endif
#endif

#ifdef MOZILLA_CLIENT
#include "nsCOMPtr.h"
#include "nsServiceManagerUtils.h"
#include "nsIUnicodeEncoder.h"
#include "nsIUnicodeDecoder.h"
#include "nsICaseConversion.h"
#include "nsICharsetConverterManager.h"
#include "nsUnicharUtilCIID.h"
#include "nsUnicharUtils.h"

static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
#endif

#ifdef MOZILLA_CLIENT
#ifdef __SUNPRO_CC // for SunONE Studio compiler
using namespace std;
#endif
#else
#ifndef W32
using namespace std;
#endif
#endif

...

void freelist(char *** list, int n) {
    if (list && (n > 0)) {
        for (int i = 0; i < n; i++) if ((*list)[i]) free((*list)[i]);
        free(*list);
        *list = NULL;
    }
}
6>------ Build started: Project: hunspell, Configuration: Debug Win32 ------
...
6>  hunspell.vcxproj -> C:\temp\speech\divided_rm_speech_proj\Debug\hunspell.exe
...
10>------ Build started: Project: phtranscript, Configuration: Debug Win32 ------
...
10>  phtranscript.vcxproj -> C:\temp\speech\divided_rm_speech_proj\Debug\phtranscript.exe
...
19>------ Build started: Project: speechRecognizer, Configuration: Debug Win32 ------
...
19>  Generating Code...
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "void __cdecl freelist(char * * *,int)" (?freelist@@YAXPAPAPADH@Z) referenced in function "public: void __thiscall hunspellMorph::impl::Morph(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &)" (?Morph@impl@hunspellMorph@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z)
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::Hunspell(char const *,char const *,char const *)" (??0Hunspell@@QAE@PBD00@Z) referenced in function "public: __thiscall hunspellMorph::impl::impl(void)" (??0impl@hunspellMorph@@QAE@XZ)
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::~Hunspell(void)" (??1Hunspell@@QAE@XZ) referenced in function "public: __thiscall hunspellMorph::impl::~impl(void)" (??1impl@hunspellMorph@@QAE@XZ)
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "public: int __thiscall Hunspell::analyze(char * * *,char const *,int)" (?analyze@Hunspell@@QAEHPAPAPADPBDH@Z) referenced in function "public: void __thiscall hunspellMorph::impl::Morph(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &)" (?Morph@impl@hunspellMorph@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z)
19>C:\temp\speech\divided_rm_speech_proj\Debug\speechRecognizer.exe : fatal error LNK1120: 4 unresolved externals
21>speechRecognizer.lib(hunspellMorph.obj) : error LNK2019: unresolved external symbol "void __cdecl freelist(char * * *,int)" (?freelist@@YAXPAPAPADH@Z) referenced in function "public: void __thiscall hunspellMorph::impl::Morph(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &)" (?Morph@impl@hunspellMorph@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z)
21>speechRecognizer.lib(hunspellMorph.obj) : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::Hunspell(char const *,char const *,char const *)" (??0Hunspell@@QAE@PBD00@Z) referenced in function "public: __thiscall hunspellMorph::impl::impl(void)" (??0impl@hunspellMorph@@QAE@XZ)
21>speechRecognizer.lib(hunspellMorph.obj) : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::~Hunspell(void)" (??1Hunspell@@QAE@XZ) referenced in function "public: __thiscall hunspellMorph::impl::~impl(void)" (??1impl@hunspellMorph@@QAE@XZ)
21>speechRecognizer.lib(hunspellMorph.obj) : error LNK2019: unresolved external symbol "public: int __thiscall Hunspell::analyze(char * * *,char const *,int)" (?analyze@Hunspell@@QAEHPAPAPADPBDH@Z) referenced in function "public: void __thiscall hunspellMorph::impl::Morph(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &)" (?Morph@impl@hunspellMorph@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z)
21>C:\temp\speech\divided_rm_speech_proj\Debug\interface11.exe : fatal error LNK1120: 8 unresolved externals