0

I have a DLL contains an encapsulated class, let's call it class A, and it works fine. now I want to add another class inside the same DLL; class A call class B. this causes a linking error(but they are inside the same DLL).if I remove class B everything works, None of these classes or functions are being called from outside the DLL!!!

/******** DLL ********/


 #ifndef ENGD3D12_H
#define ENGD3D12_H
class CPUOP;

class EngD3D12 : public IRenderDevice, public RendererAttributes
{
public:
    EngD3D12(HINSTANCE hDll);
    ~EngD3D12(void);

CPUOP *cpuOP;



}
#endif
///////////////////////////////////////
CPP FILE
EngD3D12::EngD3D12(HINSTANCE hDLL) 
{
    cpuOP = new CPUOP(); // err
    cpuOP->GetCPUInfo();    //err
    this->m_hDLL = hDLL;
    m4xMsaaState = false;
    m4xMsaaQuality = 0;
    mCurrentBackBuffer = 0;
    mCurrentFence = 0;
    mBackBufferFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
    mDepthStencilFormat = DXGI_FORMAT_D24_UNORM_S8_UINT;
    m_hFenceEvent = CreateEventExW(nullptr, false, false, EVENT_ALL_ACCESS);
}

//////////////////////////////////////////////
CPUOP.H
#ifndef CPUOP_H
#define CPUOP_H


 class CPUOP
{
    
    public :
        
        typedef struct CPUINFO_Type {
            bool bSSE;
            bool bSSE2;
            bool bSSE3;
            bool bSSSE3;
            bool bSSE4_2;
            bool bSSE4_1;
            bool bAVX;
            bool bOSEnabledAVX;
            bool b3DNow;
            bool bMMX;
            char name[48];
            bool bExt;
            bool bMMXEx;
            bool b3DNowEx;
            char vendor[13];
            
        }  CPUINFO;
    CPUOP();
    ~CPUOP();
    CPUINFO GetCPUInfo();
    
    bool OSSupportSSEE();
    void GetCPUName(char*, int, const char*);
};
 
#endif

///////////////////////////////////////
//CPUOP.cpp
CPUOP::CPUOP()
{

}
CPUOP::CPUINFO CPUOP::GetCPUInfo()
{}
/******** DLL ********/

> Severity  Code    Description Project File    Line    Suppression State
> Error LNK2019 unresolved external symbol "public: __thiscall
> CPUOP::CPUOP(void)" (??0CPUOP@@QAE@XZ) referenced in function "public:
> __thiscall EngD3D12::EngD3D12(struct HINSTANCE__ *)" (??0EngD3D12@@QAE@PAUHINSTANCE__@@@Z)     Error  LNK2019 unresolved
> external symbol "public: struct CPUOP::CPUINFO_Type __thiscall
> CPUOP::GetCPUInfo(void)" (?GetCPUInfo@CPUOP@@QAE?AUCPUINFO_Type@1@XZ)
> referenced in function "public: __thiscall EngD3D12::EngD3D12(struct
> HINSTANCE__ *)" (??0EngD3D12@@QAE@PAUHINSTANCE__@@@Z)

ma1169
  • 659
  • 1
  • 8
  • 26
  • The posted code is so far from being compilable that it's hard to guess where the problem might be in the real code. See [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – dxiv Feb 12 '21 at 07:00
  • So are you seeing the linking error when you build the DLL, or when you build the program that is using the DLL? – john Feb 12 '21 at 07:00
  • Yes, please post real code, if you post what you think is an accurate summary of your code it's almost inevitable that you will fail to post whatever it is that is actually causing the error. – john Feb 12 '21 at 07:02
  • I see the linking error when I build the DLL., abd dxiv I know there shouldn't be an error. OK give me a sec – ma1169 Feb 12 '21 at 07:02
  • @ma1169 So this is just a normal linking error caused by one of the many mistakes that cause linking errors. At the moment it's impossible to say what that error is. – john Feb 12 '21 at 07:03
  • 1
    @ma1169 The simplest explanation (not saying it's definitely true) is that you are failing to compile the file containing `CPUOP::CPUOP()` and `CPUOP::CPUINFO CPUOP::GetCPUInfo()`. It's not completely clear from your editted post but those functions seem to be in a separate file. – john Feb 12 '21 at 07:19
  • They are in a cpp file i used /// to seperate header and cpp, the CPUOP works in a separate project or if i run it in the WinMain – ma1169 Feb 12 '21 at 07:27
  • @ma1169 but how do you compile and link them? Just with a normal Visual Studio project? – PeterT Feb 12 '21 at 07:28
  • I use visual studio 2019 enterprise, and linking works fine if I removed CPUOP object from EngD3D12 constructor – ma1169 Feb 12 '21 at 07:32
  • @ma1169 can you maybe add the full process script output to some paste site like gist.github.com ? – PeterT Feb 12 '21 at 07:34
  • @ma1169 Nothing you have said so far contradicts my theory. Try this test, put a **deliberate error** in the `CPUOP::CPUOP` constructor (say an undeclared variable or just some garbage text) and see if you get a compiler error when you build the DLL. If you do then that proves my theory wrong, or if you don't, then you have the explanation. – john Feb 12 '21 at 07:35
  • ok it will post it in a bit, @john i did and i got an error Error (active) E0020 identifier "x" is undefined EngD3D12 Source Files\CPUOP.cpp 41 – ma1169 Feb 12 '21 at 07:38
  • @ma1169 NO, E0020 is a intellisense error, not a compiler error. That proves nothing. Maybe my theory is correct? (Compiler errors start with C, e.g. undeclared identifier is C2065). – john Feb 12 '21 at 07:40
  • @ma1169 If you are using VS do a Rebuild All on the DLL project, and edit into the question the complete Output Window (*not* the Error List), including the successful compile lines before the link errors. – dxiv Feb 12 '21 at 07:41
  • @ma1169 Another test would be to move the missing functions into the file you know is compiling successfully. – john Feb 12 '21 at 07:45
  • https://gist.github.com/fido9dido/97970e115336f0ea6a8c10742f78654d – ma1169 Feb 12 '21 at 07:47
  • @ma1169 yeah, it's not even trying to compile `CPUOP.cpp` before linking, is that file part of the right project? Did you exclude it from the win32 build somehow? – PeterT Feb 12 '21 at 07:50
  • is that file part of the right project? yes it is. it's a new class and I didnt do anything to exclude it – ma1169 Feb 12 '21 at 07:54
  • @ma1169 Well you could always try removing it and adding it again. That it isn't being compiled is clearly the problem. It is strange that intellisense is picking it up but not the compiler. I would guess that it's added under one configuration but not under the configuration that you are trying to build. – john Feb 12 '21 at 08:02
  • @ma1169 just create a new project and add the files to it, there's some setting you accidentally changed – PeterT Feb 12 '21 at 08:02
  • Okay, I will do that and I will let you know – ma1169 Feb 12 '21 at 08:03
  • @john i removed the .cpp file and made a new one and it worked!!!! Thanks guys – ma1169 Feb 12 '21 at 08:10
  • it seems that the old cpp file had item type of c/c++ header instead of compiler – ma1169 Feb 12 '21 at 08:14

0 Answers0