Visual
C++ Gotchas and Fixes
Link error (error LNK2001)
Link error (error LNK2019)
You fixed the problem but you still get the
same errors
311 errors and 325 warnings!
File already exists.
Can't find the header file (fatal
error C1083)
Ambiguous symbol (error C2872)
Where's the Link tab?
Link error
2001:
main.obj : error LNK2001: unresolved external symbol "public:
__thiscall NodalLoad::NodalLoad
- It may be that you have forgotten to link to a lib file. Check
which lib the file causing
the link error is in. Then in Settings->Link (select General in the
dropdown menu) add the name of the lib file
- In other cases you may want to remove an offending file from a
lib, and rebuild the lib. (Only do this for your own libs that you can
rebuild, of course). This can be the case where you link to a lib and
that lib, itself, has a linking error.
- If you have a lot of libs linked for another project, their order may be incorrect (especially
if there are interdependencies). It's good to copy-paste the lib list
from the app that you're linking to, so the order will be the same.
- You may simply need to include
#include <windows.h>
this is especially the case if you use the OpenGL API
- For some kinds of projects, Bill seems to prefer that you create
a new C++ header or C++ source file and paste in the code. If you do
Project->Add To Project -> Files, he tends to ignore "added"
files at the link stage.
Link
error 2019:
openSees error LNK2019: unresolved external symbol
"int
__cdecl TclModelBuilderVeesCommand(void *,struct Tcl_Interp *,int,..)"
-
In this case you have an extern symbol that is not found, that is, you
have declared something as extern but whereever the original declaration
of the object is cannot be found. A fix is to add the file with the
non-extern declaration to the project so it can be found.
- The library that you are linking to is missing a source file that has
this symbol in it.
You
fixed the problem but you still get the same errors:
Go into the folder where the workspace (file ending in .dsp or .dsw)
resides. Delete the file ending in .ncb
What happens is Bill caches errors he found in the file. Deleting it
gives you a fresh build.
311 errors
and 325 warnings!:
Try clicking Build-> Execute yourprog.exe
If the linking is set to force, the project may get built and run
anyways.
File
already exists.
Find where the actual source file is, delete it, and reboot Windows.
Can't find the header file:
ain.cpp(34) : fatal error C1083: Cannot open include file:
Project->Settings->C/C++
choose Preprocessor from the drop down list.
under Additional Include Directories,
add ., at the beginning of the list
(add the current working directory where you just created your new
header file!)
error C2872:
'ErrorHandler' : ambiguous symbol
This problem occurs when there is more than one file that declares the
type. In my case, both the OpenSees library and the Xerces-c library
had declared a class named ErrorHandler. The fix:
- wrap one class declaration in, i.e.
namespace yourspace {
class ErrorHandler {
:
};
}
- declare the instance using scoping, i.e.
yourspace::ErrorHandler eh;
Where's the Link tab??
If you have a project with
subprojects, the
subprojects do not have a link tab, only the main project. So set the main
project as the active project and link to any libraries you need from
there!