0

이 사이트에서이 질문에 대한 모든 답변 (많은 내용을 본 것에서부터)이 내 사례에서 다루어졌으며 여전히 곤경. 필자는 레거시 코드로 작업하면서 올바르게 연결된 개발 환경을 설정하는 방식으로 해킹해야합니다. VS 2012를 사용하여, 나는 그들 사이의 의존성의 거미줄과 함께 그것에 22 프로젝트와 솔루션을했습니다. 1 프로젝트, phtranscript는 다른 프로젝트 hunspell의 코드에 따라 다르며 phtranscript의 코드는 차례로 제 3 프로젝트 speechRecognizer에서 필요합니다. 여기서, 관련 파일 컴파일러/링커 출력은 : 프로젝트 phtranscript에서오류 LNK2019 : 해결되지 않은 외부 기호, 모든 일반적인 원인을 배제

:

phTranscript.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 

hunspellMorph.cpp : 프로젝트 hunspell에서

#include "phTranscript.h" 
#include "hunspell.hxx" 
#include <treeNode.h> 

#include <string.h> 

class hunspellMorph::impl{ 
private: 
    Hunspell hs; 

public: 
    impl(); 

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

}; 

void hunspellMorph::impl::Morph(const std::string &in,std::vector<std::string> &out){ 
    char **slst; 
    int re = hs.analyze(&slst,in.c_str()); 
    ... 
    freelist(&slst,re); 
} 

hunspellMorph::hunspellMorph(){ 
    pImpl_ = new impl(); 
} 

hunspellMorph::~hunspellMorph(){ 
    delete pImpl_; 
} 

.... 

:

hunspell.hxx :

#include "affixmgr.hxx" 
#include "suggestmgr.hxx" 
#include "csutil.hxx" 
#include "langnum.hxx" 

#define SPELL_COMPOUND (1 << 0) 
#define SPELL_FORBIDDEN (1 << 1) 
#define SPELL_ALLCAP (1 << 2) 
#define SPELL_NOCAP  (1 << 3) 
#define SPELL_INITCAP (1 << 4) 

#define MAXDIC 20 
#define MAXSUGGESTION 15 
#define MAXSHARPS 5 

#ifndef _HUNSPELL_HXX_ 
#define _HUNSPELL_HXX_ 

class Hunspell 
{ 
    ... 
public: 
    Hunspell(const char * affpath, const char * dpath, const char * key = NULL); 
    ~Hunspell(); 

    int analyze(char ***slst,const char *word,int d=0); 
    ... 
}; 
#endif 

csutil.hxx :

#ifndef __CSUTILHXX__ 
#define __CSUTILHXX__ 

// First some base level utility routines 

#define NOCAP 0 
#define INITCAP 1 
#define ALLCAP 2 
#define HUHCAP 3 
#define HUHINITCAP 4 

#define MORPH_STEM  "st:" 
#define MORPH_ALLOMORPH "al:" 
#define MORPH_POS   "po:" 
#define MORPH_DERI_PFX "dp:" 
#define MORPH_INFL_PFX "ip:" 
#define MORPH_TERM_PFX "tp:" 
#define MORPH_DERI_SFX "ds:" 
#define MORPH_INFL_SFX "is:" 
#define MORPH_TERM_SFX "ts:" 
#define MORPH_SURF_PFX "sp:" 
#define MORPH_FREQ  "fr:" 
#define MORPH_PHON  "ph:" 
#define MORPH_HYPH  "hy:" 
#define MORPH_PART  "pa:" 
#define MORPH_HENTRY  "_H:" 
#define MORPH_TAG_LEN  strlen(MORPH_STEM) 

#define MSEP_FLD ' ' 
#define MSEP_REC '\n' 
#define MSEP_ALT '\v' 

// default flags 
#define DEFAULTFLAGS 65510 
#define FORBIDDENWORD 65510 
#define ONLYUPCASEFLAG 65511 

typedef struct { 
    unsigned char l; 
    unsigned char h; 
} w_char; 

#define w_char_eq(a,b) (((a).l == (b).l) && ((a).h == (b).h)) 

... 
// free character array list 
void freelist(char *** list, int n); 
#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){ 
    ... 
} 

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; 
    } 
} 

그리고 여기에 다른 사이의 정리 빌드의 출력입니다 프로젝트 :

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)" ([email protected]@[email protected]) 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> > > > &)" ([email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@Z) 
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::Hunspell(char const *,char const *,char const *)" ([email protected]@[email protected]@Z) referenced in function "public: __thiscall hunspellMorph::impl::impl(void)" ([email protected]@@[email protected]) 
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::~Hunspell(void)" ([email protected]@[email protected]) referenced in function "public: __thiscall hunspellMorph::impl::~impl(void)" ([email protected]@@[email protected]) 
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "public: int __thiscall Hunspell::analyze(char * * *,char const *,int)" ([email protected]@@[email protected]) 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> > > > &)" ([email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@Z) 
19>C:\temp\speech\divided_rm_speech_proj\Debug\speechRecognizer.exe : fatal error LNK1120: 4 unresolved externals 

