Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Teodor_H_
Beginner
260 Views

Suspicious Optimization Behavior - LNK2019 inline virtual destructors

I have following code:

//ivirtualbase.hh
#pragma once
#ifdef _build_dll
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif
class IVirtualBase
{
public:
    virtual ~IVirtualBase(){};
    virtual void speak() = 0;
};

//virtualclass.hh
#pragma once
#ifdef _build_dll
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif
class IVirtualBase
{
public:
    virtual ~IVirtualBase(){};
    virtual void speak() = 0;
};

//concreteclass.hh
#pragma once
#include "ivirtualbase.hh"
#include "virtualclass.hh"

class DLLEXPORT ConcreteClass : public VirtualClass
{
public:
    ConcreteClass(int nn);
    void speak();
    void eat();
    virtual ~ConcreteClass();
private:
    int n;
};

//concreteclass.cpp
#include "concreteclass.hh"
#include <iostream>
ConcreteClass::ConcreteClass(int nn)
{
    n = nn;
}
void ConcreteClass::eat()
{
    n = n - 1;
    std::cout << "Eating 1 n now is " << n << std::endl;
}
void ConcreteClass::speak()
{
    std::cout << "n is " << n << std::endl;
}
ConcreteClass::~ConcreteClass()
{
    std::cout << "destroyed" << std::endl;
}

This code is compiled in a DLL using the following flags:

Compiler:

/GS /Qopenmp /GA /Qansi-alias /Wall /QxHost /Zc:wchar_t /O1 /Qintel-extensions- /Ob2 
/Fd"x64\Release\vc120.pdb" /D "_MBCS" /D "_build_dll" /D "_WINDLL" 
/Qstd=c++11 /Zc:forScope /Oi /MD /Fa"x64\Release\" /EHsc /nologo /Qparallel /Fo"x64\Release\"
/Qprof-dir "x64\Release\" /FA /Wpch-messages- /Fp"x64\Release\Project1.pch" 

Linker:

/OUT:"c:\users\thanchevici\documents\visual studio 2013\Projects\Project1\x64\Release\Project1.dll" /MANIFEST /NXCOMPAT 
/PDB:"c:\users\thanchevici\documents\visual studio 2013\Projects\Project1\x64\Release\Project1.pdb" 
/DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" 
"shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" 
/IMPLIB:"c:\users\thanchevici\documents\visual studio 2013\Projects\Project1\x64\Release\Project1.lib" /DLL 
/MACHINE:X64 /OPT:NOREF /MANIFESTUAC:"level='asInvoker' uiAccess='false'" 
/ManifestFile:"x64\Release\Project1.dll.intermediate.manifest" /OPT:ICF /NOLOGO /TLBID:1 

Library compiles and links without error.

The test program however fails to link

#include "concreteclass.hh"
int main()
{
    ConcreteClass c(10);
    c.speak();
    c.eat();
    return 0;
}

Compiled with:

/GS /W3 /Gy /Zc:wchar_t 
/I"C:\Users\thanchevici\Documents\Visual Studio 2013\Projects\Project1\Project1" 
/O1 /Ob2 /Fd"x64\Release\vc120.pdb" /D "_MBCS" 
/Zc:forScope /Oi /MD /Fa"x64\Release\" /EHsc 
/nologo /Fo"x64\Release\" /Qprof-dir "x64\Release\" /Fp"x64\Release\project2.pch" 

Linked with:

/OUT:"c:\users\thanchevici\documents\visual studio 2013\Projects\Project1\x64\Release\project2.exe" 
/MANIFEST /NXCOMPAT 
/PDB:"c:\users\thanchevici\documents\visual studio 2013\Projects\Project1\x64\Release\project2.pdb" 
/DYNAMICBASE "Project1.lib" "kernel32.lib" "user32.lib" "gdi32.lib" 
"winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" 
"oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" 
/DEBUG /MACHINE:X64 /OPT:REF /SUBSYSTEM:CONSOLE 
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" 
/ManifestFile:"x64\Release\project2.exe.intermediate.manifest"
/OPT:ICF /NOLOGO /LIBPATH:"C:\Users\thanchevici\Documents\Visual Studio 2013\Projects\Project1\x64\Release" 
/TLBID:1 

The error is

error LNK2019: unresolved external symbol "public: virtual __cdecl IVirtualBase::~IVirtualBase(void)" (??1IVirtualBase@@UEAA@XZ) referenced in function main

