error LNK2001: unresolved external symbol - visual-studio-2010

I am converting my project from vc6 to VS 2010.When I compile my project i get error as below for may .lib inputs. I have added all these lib in the Linker-> Input-> Additional Dependencies, also provided the path of these .lib files in Link->General->Additional Library directories. Any tip on this will be very helpful.
lb0.lib(ob0.obj) :error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP##YGXPAVExceptionClass###Z)
lb1.lib(ob1.obj) : error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP##YGXPAVExceptionClass###Z)
lb2.lib(ob2.obj) : error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP##YGXPAVExceptionClass###Z)
lb3.lib(ob3.obj) : error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP##YGXPAVExceptionClass###Z)
lb3.lib(ob4.obj) : error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP##YGXPAVExceptionClass###Z)
lb3.lib(ob5.obj) : error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP##YGXPAVExceptionClass###Z)
lb4.lib(0b6.obj) : error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP##YGXPAVExceptionClass###Z)
Thanks

You need to identify where the SetLastExP() function is defined.
Check that the library that implements SetLastExP is linked.
Get the .obj file and check with dumpbin if it implements in the decoration that you expect.
dumpbin /symbols foo.obj | find "External" | find "SetLastExP"
Compare the decoration you see with the decoration you have in the Linker error message.
Probably the function is defined as extern "C" while your header file doesn't reflect this.

Sometimes, if you have different Character sets (Configuration properties -> general) in your subprojects, Visual Studio shows this kind of error:
error LNK2001: unresolved external symbol" with an *.obj

Related

wxWidgets 2.9.4 built under Visual C++ Express 2010 gives unresolved external errors

