A C++ project can be compiled by VS6 without errors&warnings.
With VS 2013 Prof., linker problems are occuring. They are providing a pattern namely std::basic_string.
The code was written in 2007 but not by me.
Referenced by a constructor:
vrun.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) public: char const * __thiscall
std::basic_string,class
std::allocator >::c_str(void)const " (__imp_?c_str#?$basic_s
tring#DU?$char_traits#D#std##V?$allocator#D#2##std##QBEPBDXZ)
referenced in fun ction "public: __thiscall VTrs::VTrs(class
VMessageContext &)" (?? 0VDMTrs##QAE#AAVVDMMessageHandlerContext###Z)
In vrun.cpp:
VTrs::VTrs(VMessageContext& handler_):
Inherited(RXS::rName().c_str()),
_handler(handler_)
{
}
(c_str -> const char* c_str() const; --- C98 style --- C11 was not applied in the project till yet)
In vrun.h:
VTrs(VMessageContext&);
Referenced by an operator:
vrun.obj : error LNK2019: unresolved external symbol "__declspec(dllimport)
public: int __thiscall std::basic_string<char,struct std::char_traits<char>,cl
ass std::allocator<char> >::compare(char const *)const " (__imp_?compare#?$basi
c_string#DU?$char_traits#D#std##V?$allocator#D#2##std##QBEHPBD#Z) referenced in
function "bool __cdecl std::operator==<char,struct std::char_traits<char>,clas
s std::allocator<char> >(class std::basic_string<char,struct std::char_traits<c
har>,class std::allocator<char> > const &,char const *)" (??$?8DU?$char_traits#
D#std##V?$allocator#D#1##std##YA_NABV?$basic_string#DU?$char_traits#D#std##V?$a
llocator#D#2##0#PBD#Z)
Refers -as far as interpreted- to a standard operator. (No operator overloading done for == which refers to a string)
By the way, the code itself does not contain "std::basic_string".
The according msdn article was read but this issue was not resolved till yet.
'Usual' issues such as the "C" modifier modifications are already considered for another code.
Any hint how to cope with that?
EDIT: When opening the project the first time with Visual Studio 2013, a kind of conversion dialog was displayed. I agreed but it affected the VC++ Directories. It was visible when comparing the project file with ClearCase to the previous verison. UndoCheckout (via ClearCase) applied the old state. Now it works.
Your linker needs to get the newer MSVC std library from the relevant lib file and it should pick this up when you migrate the project. Take a look at Project Properties->Configuration Properties->Linker->Input and make sure "Ignore All Default Libraries" is set to No
When opening the project the first time with Visual Studio 2013, a kind of conversion dialog was displayed. I agreed but it affected the VC++ Directories. It was visible when comparing the project file with ClearCase to the previous version. UndoCheckout (via ClearCase) applied the old state. Now it works.
Related
#include "gtest/gtest.h"
TEST(BattleUnitTest, CountryReturnsProperName) {
EXPECT_EQ(1, 1);
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
I can't seem to get google test to work. I ran Nuget package manager to get gtest. It keeps giving me these errors:
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "bool __cdecl testing::internal::IsTrue(bool)" (?IsTrue#internal#testing##YA_N_N#Z) referenced in function "public: void __thiscall testing::internal::scoped_ptr<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::reset(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *)" (?reset#?$scoped_ptr#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###internal#testing##QAEXPAV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) Assignment1_Battle E:\C++\Projects\Assignment1_Battle\Assignment1_Battle\BattleUnitTest.obj 1
.
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "public: __thiscall testing::Message::Message(void)" (??0Message#testing##QAE#XZ) referenced in function "private: virtual void __thiscall BattleUnitTest_CountryReturnsProperName_Test::TestBody(void)" (?TestBody#BattleUnitTest_CountryReturnsProperName_Test##EAEXXZ) Assignment1_Battle E:\C++\Projects\Assignment1_Battle\Assignment1_Battle\BattleUnitTest.obj 1
.
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "class testing::AssertionResult __cdecl testing::internal::EqFailure(char const *,char const *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?EqFailure#internal#testing##YA?AVAssertionResult#2#PBD0ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##1_N#Z) referenced in function "class testing::AssertionResult __cdecl testing::internal::CmpHelperEQ<int,int>(char const *,char const *,int const &,int const &)" (??$CmpHelperEQ#HH#internal#testing##YA?AVAssertionResult#1#PBD0ABH1#Z) Assignment1_Battle E:\C++\Projects\Assignment1_Battle\Assignment1_Battle\BattleUnitTest.obj 1
I could post all the errors but almost all of them have to do with LNK2019. Does anyone know how to fix these errors?
I had this problem but there was nothing wrong with my linker settings. I eventually tracked it down to this post PrintTo link issue:
This was indeed caused by the mismatching /Zc:wchar_t setting. I
failed to mention in the previous post that I had made that example
code as Qt Console Application project (with Qt Add-in 1.1.9).
Apparently the wchar_t setting is set to 'no' with that project
template, while Google Mock's project setting is set to 'yes' by
default. When I recompiled Google Mock with the setting set to 'no'
the linker problem went away.
When I changed my setting "Treat WChar_t As Built in Type" to "Yes /Zc:wchar_t" the build worked.
Looks like you need some additional configuration of your test project:
Add gtest library name to you project properties (Project Properties->Configuration Properties->Linker->Input). Be aware that you probably need to add this thing for both Debug and Release configurations and that library names are different (they are gtest.lib for Release and gtestd.lib for Debug; the difference is "d" at the end of the name before dot).
Add the path to the gtest library to your project properties (Project Properties->Configuration Properties->VC++ Directories->Library Directories). This also needs to be done separately for Debug and Release configurations, because the directories are different as well.
If something else goes wrong, this article might be really useful. It contains the full scenario of setting up gtest for a project in Visual Studio without using Nuget. Just be aware that Nuget basically sets up already compiled version of gtest to "package" sub-directory of your project/solution.
I've made a static library project and I added it to the solution that has a project which uses the library.
I included the class I needed from it in the main project like I would with another static library but it throws these errors:
error LNK2019: unresolved external symbol "public: __thiscall NetworkingLib::Base::Base(void)" (??0Base#NetworkingLib##QAE#XZ) referenced in function _SDL_main
error LNK2019: unresolved external symbol "public: void __thiscall NetworkingLib::Base::Connect(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Connect#Base#NetworkingLib##QAEXV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##0#Z) referenced in function _SDL_main
I have no idea what is going wrong. I checked with another project that uses a library in the same way and I can't find any differences. Any help detecting the problem?
The class NetworkingLib::Base has a method I want to use. So what I did in the main project is:
#include "../NetworkLibrary/Base.h"
NetworkingLib::Base *m_pNetworkObj;
m_pNetworkObj = new NetworkingLib::Base();
m_pNetworkObj->Connect("localhost", "80");
I don't think there's anything wrong with this so the problem must be elsewhere.
It's not enough to have the static library in the same solution. You have to pass it to the linker of the project that uses it.
In Visual Studio, the best way to do this is by adding a "Project Reference". This sets up the dependency so that the projects build in the correct order, and also picks the version of the static library matching the consuming project, be that Debug vs Release, x86 vs x64, etc.
Is there any way I can have the main functions for a library built in vs 2010 be accessible from a vs2005 project? The problem that I face is that I have a project in vs 2005 that needs to use the clang frontend library to parse c code. The clang library requires vs 2010 to compile.
Any light you could shed on my problem is appreciated.
Thanks,
Saketh
EDIT:
I receive the following linker errors on compilation
1>hello.lib(hello.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::ios_base::width(_int64)" (_imp_?width#ios_base#std##QAE_J_J#Z) referenced in function "class std::basic_ostream > & __cdecl std::operator<< >(class std::basic_ostream > &,char const *)" (??$?6U?$char_traits#D#std###std##YAAAV?$basic_ostream#DU?$char_traits#D#std###0#AAV10#PBD#Z)
1>hello.lib(hello.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::basic_streambuf >::sputn(char const *,_int64)" (_imp_?sputn#?$basic_streambuf#DU?$char_traits#D#std###std##QAE_JPBD_J#Z) referenced in function "class std::basic_ostream > & __cdecl std::operator<< >(class std::basic_ostream > &,char const *)" (??$?6U?$char_traits#D#std###std##YAAAV?$basic_ostream#DU?$char_traits#D#std###0#AAV10#PBD#Z)
1>hello.lib(hello.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::ios_base::width(void)const " (_imp?width#ios_base#std##QBE_JXZ) referenced in function "class std::basic_ostream > & __cdecl std::operator<< >(class std::basic_ostream > &,char const *)" (??$?6U?$char_traits#D#std###std##YAAAV?$basic_ostream#DU?$char_traits#D#std###0#AAV10#PBD#Z)
1>C:\Users\sakethk\Perforce\sakethk_SAKETHK_7702\source\qcom\qct\modem\uim\tools\sakethk\hello05\Debug\hello05.exe : fatal error LNK1120: 3 unresolved externals
No. Within a single module, you cannot mix objects compiled against different major versions of the CRT. This generally procludes mixing of objects compiled using different major versions of the compiler.
The correct thing to do would be to encapsulate your usage of Visual C++ 2010 within a DLL, and load that DLL from your executable compiled with Visual C++ 2005. Alternatively, upgrade your sources to use Visual C++ 2010. Visual C++ 2005 is ancient.
Your library functions should be at the lowest level here i mean that you should use C-style parameters to functions and use extern "C" to avoind compilers mangling. Here you will find good article on how to create a great library compatible with every compiler. http://chadaustin.me/cppinterface.html
When I am using Qt (v4.7.4) and Boost (tried v1.47 and v1.48) together in my c++ project, I get a linker error caused by a class that includes <boost\filesystem.hpp>. I just set up Qt and before the code was working without any problems.
This is error message:
...obj : error LNK2001: unresolved external symbol "private: static class std::codecvt const * & __cdecl boost::filesystem3::path::wchar_t_codecvt_facet(void)" (?wchar_t_codecvt_facet#path#filesystem3#boost##CAAAPBV?$codecvt#GDH#std##XZ)
...obj : error LNK2001: unresolved external symbol "void __cdecl boost::filesystem3::path_traits::convert(char const *,char const *,class std::basic_string,class std::allocator > &,class std::codecvt const &)" (?convert#path_traits#filesystem3#boost##YAXPBD0AAV?$basic_string#GU?$char_traits#G#std##V?$allocator#G#2##std##ABV?$codecvt#GDH#5##Z)
...obj : error LNK2001: unresolved external symbol "void __cdecl boost::filesystem3::path_traits::dispatch(class boost::filesystem3::directory_entry const &,class std::basic_string,class std::allocator > &,class std::codecvt const &)" (?dispatch#path_traits#filesystem3#boost##YAXABVdirectory_entry#23#AAV?$basic_string#GU?$char_traits#G#std##V?$allocator#G#2##std##ABV?$codecvt#GDH#6##Z)
...obj : error LNK2001: unresolved external symbol "void __cdecl boost::filesystem3::path_traits::convert(unsigned short const *,unsigned short const *,class std::basic_string,class std::allocator > &,class std::codecvt const &)" (?convert#path_traits#filesystem3#boost##YAXPBG0AAV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##ABV?$codecvt#GDH#5##Z)
...exe : fatal error LNK1120: 4 unresolved externals
EDIT:
Here I found someone having this problem coming to this conclusion:
this really is a Qt issue. Using wchar_t as a native type you have to
recompile Qt using the same compiler switch. There even is a bug in the
tracker: https://bugreports.qt.io/browse/QTBUG-9617
In general, you will have to be very careful and do not mix wchar_t
compiler settings in your projects as they will become incompatible.
So I recompiled Qt setting /Zc:wchar_t, but it didn't show any effect. I still get the same error.
I think you are on the right track, but it sounds like your -Zc:wchar_t didn't "stick." We had to do the same thing to make Qt happy with Google Breakpad and the ICU library. We changed the /Zc:wchar_t setting in (QT_SOURCE)\mkspecs\win32-msvc2008\qmake.conf and compiled Qt from source, and after that everything works.
When you build your project that uses Qt and Boost, you should see this option in the compiler output. Something like:
cl -c -nologo -Zm200 -Zc:wchar_t ... (etc.)
If you've already build Qt without this option, you may have to do a make confclean first to ensure everything really gets rebuilt with the new settings.
It sounds like -Zc:wchar_t will be the default in Qt 5.
Using boost-1.49, Qt 4.4 and VS2005 had the same problem. Going to project properties, then setting "Configuration Properties -> C/C++ -> Language -> Treat wchar_t as Built-in Type" to "Yes" fixed the problem.
Qt probably changed the tipology of your program with regards the configuration of the runtime: consequently, the boost library you use (filesystem), that come in many configuration accessed by naming convention - connot be found.
For instance, multithread runtimes require mt somewhere in library name (I hope I remember well, but anyway see the docs where details are fully documented). This naming is fairly transparent to the programmer, due to pragmas that boost programmers appropriately used to ease the library usage under different compilers.
You should miss the non-wchar filesystem.lib. When I used Windows, I used boost Jam to interface with Visual C++ (may be that goes back to the past millenium!). I hope it's still usable.
I'm trying to compile osgearth library with VS2010. The library uses CMake, so after setting all dependencies it generates a VS2010 solution file. However when running build in VS I get this linker error (and 200 similar ones)
Error 7 error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::basic_ofstream >::`vbase destructor'(void)" (_imp??_D?$basic_ofstream#DU?$char_traits#D#std###std##QAEXXZ) referenced in function "public: virtual void __thiscall osgEarth::DiskCache::setImage(class osgEarth::TileKey const &,struct osgEarth::CacheSpec const &,class osg::Image const *)" (?setImage#DiskCache#osgEarth##UAEXABVTileKey#2#ABUCacheSpec#2#PBVImage#osg###Z) C:\swproj\osgearth-src\src\osgEarth\Caching.obj osgEarth
I'm not very familiar with C++, is there anything else I have to set up?
You're missing a reference to std::ofstream. You either need an #include in one of your files or a reference to the standard library dll in your project.