Disabling optimization makes the error disappear.

Can you please comment on this behavior?

Thank you

Teodor

0 Kudos
24 Replies
SKost
Valued Contributor II
239 Views

Take a look at you test case, that is review it, again. There is something wrong with declarations for your interface and the base class ( headers ivirtualbase.hh and virtualclass.hh ).
SKost
Valued Contributor II
239 Views

There are compilation errors: ... Error E2238 TestApp.cpp 25: Multiple declaration for 'IVirtualBase' Error E2344 TestApp.cpp 9: Earlier declaration of 'IVirtualBase' ... if I try yo compile your test case as is. You've pasted the header file for interface twice.
SKost
Valued Contributor II
239 Views

Here is the output after I've applied a couple of corrections to your sources: ... n is 10 Eating 1 n now is 9 destroyed ... Is that expected output? PS: I think you need to review two topics of C++ language: Why virtual destructors are needed and Fundamentals of Run Time Binding ( aka Late Binding ) of C++ objects.
Teodor_H_
Beginner
239 Views

Sergey,

thank you for taking the time to look into this. I apologize for misleading example.

I have attached the complete example.

If I use /fast i get the following error:

D:\temp\intel\test>nmake /f mydll.nmake mydll

Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

        icl /GR /Wall /Oi /MD /EHa /nologo /Ob2 /c /Qopenmp /Qansi-alias /Qstd=c++11 /Qparallel /fast /D"__INTEL_COMPILER=1700" /D_MBCS /D_build_dll /D_WINDLL concreteclass.cpp
concreteclass.cpp
        xilink /OUT:mydll.dll /IMPLIB:mydll.lib  /DLL /MANIFEST /MACHINE:X64 /NOLOGO /LIBPATH:. /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"mydll.dll.intermediate.manifest" concreteclass.obj
   Creating library mydll.lib and object mydll.exp

Thu 09/15/2016  8:58:14.53
D:\temp\intel\test>nmake /f myexe.nmake myexe

Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

        icl /GR /Wall /Oi /MD /EHa /nologo /Ob2 /c /Qopenmp /Qansi-alias /Qstd=c++11 /Qparallel /fast /D"__INTEL_COMPILER=1700" /D_MBCS main.cpp
main.cpp
        xilink /OUT:myexe.exe /SUBSYSTEM:CONSOLE   "mydll.lib" /ManifestFile:"myexe.exe.intermediate.manifest" main.obj
ipo: warning #11021: unresolved ??1IVirtualBase@@UEAA@XZ
        Referenced in ipo_595610obj3.obj
ipo: error #11023: Not all components required for linking are present on command line
xilink: executing 'link'
Microsoft (R) Incremental Linker Version 12.00.40629.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/OUT:myexe.exe
/SUBSYSTEM:CONSOLE
mydll.lib
/ManifestFile:myexe.exe.intermediate.manifest
ipo_595610obj3.obj

Thu 09/15/2016  8:58:27.46
D:\temp\intel\test>

however, the code compiles fine with the following options: /QxHOST /O2 /Qprec-div- /fp:fast=2

D:\temp\intel\test>nmake /f mydll.nmake mydll

Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

        icl /GR /Wall /Oi /MD /EHa /nologo /Ob2 /c /Qopenmp /Qansi-alias /Qstd=c++11 /Qparallel /QxHOST /O2 /Qprec-div- /fp:fast=2 /D"__INTEL_COMPILER=1700" /D_MBCS /D_build_dll /D_WINDLL concreteclass.cpp
icl: command line remark #10382: option '/QxHOST' setting '/QxCORE-AVX2'
concreteclass.cpp
        xilink /OUT:mydll.dll /IMPLIB:mydll.lib  /DLL /MANIFEST /MACHINE:X64 /NOLOGO /LIBPATH:. /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"mydll.dll.intermediate.manifest" concreteclass.obj
   Creating library mydll.lib and object mydll.exp

Thu 09/15/2016  9:07:31.05
D:\temp\intel\test>nmake /f myexe.nmake myexe

Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

        icl /GR /Wall /Oi /MD /EHa /nologo /Ob2 /c /Qopenmp /Qansi-alias /Qstd=c++11 /Qparallel /QxHOST /O2 /Qprec-div- /fp:fast=2 /D"__INTEL_COMPILER=1700" /D_MBCS main.cpp
