question

DeadStack avatar image
0 Votes"
DeadStack asked Viorel-1 edited

C++ Project randomly has 4 errors (unresolved externals)

There is nothing wrong with my project but VS randomly gives errors:

1) LNK1120    3 unresolved externals .. PlayerDB.Console.exe    1

2) LNK2019    unresolved external symbol "public: void __cdecl Application::Start(void)" (?Start@Application@@QEAAXXZ) referenced in function main    ..\main.obj    1

3) LNK2019    unresolved external symbol "public: __cdecl Application::Application(void)" (??0Application@@QEAA@XZ) referenced in function main    ..\main.obj    1

4) LNK2019    unresolved external symbol "public: __cdecl Application::~Application(void)" (??1Application@@QEAA@XZ) referenced in function main    ..\main.obj    1


These keep popping up again and again, several times today alone. If I clean the solution the project builds and runs. How can I prevent this from happening or is it a bug in VS?



c++
· 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.

If you create a new project and add the existing source to it do the errors occur when building?

0 Votes 0 ·
SimpleSamples avatar image
0 Votes"
SimpleSamples answered

Your program is using a class that looks something like the following.

 class Application {
     public: void __cdecl Application::Start(void) ...
     public: __cdecl Application::Application(void) ...
     public: __cdecl Application::~Application(void) ...
 }

The class is in a file that is not always compiled because Visual Studio does not know that it needs to. When you clean the project Visual Studio knows it needs to. So you need to determine why. We need more information to help you with that.

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.

DeadStack avatar image
0 Votes"
DeadStack answered JeanineZhang-MSFT commented

This is the Application.h file...

 #pragma once
 #define WIN32_LEAN_AND_MEAN
 #include <Windows.h>
 #include <typeinfo>
 #include <iostream>
 #include "PlayerDB.h"
 #include "Command.h"
 #include "Enumerations.h"
    
 using namespace std;
    
 class Application
 {
 public:
  Application();
  ~Application();
  void Start();
  void Exit();
 private:
  PlayerDB* playerDB;
  List<string*>* operationalMsgs;
  void RenderHeader();
  void RenderOperationalMessages();
  void RenderDataView();
  void RenderPrompt();
  Command* GetCommand();
  void ToLowerCase(string* text);
  HANDLE consoleH = GetStdHandle(STD_OUTPUT_HANDLE);
  DataViewMode dataViewMode;
 };

  • Its File Type is a C++ Header File

  • Application.h properties has:
    • Excluded From build = Empty

    • Content = Empty

    • Item Type = C/C++ compiler

And if I make an edit to Application::Start() method, and run, the program is built and run correctly with the edit being apparent at runtime - so Visual Studio is at least sometimes building the project.

If there is any logic to how VS is working - I would suggest that such logic is at least unhelpful if not antagonistic.

· 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.

@DeadStack

Have you tried the methods provided by RLWA32, create a new project and add existing sources to it, and see if there will be an error during the build?

Could you please provide a complete sample to help us reproduce the issue?

0 Votes 0 ·
GuidoFranzke avatar image
0 Votes"
GuidoFranzke answered

Hello,
you asked this question too: lnk4042-object-specified-more-than-once-extras-ign.html
It looks like the questions belong to the same project. Did you check if there are two source files named Application.cpp ?
Maybe you should rename the files for your Application.h and Application.cpp with your code of class Application.
Regards, Guido


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.

DeadStack avatar image
0 Votes"
DeadStack answered DeadStack edited

So this issue happened again today. I'll put up the project here and I've removed vs folder. If anyone wants to take a look, that would be appreciated. Just build and the 3 errors will show up.

PS. I can't attach a zip! That makes it a bit hard.

Here's a OneDrive share..

https://1drv.ms/u/s!AhbcRtciy6_0jcoR1zcefgToZrpUlA?e=GyzCkt

· 3
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.

This is actually happening under different circumstances than usual. Normally I've seen it when the program is runnable, but in this case, after a clean the project isn't runnable. But it does show the errors that keep popping up intermittently.

0 Votes 0 ·

Well, my VS2019 (Version 16.10.1) didn't like the shared code. The first build of the project choked with compilation errors. Call me lazy, but I'll leave it to you to address them.

104332-errors.png


0 Votes 0 ·
errors.png (23.5 KiB)

No, that's fine, it does have those errors, but for me they are hidden behind these other errors that I keep seeing. I have to actually manually locate these errors before they are even visible in the error list. I was hoping others would see the same errors I do, but clearly, Visual Studio isn't deterministic in it's build behavior and completely different steps are taken for different PC's.

I will put up code again when I capture the issue exclusively, without any real compile errors.

0 Votes 0 ·
Viorel-1 avatar image
0 Votes"
Viorel-1 answered Viorel-1 edited

• Its File Type is a C++ Header File
• Item Type = C/C++ compiler

Try changing Item Type of all .h files to “C/C++ header”, because in case of “C/C++ compiler” it will try to generate an Application.obj file from Application.cpp, then another one from Application.h, or vice versa. After this adjustments, which must be done for all of configurations and platform, the occasional linker errors should not appear. (Your log files contain “warning LNK4042: object specified more than once; extras ignored”, which denotes duplicate .obj files).

Then solve all of compiler errors. It seems that you have List<Player> and List<string>. Then it does not have sense to allocate Player and string using ‘new’. Or you can define a List<Player*>. The Add and Insert functions and their parameters can be adjusted to work in any case. But this is a different topic.

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.