Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build problem in Visual Studio 2010

I use CS106 library in the university.After changing Visual Studio 2008 with Visual Studio 2010, I have problems with building new projects or the old ones.I think that new Visual studio is not compatible with CS106 library.Can anyone tell how to fix this problem?

This is the output:

1>------ Build started: Project: Blank, Configuration: Debug Win32 ------ 1>Build started 3/15/2011 2:03:21 PM. 1>InitializeBuildStatus: 1> Touching "Debug\Blank.unsuccessfulbuild". 1>ClCompile: 1> All outputs are up-to-date. 1>CS106CPPLib.lib(strutils.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) 1>CS106CPPLib.lib(simpio.obj) : error LNK2019: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) referenced in function "public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::assign(class std::basic_string,class std::allocator > const &,unsigned int,unsigned int)" (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@II@Z) 1>CS106CPPLib.lib(genlib.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) 1>CS106CPPLib.lib(init.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) 1>CS106CPPLib.lib(pcgraphics.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran@_String_base@std@@SAXXZ) 1>CS106CPPLib.lib(strutils.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) 1>CS106CPPLib.lib(simpio.obj) : error LNK2019: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) referenced in function "protected: bool __thiscall std::basic_string,class std::allocator >::_Grow(unsigned int,bool)" (?_Grow@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IAE_NI_N@Z) 1>CS106CPPLib.lib(genlib.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) 1>CS106CPPLib.lib(init.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) 1>CS106CPPLib.lib(pcgraphics.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen@_String_base@std@@SAXXZ) 1>CS106CPPLib.lib(simpio.obj) : error LNK2019: unresolved external symbol "private: static void __cdecl std::locale::facet::facet_Register(class std::locale::facet *)" (?facet_Register@facet@locale@std@@CAXPAV123@@Z) referenced in function "public: void __thiscall std::locale::facet::_Register(void)" (?_Register@facet@locale@std@@QAEXXZ) 1>CS106CPPLib.lib(strutils.obj) : error LNK2001: unresolved external symbol "private: static void __cdecl std::locale::facet::facet_Register(class std::locale::facet *)" (?facet_Register@facet@locale@std@@CAXPAV123@@Z) 1>CS106CPPLib.lib(simpio.obj) : error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB) 1>CS106CPPLib.lib(strutils.obj) : error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB) 1>Debug\Blank.exe : fatal error LNK1120: 4 unresolved externals 1> 1>Build FAILED. 1> 1>Time Elapsed 00:00:00.97 ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

like image 949
gkiko Avatar asked Jan 20 '23 05:01

gkiko


2 Answers

Here is the solution: http://melbsdailydigest.blogspot.com/

1.) Download one of the latest projects from the Stanford CS106B Website:

CS106B Assignment 1

2.) Unzip the project and find its subdirectory \CS106. This is the folder that contains all the library (CS106CPPLib.lib) and header files for the CS106 program.

3.) Copy this folder as a subdirectory to one of your assignment folders (ex. C:\Assignment1\CS106.

4.) Startup Visual Studio2008 and click File->New->Project… When given the choice choose to create a new Console program.

5.) You’ll then be presented with a new project with multiple files including stdafx.h, stdafx.cpp and similarly named files for whatever you named your project when prompted earlier. DELETE/ REMOVE all these files from the project.

6.) Right click the Source File Folder and choose Add->Existing Item… Choose the first assignment file (Assign1warmup.cpp).

7.) If you compile at this point you’ll realize that it’s still looking for the stdafx.h precompiled header. Let’s fix that. Go to Project->Assignment1 Properties… (or whatever your project might be named). Go to the option in the “tree” menu for Configuration Properties->C/C++->Pre-Compiled Headers . Under the option for Create/Use Precompiled header, choose the drop down option for Not Using Precompiled headers.

8.) While you’re in this section, take the time now to also select the location for the header files for this project. Under the Configuration Properties->C/C++->General section choose the Additional Include Directories option and use the … to browse and select the CS106 folder that you copied to your project folder earlier.

9.) One last thing you should change here is in the Configuration Properties->C/C++->Code Generation section. Change the default (which I believe is for a Multi-Threaded Debug .DLL) to just Multi-Threaded Debug (or just Multi-Threaded if you are doing your release build).

10.) Lastly, we’ll need to let the linker know where to find the CS106 library file. To do that you’ll need to make 2 additional settings. One is in the Configuration Properties->Linker->General section where you can select the location of your additional library files in the section titled appropriately enough – “Additional Library Directories”. You’ll also need to add your library to the project through the “Additional Dependencies” section which is under Configuration Properties->Linker->Input. Just type in CS106CPPLIB.lib.

Note: I found that there seems to be some difference in the menus you get and the settings that get saved depending on what your selection is at the moment in the solution Explorer Window. I originally made all my changes while I was selecting the actual source file, but there were no linker menus at that point. I had to move up to the Source File Folder level to get additional menus where I could set my linker options. Also important to note is that if you make your settings at the lower level (ie. Cpp file) they seem to supersede whatever is set in the level above it.

At this point the project should correctly build with the selection of the Build->Rebuild Solution command. Happy programming!

like image 74
gkiko Avatar answered Jan 22 '23 18:01

gkiko


The source code would help to fix this. But....did you add #include <string> at the top of the file producing the errors?

like image 41
Gregor Brandt Avatar answered Jan 22 '23 19:01

Gregor Brandt