Visual Studio: Unresolved External Symbols After Adding New DLL APIs

In Visual Studio 2010 solution, I have 2 projects:

  • Project A , which is a dll project
  • Project B , which is an executable project and depends on project A (configured using the dependencies properties of the project project)

When I add new APIs to project A declared using __declspec(dllexport) , specified and calling them from project B

If I just “ Build ” Project B , then it turns out that Project A built, and then Project B , but the linker does not find the new APIs and tells them as unresolved external characters. Now, if I Rebuild "project B , the solution is completely rebuilt and I don't have unresolved character-linker errors.

Any idea what might make the builder not find new characters with a simple Build action and how to fix it?

+4
source share
2 answers

It is quite difficult to explain this with the information you provide. This clearly indicates a build order problem, even if you have documented that A is first created.

You may have a problem with the parallel build feature available in VS. If he does not see the relationship between projects, he allows projects to be built simultaneously using your machine with several processor cores. You can see the initial building, but B also begins to build right away. It is indicated with numbered messages in the "Exit" window, preceded by 1> and 2>.

If there really is an addiction, it becomes a race. If B goes to the linking stage before A connects, then this will certainly have problems. But it is usually declared that he cannot find the import library for the DLL project. Finding an old version of A.lib that lacks some identifiers would be an unusual corner case. However, it is still interesting when he finds A.lib during his writing. Which explains what you observed.

The best thing to do is to make sure that VS knows that there is a dependency, not relying on what she finds out. It is not good to understand this for C or C ++ projects. Right-click your project B in the Solution Explorer window and select Project Dependencies. Check the project A. Now it will no longer build at the same time, B will not start building until it is done A. In fact, this is what you did manually to solve this problem.

If you still have problems, you will need to suspect other programs on your computer, such as a mess with files. Antivirus software is always at the top of the list of troublemakers. Avast is particularly notorious for the fact that VS is very hard.

+4
source

My question is, does this happen every time? It should not. Create command links, create binary files, find resources depending on an existing resource. Not if you change any resource, such as a library, drawings, etc. Then you need rebuild (clean+build) .

Build the project before another build of the project. You should add the dependency as follows:

  • Right click on solution> properties.
  • Go to Project Dependencies> Select a project and check the dependent project.
  • Finally, right-click on your project B, select Set as StartUp Project .

This will make your project build consistently.

0
source

Source: https://habr.com/ru/post/1483101/


All Articles