visual studio 2010 express linking file in different projects - c++

in visual studio 2010 express edition. i have a project (a static library) called prj1.
prj1 has codes to create an object obj1.
in another project prj2 which is a dynamic library i have code which intantiates the object by "new obj1" (the code of obj1 is in prj1).
now when i try to build prj2 i get linking errors:
1> when i try to right click on prj2->properties->frameworkk and references if i add prj1 as new reference i get a lot of link errors like MSVCRTD.lib(MSVCR100D.dll) : error LNK2005:
2> if i do not do step1 above and right click on the solution->properties->project dependencies and then choose prj1 to depend on the prj2. then i get just get a link error which complains that : error LNK2019: unresolved external symbol obj1... unresolved externals.
It would be very kind if someone can help me resolve this issue.
Thanks

Seems that your options that choose runtime library differ. One project for example links to "multi-threaded debug DLL" and other project to "multi threaded debug". When you try to link the projects to each other then you get multiply defined runtime library symbols.

Your static library must be found/added to your library directories, and dependency list, too.

Related

LNK2019 errors on project that has identical properties to another one that works

Using Visual Studio Community 2017
I have 4 projects:
Static library project that uses GLFW and couple other libraries
ProjectA which uses that library, compiles fine
ProjectB which also uses that library, compiles fine
ProjectC which I recently created and uses the library, does not compile
ProjectC has the same properties as ProjectB and ProjectA, nothing should be different, right?
But somehow, I get these errors when compiling ProjectC:
glfw3.lib(context.obj) : error LNK2001: unresolved external symbol
__imp___stdio_common_vsscanf
audio.lib(au.obj) : error LNK2001: unresolved external symbol
__imp__stricmp
I tried building GLFW and Audio library from their sources and replaced the project ones with newly built ones, no effect.
Once again, I somehow managed to untick "Inherit from parent or project defaults" checkbox in Additional Include Directories.
Check your checkboxes everybody!

"Unresolved external symbol __except_handler4_common" in Visual Studio 2015

I'm compiling a legacy Visual Studio 6.0 C++ application in Visual Studio 2015 and I've run into this error and searching the net hasn't yielded any useful information.
LNK2019 unresolved external symbol __except_handler4_common referenced in function __except_handler4 (MSVCRT.lib)
I understand that somewhere in the code is referencing a method no longer(?) present in current versions of MSVCRT. Is there a workaround / compiler flag for this?
The error message is actually saying the the function __except_handler4, defined in MSVCRT.LIB, references the undefined symbol __except_handler4_common. So it's not your code that's making the this reference, it's Visual Studio 2015's code.
The symbol __except_handler4_common is defined in vcruntime.lib. This file should be automatically be linked in. I'm not sure why it wasn't. Did you select the static runtime library in the project options ("Multi-threaded (/MT)"), but then manually add MSVCRT.LIB (part of the dynamic C runtime libary)?
In your library project, check Properties -> C/C++ -> Code Generation -> Runtime Library
Chances are it's set to "Multi Threaded Debug DLL" (/MDd).
If that's the case then try changing it to "Multi Threaded Debug" (/MTd) and rebuild (that worked for me).
The reason for this error depends.
For me it was "libcmt.lib" and "libcmtd.lib" listed explicitly among linker inputs, rather than by selecting it from "Runtime Library" field in GUI.
For me, I was linking to the objects of a static project from a non-static unit test. I tried setting the unit test to static build, but then the compiler (VC++ 2015) got the error An internal error has occurred in the compiler. I ended up setting both the main project and the unit test project to "Use MFC in a Shared DLL", and then it worked.

_initp_misc_cfltcvt_tab and _FPinit when switching to /MDd

I switched my Visual C++ 2012 project from Multi-threaded Debug (/MTd) to Multi-threaded Debug DLL (/MDd). The project is a mixture of C++ .vcxproj and Intel Fortran (.vfproj) projects. After all is rebuild I get the errors below.
In CRT source code I see the offending symbols are defined in crt0dat.c if CRTDLL symbol is not defined. How do I make sure I get crt0dat with CRTDLL when compiling main application?
Any other suggestions how do I troubleshoot this?
50>cmain.obj : error LNK2019: unresolved external symbol _initp_misc_cfltcvt_tab referenced in function wWinMain
50>cmain.obj : error LNK2001: unresolved external symbol _FPinit
50>C:\spm\git\clones\SPM80_dll\MSBuild\x64\dll_debug\SPM_dll_debug_x64.exe : fatal error LNK1120: 2 unresolved externals
I believe /MDd builds require msvcrtd.lib. This should be something that automatically gets linked into your project; it might be that it's ignored through a project setting. Open the Project Settings for the C++ project and look under Linker->Input. There are settings there for Ignore All Default Libraries and Ignore Specific Default Libraries. See if there's anything there that might cause the linker to ignore msvcrtd.lib.
BTW, your code will also need the appropriate DLL to run, which for VS 2012 would be msvcr110d.dll. This should already installed on your machine when you installed VS 2012, but it will have to be distributed with the executable if you move it to another computer.

Compiling C++ program using MS Visual Studio 2010 as to not depend on any external code or redistributables

I want my exe to be runnable without depending on any redistributable packages but when I set
"Use of MFC" to "Use MFC in a Static Library" in the Project > Properties menu, I get errors such as this one:
- Error 2 error LNK2019: unresolved external symbol _imp_GetWindowTextW#12 referenced in function _wmain
So basically I get unresolved external symbol for the functions.
Thank you.
In Project->Properties->Linker->Command Line type user32.lib
Under the linker settings for your project, make sure you've included the default libraries under "Additional Dependencies".
This is usually:
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
Also, make sure have not set "Ignore All Default Libraries".

C++ project compiles as static library but not dynamic (Visual Studio)

I'm a little new to c++ in visual studio, and I'm trying to compile a massive C++ project with Visual Studio. I've gone through and added all source and header files to my project and also updated all of the include paths in the project properties.
If I have the type of project set to "Static Library (.Lib)" the project will compile without error and I'll have a nice fatty .lib file.
If I change the project over to a "Dynamic Library (.dll)" The project no longer compiles and fails on linking errors.
Here's an example of one:
Error 27 error LNK2001: unresolved external symbol "char const * __cdecl Project::toString(enum Project::compMode)" (?toString#Project##$$FYAPBDW4compMode#1##Z) H:\repo.project\user\tool\component.obj tool
Any help or background on what might be happening here?
Check if you defined the following member function
char const* Project::toString(Project::compMode)
When you compile as a static library an unresolved symbol is not an error, because it can be resolved later when you link with other code.
You may have forgotten to add some .cpp file to your project.