많은 코드가 있다는 점에 유의하십시오. 중요하지 않은 것이 있으면 알려주세요.이 설명을 업데이트하겠습니다.

Visual Studio 2012 환경 설정에서 phtranscript의 프로젝트 속성에는 공통 속성 아래에 hunspell 참조가 설정되고 include 디렉토리 필드에는 hunspell include 디렉토리가 포함되고 library directories 필드에는 hunspell 라이브러리 출력 폴더가 포함됩니다 (VC++ 디렉토리), C/C++ 추가 include 디렉토리에는 hunspell include 디렉토리가 나열됩니다. 필자는 링커 -> 입력 추가 라이브러리 필드를 남겼습니다. 왜냐하면 "이미 선언 된 심볼"링커 오류가 나왔기 때문입니다. Project Dependencies (프로젝트 종속성)에서 hunspell을 확인하고 작성 순서에서 phtranscript 앞에 오는지 확인합니다. 마지막으로 필자는 기존의 hunspell 라이브러리 (컴파일 된 후)를 phtranscript 프로젝트에 수동으로 추가했습니다. speechrecognizer 프로젝트에서 필자는 phtranscript 프로젝트 종속성에 해당하는 동일한 단계를 수행했습니다.

코드는 거의 악몽입니다. 이 문제를 해결하는 데 필요한 최소한의 변경 사항은 무엇입니까? 가급적이면 코드 변경 대신 IDE 측에서 무언가를 변경/추가하는 것이 바람직합니다 (필연적이지만).

업데이트 :

모든 프로젝트는 프로젝트 속성에서 응용 프로그램으로 지정되었습니다.(1 개 프로젝트 실행을 의미 제외한 모든) 정적 라이브러리로 변경 한 후, 링크 오류가이되었다 :

21>speechRecognizer.lib(hunspellMorph.obj) : error LNK2019: unresolved external symbol "void __cdecl freelist(char * * *,int)" ([email protected]@[email protected]) 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> > > > &)" ([email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@Z) 
21>speechRecognizer.lib(hunspellMorph.obj) : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::Hunspell(char const *,char const *,char const *)" ([email protected]@[email protected]@Z) referenced in function "public: __thiscall hunspellMorph::impl::impl(void)" ([email protected]@@[email protected]) 
21>speechRecognizer.lib(hunspellMorph.obj) : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::~Hunspell(void)" ([email protected]@[email protected]) referenced in function "public: __thiscall hunspellMorph::impl::~impl(void)" ([email protected]@@[email protected]) 
21>speechRecognizer.lib(hunspellMorph.obj) : error LNK2019: unresolved external symbol "public: int __thiscall Hunspell::analyze(char * * *,char const *,int)" ([email protected]@@[email protected]) 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> > > > &)" ([email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@Z) 
21>C:\temp\speech\divided_rm_speech_proj\Debug\interface11.exe : fatal error LNK1120: 8 unresolved externals 

이 링크 오류가 아니라 컴파일 할 때보다 솟아 맨 끝에 응용 프로그램을 컴파일 할 때까지 기다립니다 응용 프로그램으로 speechrecognizer. 다른 미해결 된 연결 고리가 있지만이 문제와 관련이 있지만 독립적이라고 보입니다.

답변

0

출력 결과에 따르면 두 프로젝트가 * .exe 파일로 컴파일됩니다. 나는 'phrranscript'가 'hunspell'의 일부인 모듈을 사용하는 것을 당신이 어떻게 기대하는지 모르겠다.

종속성을 만드는 경우 hunspell은 phtranscript가 링크하는 정적 (또는 동적) 라이브러리 여야합니다. 나는 당신이 모든 의존성을 올바르게 설정했다고 믿는다. 그러나 VS는 함께 링크 할 것이 없기 때문에 링커가 당신에게 너무 화가났다. * .exe를 의존성으로 사용할 수 없다.

간단한 해결책 : 'hunspell'유형을 '정적 라이브러리 (.lib)'또는 '동적 라이브러리 (.dll)'로 변경하고 'phtranscript'를 입력 라이브러리로 사용하십시오.

+0

잘 작동하지 않았고 그냥 따라갔습니다. 위의 첫 번째 업데이트는 제안 사항을 해결합니다. – Erik

+0

hunspell이 speechRecognizer의 입력 라이브러리로 올바르게 추가되었는지 확인하십시오. 내가 알 수있는 한, 모든 누락 된 외부는 hunspell 출처에 정의되어 있습니다. –

+0

speechrecognizer의 속성 페이지에서 저는 hunspell을 참조 용으로 인용했고 VC++ 라이브러리 디렉토리의 일부로 객체를 포함하는 디렉토리를 인용했습니다. 방금 라이브러리 파일 아래에 lib 파일을 명시 적으로 추가 종속성에 넣으면 작동합니다. 정말 고마워요! 왜 다른 사람들이 일하지 않았습니까? 비록 낯선 사람이라도, 정확히 같은 방식으로 설정 되었더라도 (라이브러리 사서의 명시적인 라이브러리 명세에 명시된) 다른 프로젝트에이 문제가없는 이유는 무엇입니까? – Erik

관련 문제