none
LNK2019 errors suddenly popping up RRS feed

  • Question

  • I have made a Windows desktop program in C Winapi with Microsoft Visual C++ 2010, which I use from time to time, and to which I now and then add some new functionalities. A few days ago the program suddenly wouldn’t open when I tried to start it. I found this strange, because I couldn’t remember to have compiled the program with any new code since last time I used it. I then went into the source code, and when building it, got a long list of LNK2019 errors. I googled each of them, and fixed the issues by doing the recommendations. Most of them were fixed by adding some libraries to Project properties > Configuration properties > Linker > Input > Additional dependencies. I added User32.lib, Gdi32.lib, Advapi32.lib and Shell32.lib.  

    There is, however, one error I am not able to fix, and which is related to “tmainCRTStartup”.  I therefore still get the following error message:

    1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library

    1>LIBCMTD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

    fatal error LNK1120: 1 unresolved externals

    I believe I have tried all the recommendations on the internet, but has not been able to resolve the issue. I therefore hope that somebody could help me with this.

    Lately I have added some code for playing with a midi keyboard, like “midiInStart”. It is said that this requires the header file “mmeapi.h”, but which I don’t have available, and which I neither know where to download. Yet my program has been working for a long time without it.

    I am very puzzled how all these errors suddenly can pop up, after the program has been working fine for a long time. I wonder what’s the reason for this. Great if someone could give an explanation.

    Thanks in advance.

    Thursday, August 15, 2019 11:26 AM

Answers

  • Unfortunately there is not enough information to be able to be helpful here.

    Visual Studio itself doesn't do anything suddenly. This means one of two things.

    1) You did something that you don't see as relevant which caused this.

    2) You are having hardware problems and this caused corruption.

    But there are a couple of things that I find inconsistent about your post.

    You had that bunch of LNK2019 errors. Surely, since you had to set up the project before, all of these libraries would have already been added to the to the project in order to get it to build in the first place. So why did you have to search for this information if you did it before?

    Then there is the unresolved external symbol _main linker error. This requires an extremely deliberate set of actions, your project configuration corrupting in such a way as to convert the word Windows into Console at the exact right spot in the file, or link.exe corrupting in such a way that it always tries to use the console entrypoint. The corruption that has to take place is needed to be so precise that it is hard to imagine that it could happen, or if it did then you wouldn't feel the effects of the corruption in other areas of the system.

    In the case of corruption, the only real advice that can be given is to reinstall Windows and Visual Studio and then recreate the project. Then in future use source control to avoid this kind of corruption.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    • Proposed as answer by Guido Franzke Friday, August 16, 2019 5:47 AM
    • Marked as answer by Gurunama Friday, August 16, 2019 7:27 PM
    Thursday, August 15, 2019 2:45 PM

All replies

  • Unfortunately there is not enough information to be able to be helpful here.

    Visual Studio itself doesn't do anything suddenly. This means one of two things.

    1) You did something that you don't see as relevant which caused this.

    2) You are having hardware problems and this caused corruption.

    But there are a couple of things that I find inconsistent about your post.

    You had that bunch of LNK2019 errors. Surely, since you had to set up the project before, all of these libraries would have already been added to the to the project in order to get it to build in the first place. So why did you have to search for this information if you did it before?

    Then there is the unresolved external symbol _main linker error. This requires an extremely deliberate set of actions, your project configuration corrupting in such a way as to convert the word Windows into Console at the exact right spot in the file, or link.exe corrupting in such a way that it always tries to use the console entrypoint. The corruption that has to take place is needed to be so precise that it is hard to imagine that it could happen, or if it did then you wouldn't feel the effects of the corruption in other areas of the system.

    In the case of corruption, the only real advice that can be given is to reinstall Windows and Visual Studio and then recreate the project. Then in future use source control to avoid this kind of corruption.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    • Proposed as answer by Guido Franzke Friday, August 16, 2019 5:47 AM
    • Marked as answer by Gurunama Friday, August 16, 2019 7:27 PM
    Thursday, August 15, 2019 2:45 PM
  • Thanks for the answer, which resolved my confusion.

    I tried to compile an older version of the code, which I know for sure have been working, but got the same errors. Then I downloaded and installed VIsual Studio Community 2019, but was not able to open it. I am not anymore able to open my 2010 Express version neither. So obviously the issue must have something to do with the harddisk and corrupted files.

    I can either restore the Windows system that I am using now, Windows 7, which would involve reformatting the hard disk, or I can buy Windows 10. But as I don't know so much about hardware errors, I wonder if this will actually solve the problem, or that the issue of the program is a sign of some serious error with the harddrive, making it likely that similar problems would come up again at a later time. Hence, that I should buy a new harddisk or a new computer. I wonder if you had any views on that.

    Sincerely

    Friday, August 16, 2019 7:27 PM