LNK2005 error

kaveh rahimi 61 Reputation points
2021-09-22T17:10:25.737+00:00

Hi , I debug the below code and receive LNK2005 error "main already defined in ConsoleApplication2.obj".
I cannot understand its reason.
Please help
Thanks

include <windows.h>

include <iostream>

pragma comment(lib, "CH341DLL.LIB")

namespace
{
int main(){

    typedef     VOID(CALLBACK   * mPCH341_NOTIFY_ROUTINE) (  // É豸ʼþ֪ͨ»Øµ÷³ÌÐò
        ULONG           iEventStatus);  // É豸ʼþºÍµ±Ç°×´Ì¬(ÔÚÏÂÐж¨Òå): 0=É豸°Î³öʼþ, 3=É豸²åÈëʼþ

define CH341_DEVICE_ARRIVAL 3 // É豸²åÈëʼþ,ÒѾ­²åÈë

define CH341_DEVICE_REMOVE_PEND 1 // É豸½«Òª°Î³ö

define CH341_DEVICE_REMOVE 0 // É豸°Î³öʼþ,ÒѾ­°Î³ö

    ULONG iIndex = 0;
    PCHAR iDeviceID = 0;
    mPCH341_NOTIFY_ROUTINE  iNotifyRoutine = 0;

    BOOL    WINAPI  CH341SetDeviceNotify(
        ULONG                   iIndex,
        PCHAR                   iDeviceID,
        mPCH341_NOTIFY_ROUTINE  iNotifyRoutine);

    if (CH341SetDeviceNotify(iIndex, iDeviceID, iNotifyRoutine)) {
        std::cout << "usb port connected"<<CH341SetDeviceNotify(iIndex, iDeviceID, iNotifyRoutine);
    }
    return CH341SetDeviceNotify(iIndex, iDeviceID, iNotifyRoutine);
}

}

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,537 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Minxin Yu 10,031 Reputation points Microsoft Vendor
    2021-09-23T02:50:17.867+00:00

    Hi, kavehrahimi-5744

    The error message means that in all the compiled code, the *.obj files, the linker finds more than one main() function. Please try to rebuild your solution separately from the beginning, and then add files where you are sure you can't go wrong. You could refer to the document: LNK2005.

    Best regards,

    Minxin Yu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.