0

A C++ newbie here so please be kind.

I have console application I am creating Visual Studio. I have set the include directory settings to look for the .h files in the appropriate location. Here is the code and all include statements (PS this is not my code. I got it from assignment 1 of CD106B from Stanford University. I am taking that course for personal learning.) Here is the code for my Obenglobish.cpp file

 * File: Obenglobish.java
 * ----------------------
 * Name: [TODO: enter name here]
 * Section: [TODO: enter section leader here]
 * This file is the starter project for the Obenglobish problem.
 * [TODO: rewrite the documentation]
 */

#include <iostream>
#include <string>
#include "simpio.h"
#include "strlib.h"

using namespace std;

/* Main program */

string obenglobish(string word) {
    return "word";
}

int main() {
    while (true) {
        string word = getLine("Enter a word: ");
        if (word == "") break;
        string trans = obenglobish(word);
        cout << word << " -> " << trans << endl;
    }
    return 0;
}


When I attempt to Run the program using Visual Studio Local debugger here is what I see in the output windows.

1>------ Build started: Project: Obenglobish, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(36,5): warning MSB4211: The property "IntermediateOutputPath" is being set to a value for the first time, but it was already consumed at "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets (35,5)".
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(337,5): warning MSB4211: The property "CleanFile" is being set to a value for the first time, but it was already consumed at "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets (35,5)".
1>Obenglobish.obj : error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl getLine(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?getLine@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z) referenced in function _main
1>C:\Users\faisa\OneDrive\Documents\Training\Taking\OOPinCPlusPlus\Obenglobish\Debug\Obenglobish.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "Obenglobish.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The interesting line to me is as follows

error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl getLine(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?getLine@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z) referenced in function _main

The way I read it is that in the main function, the getLine function (which is defined in simpio.cpp) is referencing another function or class called "class std::allocator" which references another class or function called "std::char_traits" which reference another called "std::basic_string".

Again I am just guessing here so be kind :)

What is going on? Why am I getting unresolved external symbol errors when I have referenced the proper header files? I even tried including the actual CPP files "simpio.cpp" and "strlib.cpp" in my project without any success.

Thanks for any help in advance.

  • 1
    Assuming you mean to use `std::getline` and don't have another function named that then you're using it incorrectly. https://en.cppreference.com/w/cpp/string/basic_string/getline If you do have another function named that then you should try renaming it. It would be a good time to get out of the `using namespace std;` habit too. – Retired Ninja Jun 19 '20 at 02:39
  • 1
    `File: Obenglobish.java` What? – drescherjm Jun 19 '20 at 02:41
  • That is how the file came. I think they meant for it to be CPP. It is in a commen anyway so doesn't affect the program. – Faisal Akhtar Jun 19 '20 at 03:20
  • the getLine function is actually a different function defined in the stanford standard library. You can find the details here. http://web.stanford.edu/class/archive/cs/cs106b/cs106b.1132/materials/cppdoc/simpio.html – Faisal Akhtar Jun 19 '20 at 03:21

0 Answers0