Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

c++ - Dll project error "_DllMain@12 already defined in dllmain.obj" MSVS 2017

Here is my .cpp file:

#include "stdafx.h"

#include <iostream>
#include <stdio.h>

INT APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved) {
    FILE *stream;
    fopen_s(&stream, "F:\tmp\_dll\out.txt", "a+");

    switch (Reason) {
    case DLL_PROCESS_ATTACH:
        fprintf(stream, "DLL attach function called
");
        break;
    case DLL_PROCESS_DETACH:
        fprintf(stream, "DLL detach function called
");
        break;
    case DLL_THREAD_ATTACH:
        fprintf(stream, "DLL thread attach function called
");
        break;
    case DLL_THREAD_DETACH:
        fprintf(stream, "DLL thread detach function called
");
        break;
    }

    fclose(stream);

    return TRUE;
}

and here is the error:

1>hook.obj : error LNK2005: _DllMain@12 already defined in dllmain.obj
1>   Creating library F:projects\_dll_hookDebughook.lib and object F:projects\_dll_hookDebughook.exp
1>F:projects\_dll_hookDebughook.dll : fatal error LNK1169: one or more multiply defined symbols found

I know this question have been asked before and I understand the reason for this error, I can not fix it.

The project's "Use of MFC" is set to "Use Standard Windows Libraries".

What I tried and didn't work:

  1. I can't see what library/file produces this error, it doesn't show up in the output.
  2. Remove preprocessor definition of _USRDLL and/or replace it with _LIB.
  3. Add mfcs120d.lib to Additional Dependencies - that file is not found.

What else can I try? Thank you!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...