question

kavehrahimi-5744 avatar image
0 Votes"
kavehrahimi-5744 asked MinxinYu-MSFT edited

LNK2005 error

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++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MinxinYu-MSFT avatar image
0 Votes"
MinxinYu-MSFT answered MinxinYu-MSFT edited

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.




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, @kavehrahimi-5744
May I know if you have got any chance to check my answer? I am glad to help if you have any other questions.

0 Votes 0 ·