icl: command line remark #10382: option '/QxHOST' setting '/QxCORE-AVX2'
main.cpp
        xilink /OUT:myexe.exe /SUBSYSTEM:CONSOLE   "mydll.lib" /ManifestFile:"myexe.exe.intermediate.manifest" main.obj
xilink: executing 'link'
Microsoft (R) Incremental Linker Version 12.00.40629.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/OUT:myexe.exe
/SUBSYSTEM:CONSOLE
mydll.lib
/ManifestFile:myexe.exe.intermediate.manifest
main.obj

Thu 09/15/2016  9:07:46.98
D:\temp\intel\test>myexe.exe
n is 10
Eating 1 n now is 9
destroyed

Thu 09/15/2016  9:07:50.45
D:\temp\intel\test>

Teodor

Teodor_H_
Beginner
239 Views

Hi Sergey,

by changing the code in main.cpp to

#include "concreteclass.hh"
int main()
{
    ConcreteClass* c = new ConcreteClass(10);
    c->speak();
    c->eat();
    delete c;
    return 0;
}

I get the unresolved symbol no matter what

D:\temp\intel\test>nmake /f mydll.nmake mydll

Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

        icl /GR /Wall /Oi /MD /EHa /nologo /Ob2 /c /Qopenmp /Qansi-alias /Qstd=c++11 /Qparallel /Qm64 /Qvc12 /QxHOST /O2 /Qprec-div- /fp:fast=2 /D"__INTEL_COMPILER=1700" /D_MBCS /D_build_dll /D_WINDLL concreteclass.cpp
icl: command line remark #10382: option '/QxHOST' setting '/QxCORE-AVX2'
concreteclass.cpp
        xilink /OUT:mydll.dll /IMPLIB:mydll.lib  /DLL /MANIFEST /MACHINE:X64 /NOLOGO /LIBPATH:. /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"mydll.dll.intermediate.manifest" concreteclass.obj
   Creating library mydll.lib and object mydll.exp

Thu 09/15/2016 10:58:04.36
D:\temp\intel\test>nmake /f myexe.nmake myexe

Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

        icl /GR /Wall /Oi /MD /EHa /nologo /Ob2 /c /Qopenmp /Qansi-alias /Qstd=c++11 /Qparallel /Qm64 /Qvc12 /QxHOST /O2 /Qprec-div- /fp:fast=2 /D"__INTEL_COMPILER=1700" /D_MBCS main.cpp
icl: command line remark #10382: option '/QxHOST' setting '/QxCORE-AVX2'
main.cpp
        xilink /OUT:myexe.exe /SUBSYSTEM:CONSOLE   "mydll.lib" /ManifestFile:"myexe.exe.intermediate.manifest" main.obj
xilink: executing 'link'
Microsoft (R) Incremental Linker Version 12.00.40629.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/OUT:myexe.exe
/SUBSYSTEM:CONSOLE
mydll.lib
/ManifestFile:myexe.exe.intermediate.manifest
main.obj
main.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl IVirtualBase::~IVirtualBase(void)" (??1IVirtualBase@@UEAA@XZ) referenced in function "public: virtual void * __cdecl ConcreteClass::`scalar deleting destructor'(unsigned int)" (??_GConcreteClass@@UEAAPEAXI@Z)
myexe.exe : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.0.109\windows\bin\intel64\xilink.EXE"' : return code '0x460'
Stop.

The same code compiles and links fine with VC 12

D:\temp\intel\test>nmake /f mydll.nmake mydll

Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl /GR /W3 /Oi /MD /EHa /nologo /Ob2 /c  /O2 /D_MBCS /D_build_dll /D_WINDLL concreteclass.cpp
concreteclass.cpp
d:\temp\intel\test\concreteclass.hh(6) : warning C4275: non dll-interface class 'VirtualClass' used as base for dll-interface class 'ConcreteClass'
        d:\temp\intel\test\virtualclass.hh(3) : see declaration of 'VirtualClass'
        d:\temp\intel\test\concreteclass.hh(5) : see declaration of 'ConcreteClass'
        link /OUT:mydll.dll /IMPLIB:mydll.lib  /DLL /MANIFEST /MACHINE:X64 /NOLOGO /LIBPATH:. /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"mydll.dll.intermediate.manifest" concreteclass.obj
   Creating library mydll.lib and object mydll.exp

d:\temp\intel\test>nmake /f myexe.nmake myexe

Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl /GR /W3 /Oi /MD /EHa /nologo /Ob2 /c  /O2 /D_MBCS main.cpp
main.cpp
d:\temp\intel\test\concreteclass.hh(6) : warning C4275: non dll-interface class 'VirtualClass' used as base for dll-interface class 'ConcreteClass'
        d:\temp\intel\test\virtualclass.hh(3) : see declaration of 'VirtualClass'
        d:\temp\intel\test\concreteclass.hh(5) : see declaration of 'ConcreteClass'
        link /OUT:myexe.exe /SUBSYSTEM:CONSOLE  /MANIFEST /MACHINE:X64 /NOLOGO /LIBPATH:. /MANIFESTUAC:"level='asInvoker' uiAccess='false'" "mydll.lib" /ManifestFile:"myexe.exe.intermediate.manifest" main.obj

d:\temp\intel\test>cl
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.40629 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

I looked at the assembly generated by vc12 and it calls

call        qword ptr [__imp_??_DConcreteClass@@QEAAXXZ]
;vc12
;public: void __cdecl ConcreteClass::`vbase destructor'(void) __ptr64

