1

To fix another debug error, I added -std=c++11 to the build command. Now I'm getting a ton of "undefined reference errors like this one:

In function encrypt(std::string&, int)': 
/home/bob/workspace/New/Debug/../test.cpp:10: undefined reference to std::string::begin()' 
/home/bob/workspace/New/Debug/../test.cpp:10: undefined reference to std::string::end()' 
./test.o: In function main': 
/home/bob/workspace/New/Debug/../test.cpp:24: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'" '

What do I need to fix ? Here's my code

using namespace std;
#include <iostream>
#include <string>

void encrypt(std::string &iostr, int key) {
key %= 26;
int ch;

for (auto &it : iostr) {
ch = tolower(it);
if (!islower(ch)) {
continue;
}
ch += key;
if (ch > 'z') {
ch -= 26;
}
it = ch;
}
}

int main() {
string source;
int key = 1;
cout
<< "Paste cyphertext and press enter to shift each letter right 1";

getline(cin, source);
encrypt(source, key);

cout << source << "";



encrypt(source, key);
cout << source << endl;
cout << "Press ENTER to exit";
cin.ignore(cin.rdbuf()->in_avail() + 1);

return 0;

}
1
  • I think you should give some information about your environment such as OS and compiler versions.
    – Esref
    Jun 15, 2015 at 6:54

1 Answer 1

2

looks like to need to install the stdc++ dev files

sudo apt-get install libstdc++-4.8-dev

then to compile the code

g++ -o execname ./sourcefile.cpp -std=c++11
3
  • Thanks. I did need that update, but the same undefined reference errors persist.
    – bert0nius
    Jun 15, 2015 at 6:37
  • odd, We'll need more to figure it out, what are your compiler and os versions g++ --version and uname -srvi and also what ide are you using?
    – cargo
    Jun 15, 2015 at 7:38
  • also check to make sure you are building with g++ not gcc, if you are using gcc you'll have to add extra flags to get it to build
    – cargo
    Jun 15, 2015 at 7:54

Not the answer you're looking for? Browse other questions tagged .