I have been trying to upgrade to wxWidgets 2.9.4 over my old 2.8.12 and have run into problems. I compiled it without errors from the command line but when I try to use them in the program that worked just fine under the previous version I get unresolved externals. I cut it down to just a bare frame and TextCtrl object and it still does this (it's basically identical to one of the sample codes at the moment).
I tried the following commands to build the static libraries:
nmake -f makefile.vc SHARED=0 BUILD=release + nmake -f makefile.vc SHARED=0 BUILD=debug
nmake -f makefile.vc SHARED=0 MONOLITHIC=0 BUILD=release + nmake -f makefile.vc SHARED=0 MONOLITHIC=0 BUILD=debug
nmake -f makefile.vc SHARED=0 BUILD=release UNICODE=0 + nmake -f makefile.vc SHARED=0 BUILD=debug UNICODE=0
nmake -f makefile.vc SHARED=0 BUILD=release UNICODE=0 MONOLITHIC=0 + nmake -f makefile.vc SHARED=0 BUILD=debug UNICODE=0 MONOLITHIC=0
Note that I tried using them with both the recommended unicode and no longer supported non-unicode (changed the project properties in Configuration Properties->General accordingly). Also, I used multi-threaded DLL /MD and /MDd linking as recommended by the wxWidgets manual.
Edit: Tried using \MT and \MTd as well, same effect.
From all of the above I get the same linker errors listed below when compiling my application. Please advise me what to do because I have ran out of ideas...
Additionally, as a final resort I built the whole thing using the converted MSVS project from the ../build/msw folder but it gave me the same results.
Debug compile
1>hworld.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall wxApp::Initialize(int &,unsigned short * *)" (?Initialize#wxApp##UAE_NAAHPAPAG#Z)
1>hworld.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall wxAppConsoleBase::OnAssertFailure(unsigned short const *,int,unsigned short const *,unsigned short const *,unsigned short const *)" (?OnAssertFailure#wxAppConsoleBase##UAEXPBGH000#Z)
1>hworld.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall wxAppConsoleBase::OnAssert(unsigned short const *,int,unsigned short const *,unsigned short const *)" (?OnAssert#wxAppConsoleBase##UAEXPBGH00#Z)
1>hworld.obj : error LNK2001: unresolved external symbol "unsigned short const * const wxEmptyString" (?wxEmptyString##3PBGB)
1>hworld.obj : error LNK2019: unresolved external symbol "private: static struct wxString::SubstrBufFromType<class wxScopedCharTypeBuffer<unsigned short> > __cdecl wxString::ConvertStr(char const *,unsigned int,class wxMBConv const &)" (?ConvertStr#wxString##CA?AU?$SubstrBufFromType#V?$wxScopedCharTypeBuffer#G###1#PBDIABVwxMBConv###Z) referenced in function "private: static class wxScopedCharTypeBuffer<unsigned short> __cdecl wxString::ImplStr(char const *,class wxMBConv const &)" (?ImplStr#wxString##CA?AV?$wxScopedCharTypeBuffer#G##PBDABVwxMBConv###Z)
1>hworld.obj : error LNK2019: unresolved external symbol "void __cdecl wxOnAssert(char const *,int,char const *,char const *,unsigned short const *)" (?wxOnAssert##YAXPBDH00PBG#Z) referenced in function "public: void __thiscall wxControlContainerBase::SetContainerWindow(class wxWindow *)" (?SetContainerWindow#wxControlContainerBase##QAEXPAVwxWindow###Z)
1>wxpngd.lib(wxpng_pngread.obj) : error LNK2019: unresolved external symbol _inflateInit_ referenced in function _png_create_read_struct_2
1>wxpngd.lib(wxpng_pngread.obj) : error LNK2019: unresolved external symbol _inflate referenced in function _png_read_row
1>wxpngd.lib(wxpng_pngrutil.obj) : error LNK2001: unresolved external symbol _inflate
1>wxpngd.lib(wxpng_pngread.obj) : error LNK2019: unresolved external symbol _inflateEnd referenced in function _png_read_destroy
1>wxpngd.lib(wxpng_png.obj) : error LNK2019: unresolved external symbol _crc32 referenced in function _png_reset_crc
1>wxpngd.lib(wxpng_png.obj) : error LNK2019: unresolved external symbol _inflateReset referenced in function _png_reset_zstream
1>wxpngd.lib(wxpng_pngrutil.obj) : error LNK2001: unresolved external symbol _inflateReset
1>wxpngd.lib(wxpng_pngwrite.obj) : error LNK2019: unresolved external symbol _deflate referenced in function _png_write_flush
1>wxpngd.lib(wxpng_pngwutil.obj) : error LNK2001: unresolved external symbol _deflate
1>wxpngd.lib(wxpng_pngwrite.obj) : error LNK2019: unresolved external symbol _deflateEnd referenced in function _png_write_destroy
1>wxpngd.lib(wxpng_pngwutil.obj) : error LNK2001: unresolved external symbol _deflateEnd
1>wxpngd.lib(wxpng_pngwutil.obj) : error LNK2019: unresolved external symbol _deflateInit2_ referenced in function _png_zlib_claim
1>wxpngd.lib(wxpng_pngwutil.obj) : error LNK2019: unresolved external symbol _deflateReset referenced in function _png_zlib_release
Release compile
1>wxpng.lib(wxpng_png.obj) : error LNK2001: unresolved external symbol _crc32
1>wxpng.lib(wxpng_png.obj) : error LNK2001: unresolved external symbol _inflateReset
1>wxpng.lib(wxpng_pngrutil.obj) : error LNK2001: unresolved external symbol _inflateReset
1>wxpng.lib(wxpng_pngread.obj) : error LNK2001: unresolved external symbol inflateInit
1>wxpng.lib(wxpng_pngread.obj) : error LNK2001: unresolved external symbol _inflate
1>wxpng.lib(wxpng_pngrutil.obj) : error LNK2001: unresolved external symbol _inflate
1>wxpng.lib(wxpng_pngread.obj) : error LNK2001: unresolved external symbol _inflateEnd
1>wxpng.lib(wxpng_pngwrite.obj) : error LNK2001: unresolved external symbol _deflate
1>wxpng.lib(wxpng_pngwutil.obj) : error LNK2001: unresolved external symbol _deflate
1>wxpng.lib(wxpng_pngwrite.obj) : error LNK2001: unresolved external symbol _deflateEnd
1>wxpng.lib(wxpng_pngwutil.obj) : error LNK2001: unresolved external symbol _deflateEnd
1>wxpng.lib(wxpng_pngwutil.obj) : error LNK2001: unresolved external symbol deflateInit2
1>wxpng.lib(wxpng_pngwutil.obj) : error LNK2001: unresolved external symbol _deflateReset
1>MSVCRT.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
All errors coming from libpng are due to not linking with wxzlib[d].lib, simply add it to the list of libraries in your project. Or use the recommended way to build wxWidgets projects with MSVC and use auto-linking by prepending -I$(WXWIN)/include/msvc to your compiler header files search path.
The rest of the errors (which you only get in debug build which is suspicious on its own) are due to a mismatch between ANSI and Unicode builds. I don't know which version do you use finally as you seem to have built all of them at one moment or the other but if you use the default build, then you need to have _UNICODE and/or UNICODE defined in your project options.
Finally, to avoid such build mismatches in the future, either do nmake -f makefile.vc clean or use different build directories by using unique COMPILER_PREFIX for each build in the future. This is really not rocket science, you just need to avoid confusing yourself by doing too many things at once. Good luck!
Go to your project's settings and change General -> Character Set property accordingly. If you compiled the wx libs with UNICODE=0 (however recommended value is 1) then you need to use Multi-Byte Character set. If compiled ith UNICODE=1 then set that property to Unicode
As for runtime libs, if you compiled with SHARED=0 then in your project settings you will need to use C++ -> Code Generation -> Runtime Libraries property with 'Multi-Threaded Debug' and 'Multi-Threaded' for Debug and Release build accordingly.
The easiest way is to build wxWidgets libs from Visual Studio (there is a build/msw folder which contains solution file for VS2010) and in your project set the same properties as wx libs projects have.
I had this problem as well. I solved it by changing the setting in:
C/C++ | Language | Treat WChar_t as built in type
to Yes.

Error compiling sample firefox protocol hander gecko SDK 3.6

I get the following error while trying to compile a sample implementation of firefox protocol handler. I am using Gecko SDK 3.6, Visual Studio 2010 on Windows Vista. I think the sample is very old and was not build using version 3.6 of the SDK.
1>nsKeywordModule.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) unsigned int __cdecl NS_NewGenericModule2(struct nsModuleInfo const *,class nsIModule * *)" (_imp?NS_NewGenericModule2##YAIPBUnsModuleInfo##PAPAVnsIModule###Z) referenced in function _NSGetModule
1>nsKeywordProtocolHandler.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall nsFixedCString::nsFixedCString(char *,unsigned int,unsigned int)" (_imp??0nsFixedCString##QAE#PADII#Z) referenced in function "public: __thiscall nsCAutoString::nsCAutoString(void)" (??0nsCAutoString##QAE#XZ)
1>nsKeywordProtocolHandler.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static char * nsCharTraits::sEmptyBuffer" (_imp?sEmptyBuffer#?$nsCharTraits#D##2PADA)
1>nsKeywordProtocolHandler.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall nsACString_internal::nsACString_internal(char *,unsigned int,unsigned int)" (_imp??0nsACString_internal##QAE#PADII#Z) referenced in function "protected: __thiscall nsCString::nsCString(char *,unsigned int,unsigned int)" (??0nsCString##IAE#PADII#Z)
I belief the sample was using the complete mozilla implementation to get the header files. Now since we have gecko sdk all the internal linkage will have to be migrated to use frozen linkage because internal linkage is not supported by gecko sdk 3.6.
So in my case i changed nsAString.h to nsStringAPI.h and followed other guidelines

Linking errors when building against Boost Unit Test Framework

I am trying to use Boost Unit Test Framework by building a stand alone library as detailed here:
http://www.boost.org/doc/libs/1_35_0/libs/test/doc/components/utf/compilation.html
So I created a VC library project containing the mentioned files and build it and it was successful. Then I created a test project and referenced the library project I just created, but when I tried to build it, I got the following linking errors:
1>Type.obj : error LNK2019: unresolved external symbol "bool __cdecl boost::test_tools::tt_detail::check_impl(class boost::test_tools::predicate_result const &,class boost::unit_test::lazy_ostream const &,class boost::unit_test::basic_cstring<char const >,unsigned __int64,enum boost::test_tools::tt_detail::tool_level,enum boost::test_tools::tt_detail::check_type,unsigned __int64,...)" (?check_impl#tt_detail#test_tools#boost##YA_NAEBVpredicate_result#23#AEBVlazy_ostream#unit_test#3#V?$basic_cstring#$$CBD#63#_KW4tool_level#123#W4check_type#123#3ZZ) referenced in function "public: void __cdecl test1::test_method(void)" (?test_method#test1##QEAAXXZ)
1>BoostUnitTestFramework.lib(framework.obj) : error LNK2019: unresolved external symbol "void __cdecl boost::debug::break_memory_alloc(long)" (?break_memory_alloc#debug#boost##YAXJ#Z) referenced in function "void __cdecl boost::unit_test::framework::init(class boost::unit_test::test_suite * (__cdecl*)(int,char * * const),int,char * * const)" (?init#framework#unit_test#boost##YAXP6APEAVtest_suite#23#HQEAPEAD#ZH0#Z)
1>BoostUnitTestFramework.lib(framework.obj) : error LNK2019: unresolved external symbol "void __cdecl boost::debug::detect_memory_leaks(bool)" (?detect_memory_leaks#debug#boost##YAX_N#Z) referenced in function "void __cdecl boost::unit_test::framework::init(class boost::unit_test::test_suite * (__cdecl*)(int,char * * const),int,char * * const)" (?init#framework#unit_test#boost##YAXP6APEAVtest_suite#23#HQEAPEAD#ZH0#Z)
1>BoostUnitTestFramework.lib(execution_monitor.obj) : error LNK2019: unresolved external symbol "bool __cdecl boost::debug::attach_debugger(bool)" (?attach_debugger#debug#boost##YA_N_N#Z) referenced in function "public: int __cdecl boost::detail::system_signal_exception::operator()(unsigned int,struct _EXCEPTION_POINTERS *)" (??Rsystem_signal_exception#detail#boost##QEAAHIPEAU_EXCEPTION_POINTERS###Z)
1>BoostUnitTestFramework.lib(execution_monitor.obj) : error LNK2019: unresolved external symbol "bool __cdecl boost::debug::under_debugger(void)" (?under_debugger#debug#boost##YA_NXZ) referenced in function "public: int __cdecl boost::execution_monitor::execute(class boost::unit_test::callback0<int> const &)" (?execute#execution_monitor#boost##QEAAHAEBV?$callback0#H#unit_test#2##Z)
1>BoostUnitTestFramework.lib(unit_test_main.obj) : error LNK2019: unresolved external symbol "class boost::unit_test::test_suite * __cdecl init_unit_test_suite(int,char * * const)" (?init_unit_test_suite##YAPEAVtest_suite#unit_test#boost##HQEAPEAD#Z) referenced in function main
1>C:\Users\Rafid\Workspace\MyPhysics\Builds\VC10\Tests\Debug\Tests.exe : fatal error LNK1120: 6 unresolved externals
They seem to be mainly caused by Boost debug library, but I can't see a reason why I should get linking errors putting in mind that Boost debug library only need to be included as header files, rather than linking against as a library!
Any ideas?!
OK, I figured out what the problem is. Apparently, the list of files mentioned in Boost's website misses the following files:
debug.cpp
test_main.cpp
test_tools.cpp
Once I added those files to my project, the test project compiled and run successfully!
UPDATE: Just wanted to mention that I actually built against Boost 1.51, so it could be that the documentation is a bit old, because I can see that in the page, they are linking the files to Boost 1.35!
For compile unit-tests of boots 1.57 on windows,
I use #Rafid answer,
For me it was add this files to projects:
test_tools.cpp
unit_test_main.cpp
framework.cpp
That locate in BOOST_DIR/libs/test/src

VS2010 Unresolved External Symbol boost::asio::detail::winsock_init_base::throw_on_error when linking boost-system with a project using libtorrent

I'm trying to build a small command line BitTorrent client using Rasterbar's libtorrent, which depends on Boost. I've built both the Boost libraries and the libtorrent library using their respective directions, but when I try to build my project I get the following linking errors
1>------ Build started: Project: MiniBT, Configuration: Debug Win32 ------
1>MiniBT.obj : error LNK2019: unresolved external symbol "protected: static void __cdecl boost::asio::detail::winsock_init_base::throw_on_error(struct boost::asio::detail::winsock_init_base::data &)" (?throw_on_error#winsock_init_base#detail#asio#boost##KAXAAUdata#1234##Z) referenced in function "public: __thiscall boost::asio::detail::winsock_init<2,0>::winsock_init<2,0>(bool)" (??0?$winsock_init#$01$0A##detail#asio#boost##QAE#_N#Z)
1>MiniBT.obj : error LNK2019: unresolved external symbol "protected: static void __cdecl boost::asio::detail::winsock_init_base::startup(struct boost::asio::detail::winsock_init_base::data &,unsigned char,unsigned char)" (?startup#winsock_init_base#detail#asio#boost##KAXAAUdata#1234#EE#Z) referenced in function "public: __thiscall boost::asio::detail::winsock_init<2,0>::winsock_init<2,0>(bool)" (??0?$winsock_init#$01$0A##detail#asio#boost##QAE#_N#Z)
1>MiniBT.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::asio::error::get_misc_category(void)" (?get_misc_category#error#asio#boost##YAABVerror_category#system#3#XZ) referenced in function "void __cdecl boost::asio::error::`dynamic initializer for 'misc_category''(void)" (??__Emisc_category#error#asio#boost##YAXXZ)
1>MiniBT.obj : error LNK2019: unresolved external symbol "unsigned long __cdecl boost::asio::detail::win_tss_ptr_create(void)" (?win_tss_ptr_create#detail#asio#boost##YAKXZ) referenced in function "public: __thiscall boost::asio::detail::win_tss_ptr<class boost::asio::detail::call_stack<class boost::asio::detail::win_iocp_io_service,unsigned char>::context>::win_tss_ptr<class boost::asio::detail::call_stack<class boost::asio::detail::win_iocp_io_service,unsigned char>::context>(void)" (??0?$win_tss_ptr#Vcontext#?$call_stack#Vwin_iocp_io_service#detail#asio#boost##E#detail#asio#boost###detail#asio#boost##QAE#XZ)
1>MiniBT.obj : error LNK2019: unresolved external symbol "protected: static void __cdecl boost::asio::detail::winsock_init_base::cleanup(struct boost::asio::detail::winsock_init_base::data &)" (?cleanup#winsock_init_base#detail#asio#boost##KAXAAUdata#1234##Z) referenced in function "public: __thiscall boost::asio::detail::winsock_init<2,0>::~winsock_init<2,0>(void)" (??1?$winsock_init#$01$0A##detail#asio#boost##QAE#XZ)
It seems to indicate that the asio::detail namespace didn't get included in the boost-system library as it is only those 5 symbols that it seems to have a problem with and it is linking to the boost-system library just fine otherwise. I'm trying to build a 32-bit application on a 64-bit system, but everything I've checked seems to be correctly configured for this.
I know I'm missing something, but I can't seem to figure out what. Does anyone have any suggestions?
With BOOST_ASIO_SEPARATE_COMPILATION defined, in addition to #include "boost/asio/ssl/impl/src.hpp", you must also #include "boost/asio/impl/src.hpp" in one of your cpp files.

Visual studio 2010 CUDA 4.0 Linker errors

Does any one know an easy way to fix the followoing errors:
1>matrixmul.cu.obj : error LNK2019: unresolved external symbol __imp_cutComparefe referenced in function main
1>matrixmul.cu.obj : error LNK2019: unresolved external symbol __imp_cutDeleteTimer referenced in function main
1>matrixmul.cu.obj : error LNK2019: unresolved external symbol __imp_cutGetTimerValue referenced in function main
1>matrixmul.cu.obj : error LNK2019: unresolved external symbol __imp_cutStopTimer referenced in function main
1>matrixmul.cu.obj : error LNK2019: unresolved external symbol __imp_cutStartTimer referenced in function main
1>matrixmul.cu.obj : error LNK2019: unresolved external symbol __imp_cutCreateTimer referenced in function main
1>matrixmul.cu.obj : error LNK2019: unresolved external symbol __imp_cutReadFilei referenced in function main
1>matrixmul.cu.obj : error LNK2019: unresolved external symbol __imp_cutReadFilef referenced in function "int __cdecl ReadFile(struct Matrix *,char *)" (?ReadFile##YAHPEAUMatrix##PEAD#Z)
1>matrixmul.cu.obj : error LNK2019: unresolved external symbol __imp_cutWriteFilef referenced in function "void __cdecl WriteFile(struct Matrix,char *)" (?WriteFile##YAXUMatrix##PEAD#Z)
I've already tried adding the lib directories in:
C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\common\lib\x64
C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\CUDALibraries\common\lib\x64
Any help is apreciated
Those symbols look like functions from the "cutil" library which is included with the CUDA SDK, so you ought to make sure that Visual Studio is set up to link against cutil.lib.

Resources