Intel generates the following:

call        qword ptr [__imp_??1ConcreteClass@@UEAA@XZ]
;intel
;public: virtual __cdecl ConcreteClass::~ConcreteClass(void) __ptr64
mov         rcx,rdi
call        ??1IVirtualBase@@UEAA@XZ

Attached are the asm files. I did try with /Qms2 but it did not make any difference.

However, by dll-exporting the interfaces, i was able to link the program.

// class DLLEXPORT VirtualClass : public virtual IVirtualBase
// class DLLEXPORT IVirtualBase

Is the DLL export really necessary in this case?

Regards,

Teodor

Teodor_H_
Beginner
239 Views

Also, removing the virtual inheritance (class VirtualClass : public IVirtualBase) makes the problem disappear.

I attached ASM files with and without virtual inheritance produced both by Intel and Visual Studio

Teodor_H_
Beginner
239 Views

More updates, using /Qinline-dllimport- option resolves the problem.

Can someone please provide more details about what exactly happened?

thank you

Teodor

SKost
Valued Contributor II
239 Views

>>However, by dll-exporting the interfaces, i was able to link the program. >> >>class DLLEXPORT VirtualClass : public virtual IVirtualBase >>class DLLEXPORT IVirtualBase >> >>Is the DLL export really necessary in this case? Yes, it is always needed for all exported from a DLL C++ classes. The same applies to all exported from a DLL C functions and external global ( static ) variables.
SKost
Valued Contributor II
239 Views

>>...Can someone please provide more details about what exactly happened? I'm not sure that this is a bug and 'm surprised that you had some troubles. If we introduce a term C++ Compiler Strictness then I would rate: - Microsoft C++ compiler as a Soft C++ compiler, - Intel C++ compiler as a Strict C++ compiler, and - MinGW C++ compiler as a Very Strict C++ compiler. For example, Microsoft C++ compiler compiles the following C++ template construction: ... template < class T, RTint iDataType > class TMatrixSet : public TDataSet< T, iDataType > { public: ... if( m_ptData1D == RTnull ) { ... } ... }; ... but, MinGW C++ compiler fails and the code needs to be changed to: ... template < class T, RTint iDataType > class TMatrixSet : public TDataSet< T, iDataType > { public: ... if( TDataSet< T, iDataType >::m_ptData1D == RTnull ) { ... } ... }; ... since m_ptData1D member is declared in TDataSet template class, and I personally prefer that strict version.
Teodor_H_
Beginner
239 Views

Sergey Kostrov wrote:

>>However, by dll-exporting the interfaces, i was able to link the program.
>>
>>class DLLEXPORT VirtualClass : public virtual IVirtualBase
>>class DLLEXPORT IVirtualBase
>>
>>Is the DLL export really necessary in this case?

Yes, it is always needed for all exported from a DLL C++ classes. The same applies to all exported from a DLL C functions and external global ( static ) variables.

Sergey,

With the code i have i get the following behavior when using the compilation flags (implementations were removed):

/GR /Wall /Oi /MD /EHa /nologo /Ob2 /c /Qopenmp /Qansi-alias /Qstd=c++11 /Qparallel 
/fast /D"__INTEL_COMPILER=1700" /D_MBCS /D_build_dll /D_WINDLL
class DLLEXPORT ConcreteClass : public VirtualClass
class VirtualClass : public IVirtualBase
class IVirtualBase

