clang 컴파일러,declspec (novtable) 로 장식된class는 허함수가 순허로 성명되지 않으면 링크가 실패합니다.

938 단어
novtable과 관련된 컴파일 링크 문제가 발생했습니다.
class __declspec(novtable) Base
{
public:
    // clang 3.1 cannot build without following "=0". But VC can build.
    virtual bool function(int i)/*=0*/;
};
 
class Child : public Base
{
public:
    virtual bool function(int i);
};
 
bool Child::function(int i)
{
    return true;
}
이상 코드,Base의function() 함수는 순허 여부와 상관없이 VC에서 Build를 통과할 수 있지만,clang을 사용하면 순허는 링크로 통과할 수 있으며, 순허 링크가 아니다.오류 메시지는 다음과 같습니다.
===========================================================
Undefined symbols forarchitecture x86_64:
  "typeinfo forBase", referenced from:
      typeinfofor Child in main.o
ld: symbol(s) not foundfor architecture x86_64
clang: error: linkercommand failed with exit code 1 (use -v to see invocation)
===========================================================
novtable에 대해 자세히 연구해야 합니다.연구를 좀 하고 원인을 이따가 보내겠습니다.

좋은 웹페이지 즐겨찾기