code compiles and links without any problem

class DLLEXPORT ConcreteClass : public VirtualClass
class VirtualClass : public virtual IVirtualBase
class IVirtualBase

there is linking error, destructor for IVirtualBase is not found

class DLLEXPORT ConcreteClass : public virtual VirtualClass
class VirtualClass : public virtual IVirtualBase
class IVirtualBase

both base destructors are not found, linking error

I assume that if everything needs to be DLL exported, then i would get the same linking error. The linking error does not appear if optimization is disabled.

As I was mentioning, adding /Qinline-dllimport- to compilation flags leads to correct linking. If, as you mention, the compiler is strict, I would expect to get at least warnings. There are no meaningful warnings in this case (compiled with /Wall /Qeffc++).

I see two options: there is a bug in the optimizer or the code is not correct, however the diagnostics are poor.

Regards,

Teodor

SKost
Valued Contributor II
239 Views

>>...I see two options: there is a bug in the optimizer or the code is not correct... Your test C++ codes are Too fundamental.
Teodor_H_
Beginner
239 Views

Sergey Kostrov wrote:

>>...I see two options: there is a bug in the optimizer or the code is not correct...

Your test C++ codes are Too fundamental.

I am not sure I follow. If the code is not correct, shouldn't the compiler tell me something?

SKost
Valued Contributor II
239 Views

1. I consider your codes ( from Post #1 ) as correct codes. 2. Intel C++ compiler did Not detect any syntax errors during parsing phase and did Not display any error or warning messages. 3. However, it looks like there is an internal problem with Intel C++ compiler and binary codes are Not generated properly ( related to VTable or something like that / I could be wrong here ). Also, Did you try W5 ( highest Warning Level ) compilation option to show all warning messages? Take into account that Wall compilation option does Not display all warnings. But W5 displays all warnings.
Teodor_H_
Beginner
239 Views

Sergey, thank you for suggestions.

Unfortunately W5 does not tell anything extra:

D:\temp\intel\test>nmake /f mydll.nmake mydll
        icl /GR /Wall /W5 /Oi /MD /EHa /nologo /Ob1 /c /Gd /LD /Qopenmp /Qansi-alias /Qstd=c++11 
            /Qparallel /Qm64 /Qvc12 /Qms2 /Qeffc++ /Wcheck /Qopenmp-offload- /fast 
            /D"__INTEL_COMPILER=1700" /D_MBCS /D_build_dll /D_WINDLL concreteclass.cpp

D:\temp\intel\test\ivirtualbase.hh(3): warning #2012: Effective C++ Item 1 prefer const and inline to #define
  #define DLLEXPORT __declspec(dllexport)
          ^
D:\temp\intel\test\concreteclass.hh(13): remark #1: last line of file ends without a newline
  };
    ^
D:\temp\intel\test\concreteclass.hh(7): warning #2304: non-explicit constructor with single argument may cause 
implicit type conversion
      ConcreteClass(int nn);
      ^
        xilink /OUT:mydll.dll /IMPLIB:mydll.lib  /DLL /MANIFEST /MACHINE:X64 /NOLOGO 
              /LIBPATH:. /MANIFESTUAC:"level='asInvoker' uiAccess='false'" 
             /ManifestFile:"mydll.dll.intermediate.manifest" concreteclass.obj
   Creating library mydll.lib and object mydll.exp
D:\temp\intel\test>nmake /f myexe.nmake myexe
        icl /GR /Wall /W5 /Oi /MD /EHa /nologo /Ob1 /c /Gd /LD /Qopenmp /Qansi-alias 
           /Qstd=c++11 /Qparallel /Qm64 /Qvc12 /Qms2 /Qeffc++ /Wcheck 
           /Qopenmp-offload- /fast /D"__INTEL_COMPILER=1700" /D_MBCS main.cpp
D:\temp\intel\test\ivirtualbase.hh(5): warning #2012: Effective C++ Item 1 prefer const and inline to #define
  #define DLLEXPORT __declspec(dllimport)
          ^
D:\temp\intel\test\concreteclass.hh(13): remark #1: last line of file ends without a newline
  };
    ^
D:\temp\intel\test\concreteclass.hh(7): warning #2304: non-explicit constructor with single argument may cause 
implicit type conversion
      ConcreteClass(int nn);
      ^
main.cpp(11): remark #1: last line of file ends without a newline
  }
   ^
        xilink /OUT:myexe.exe /SUBSYSTEM:CONSOLE  /MANIFEST /MACHINE:X64 /NOLOGO /LIBPATH:. 
               /MANIFESTUAC:"level='asInvoker' uiAccess='false'" "mydll.lib" 
               /ManifestFile:"myexe.exe.intermediate.manifest" main.obj
ipo: warning #11021: unresolved ??1IVirtualBase@@UEAA@XZ
        Referenced in ipo_4934010obj3.obj
ipo: error #11023: Not all components required for linking are present on command line
ipo_4934010obj3.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl IVirtualBase::~IVirtualBase(void)" (??1IVirtualBase@@UEAA@XZ) referenced in function "public: virtual void * __cdecl ConcreteClass::`scalar deleting destructor'(unsigned int)" (??_GConcreteClass@@UEAAPEAXI@Z)
myexe.exe : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.0.109\windows\bin\intel64\xilink.EXE"' : return code '0x460'
Stop.

D:\temp\intel\test>more *.hh
#pragma once
#include "ivirtualbase.hh"
#include "virtualclass.hh"
class DLLEXPORT ConcreteClass : public VirtualClass
{
public:
    ConcreteClass(int nn);
    void speak();
    void eat();
    virtual ~ConcreteClass();
private:
    int n;
};
#pragma once
#ifdef _build_dll
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif
class IVirtualBase
{
public:
    virtual ~IVirtualBase() {};
    virtual void speak() = 0;
};
#pragma once
#include "ivirtualbase.hh"
<strong>class VirtualClass : public virtual IVirtualBase</strong>
{
public:
    virtual ~VirtualClass() {};
    virtual void eat() = 0;
};

Here are the results when i remove the virtual inheritance:

D:\temp\intel\test>nmake /f mydll.nmake mydll
        icl /GR /Wall /W5 /Oi /MD /EHa /nologo /Ob1 /c /Gd /LD /Qopenmp /Qansi-alias /Qstd=c++11 /Qparallel 
/Qm64 /Qvc12 /Qms2 /Qeffc++ /Wcheck /Qopenmp-offload- /fast /D"__INTEL_COMPILER=1700" /D_MBCS /D_build_dll 
/D_WINDLL concreteclass.cpp
concreteclass.cpp
D:\temp\intel\test\ivirtualbase.hh(3): warning #2012: Effective C++ Item 1 prefer const and inline to #define
  #define DLLEXPORT __declspec(dllexport)
          ^
D:\temp\intel\test\concreteclass.hh(13): remark #1: last line of file ends without a newline
  };
    ^
D:\temp\intel\test\concreteclass.hh(7): warning #2304: non-explicit constructor with single argument 
may cause implicit type conversion
      ConcreteClass(int nn);
      ^
        xilink /OUT:mydll.dll /IMPLIB:mydll.lib  /DLL /MANIFEST /MACHINE:X64 /NOLOGO /LIBPATH:. 
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"mydll.dll.intermediate.manifest" concreteclass.obj
   Creating library mydll.lib and object mydll.exp
D:\temp\intel\test>nmake /f myexe.nmake myexe
        icl /GR /Wall /W5 /Oi /MD /EHa /nologo /Ob1 /c /Gd /LD /Qopenmp /Qansi-alias /Qstd=c++11
 /Qparallel /Qm64 /Qvc12 /Qms2 /Qeffc++ /Wcheck /Qopenmp-offload- /fast /D"__INTEL_COMPILER=1700" /D_MBCS main.cpp
main.cpp
D:\temp\intel\test\ivirtualbase.hh(5): warning #2012: Effective C++ Item 1 prefer const and inline to #define
  #define DLLEXPORT __declspec(dllimport)
          ^
D:\temp\intel\test\concreteclass.hh(13): remark #1: last line of file ends without a newline
  };
    ^
D:\temp\intel\test\concreteclass.hh(7): warning #2304: non-explicit constructor with single argument may 
cause implicit type conversion
      ConcreteClass(int nn);
      ^
main.cpp(11): remark #1: last line of file ends without a newline
  }
   ^
        xilink /OUT:myexe.exe /SUBSYSTEM:CONSOLE  /MANIFEST /MACHINE:X64 /NOLOGO /LIBPATH:. 
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" "mydll.lib" 
/ManifestFile:"myexe.exe.intermediate.manifest" main.obj

D:\temp\intel\test>more *.hh
#pragma once
#include "ivirtualbase.hh"
#include "virtualclass.hh"
class DLLEXPORT ConcreteClass : public VirtualClass
{
public:
    ConcreteClass(int nn);
    void speak();
    void eat();
    virtual ~ConcreteClass();
private:
    int n;
};
#pragma once
#ifdef _build_dll
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif
class IVirtualBase
{
public:
    virtual ~IVirtualBase() {};
    virtual void speak() = 0;
};
#pragma once
#include "ivirtualbase.hh"
<strong>class VirtualClass : public IVirtualBase</strong>
{
public:
    virtual ~VirtualClass() {};
    virtual void eat() = 0;
};

Anyone from Intel care to comment about this?

Thank you

SKost
Valued Contributor II
239 Views

Regarding a Warning 2304: >>D:\temp\intel\test\concreteclass.hh(7): warning #2304: non-explicit constructor with single argument may >>cause implicit type conversion ConcreteClass( int nn ); There is No a default constructor in your ConcreteClass class.
Teodor_H_
Beginner
239 Views

Sergey Kostrov wrote:

Regarding a Warning 2304:

>>D:\temp\intel\test\concreteclass.hh(7): warning #2304: non-explicit constructor with single argument may
>>cause implicit type conversion ConcreteClass( int nn );

There is No a default constructor in your ConcreteClass class.

I agree, but I fail to see how this is related to the linking error (destructor is missing).

error LNK2019: unresolved external symbol "public: virtual __cdecl IVirtualBase::~IVirtualBase(void)" (??1IVirtualBase@@UEAA@XZ) referenced in function main

 

Teodor_H_
Beginner
239 Views

Hi

Anyone from Intel can please comment on this?

Thank you

Teodor

Yuan_C_Intel
Employee
239 Views

Hi, Teodor

I tried your test case in Post#5 and cannot reproduce the linker issue with icl 17.0.

Here's my output:

C:\...\test>nmake /f mydll.nmake mydll

Microsoft (R) Program Maintenance Utility Version 11.00.50727.1
Copyright (C) Microsoft Corporation.  All rights reserved.

        icl /GR /Wall /Oi /MD /EHa /nologo /Ob2 /c /Qopenmp /Qansi-alias /Qstd=c
++11 /Qparallel /QxHOST /O2 /Qprec-div- /fp:fast=2 /D"__INTEL_COMPILER=1700" /D_
MBCS /D_build_dll /D_WINDLL concreteclass.cpp
icl: command line remark #10382: option '/QxHOST' setting '/QxCORE-AVX2'
concreteclass.cpp
        xilink /OUT:mydll.dll /IMPLIB:mydll.lib  /DLL /MANIFEST /MACHINE:X64 /NO
LOGO /LIBPATH:. /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:
"mydll.dll.intermediate.manifest" concreteclass.obj
   Creating library mydll.lib and object mydll.exp

C:\...\test>nmake /f myexe.nmake myexe

Microsoft (R) Program Maintenance Utility Version 11.00.50727.1
Copyright (C) Microsoft Corporation.  All rights reserved.

        icl /GR /Wall /Oi /MD /EHa /nologo /Ob2 /c /Qopenmp /Qansi-alias /Qstd=c
++11 /Qparallel /QxHOST /O2 /Qprec-div- /fp:fast=2 /D"__INTEL_COMPILER=1700" /D_
MBCS main.cpp
icl: command line remark #10382: option '/QxHOST' setting '/QxCORE-AVX2'
main.cpp
        xilink /OUT:myexe.exe /SUBSYSTEM:CONSOLE   "mydll.lib" /ManifestFile:"my
exe.exe.intermediate.manifest" main.obj
xilink: executing 'link'
Microsoft (R) Incremental Linker Version 11.00.50727.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/OUT:myexe.exe
/SUBSYSTEM:CONSOLE
mydll.lib

I tried both Visual Studio 2012 and Visual Studio 2015. I don't have Visual Studio 2013 environment though.

Were you using 17.0 Beta compiler or the initial produce release?

Thanks.

Yuan_C_Intel
Employee
239 Views

Hi, Teodor

I tried Visual Studio 2013 and ICL 17.0 on another system and still cannot reproduce the error.

Thanks.