ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hey guys. I have a C++ program I wrote that compiles fine when using g++. No errors, no warnings. Even verbose mode seems to indicate no warnings.
Here is the code for the Windows version:
Code:
#include <iostream>
#include <cstdlib>
#include "ClearScreen.h"
int main()
{
bool quit;
int guess;
int randomNumber;
quit = false;
srand(time(0));
ClearScreen("windows");
std::cout << "Welcome to Numbamatic, the Guess a Number Game!\n\n";
std::cout << "Please press 'Enter' to start!";
getchar();
ClearScreen("windows");
while (!quit)
{
std::string answer;
randomNumber = rand() % 10 + 1;
std::cout << "The number has been generated!\n\n";
do
{
std::cout << "Please guess a number!\n> ";
std::cin >> guess;
ClearScreen("windows");
if (guess > randomNumber)
{
std::cout << "Sorry, but the number you guessed was too high.\n\n";
}
else if (guess < randomNumber)
{
std::cout << "Sorry, but the number you guessed was too low.\n\n";
}
else
{
std::cout << "Congratulations! You correctly guessed the "\
"number!\n\n";
}
} while (guess != randomNumber);
std::cout << "Would you like to play again?\n>[y/n] ";
std::cin >> answer;
if (answer != "y" && answer != "n")
{
std::cout << "I'm sorry, but you entered an invalid response."\
" The game will now terminate due to your incompetence."\
" Have a nice day!\n\n";
quit = true;
}
else if (answer == "y")
{
ClearScreen("windows");
}
else
{
quit = true;
}
}
std::cout << "Thanks for playing!\n\n";
return 0;
}
And the ClearScreen.h file:
Code:
int ClearScreen(std::string os)
{
if (os == "unix")
{
system("clear");
}
else if (os == "windows")
{
system("cls");
}
else
{
std::cout << "Error!" << std::endl;
std::cout << "The value you passed to ClearScreen() is not valid!\n";
exit(1);
}
return 0;
}
The above code compiles perfectly in Linux using g++. However, trying to compile it for Windows using MinGW does not work. I've tried using Visual C++ 2008 on a Windows box to compile it, and it still does not work.
i586-mingw32msvc-cc numbamatic-windows.cpp -o numbamatic
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0xe): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x52): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x8b): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0xd0): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x120): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x163): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x1cd): undefined reference to `std::cout'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x1d2): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x1dd): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x1e3): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x1f3): undefined reference to `std::cout'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x1f8): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x22a): undefined reference to `___gxx_personality_sj0'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x281): undefined reference to `std::allocator<char>::allocator()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x2a0): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x2cc): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x2f0): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x30d): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x31d): undefined reference to `std::cout'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x329): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x339): undefined reference to `std::cout'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x33e): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x352): undefined reference to `std::allocator<char>::allocator()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x371): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x38e): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x3db): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x3ff): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x41c): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x43c): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x473): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x49e): undefined reference to `std::cout'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x4aa): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x4ba): undefined reference to `std::cout'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x4c6): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x4d5): undefined reference to `std::cin'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x4da): undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x4e9): undefined reference to `std::allocator<char>::allocator()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x508): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x534): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x558): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x575): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x59a): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x5bb): undefined reference to `std::cout'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x5c7): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x5e1): undefined reference to `std::cout'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x5ed): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x5ff): undefined reference to `std::cout'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x60b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x627): undefined reference to `std::cout'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x633): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x642): undefined reference to `std::cin'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x647): undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::operator>><char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x6a7): undefined reference to `std::cout'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x6b3): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x6ee): undefined reference to `std::allocator<char>::allocator()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x70d): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x739): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x7da): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x7f4): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x80e): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x833): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x854): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x890): undefined reference to `std::cout'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text+0x89c): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text$_ZStneIcSt11char_traitsIcESaIcEEbRKSbIT_T0_T1_EPKS3_[bool std::operator!=<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*)]+0x10): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(char const*) const'
/tmp/ccsNJyWn.o:numbamatic-windows.cpp:(.text$_ZSteqIcSt11char_traitsIcESaIcEEbRKSbIT_T0_T1_EPKS3_[bool std::operator==<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*)]+0x10): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(char const*) const'
collect2: ld returned 1 exit status
dev@dev:~/tutorials/cpp/personal.projects$ less numbamatic-windows.cpp
dev@dev:~/tutorials/cpp/personal.projects$ less numbamatic-unix.cpp
dev@dev:~/tutorials/cpp/personal.projects$ g++ numbamatic-windows.cpp
dev@dev:~/tutorials/cpp/personal.projects$ g++ -v numbamatic-windows.cpp
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)
/usr/lib/gcc/x86_64-linux-gnu/4.2.3/cc1plus -quiet -v -D_GNU_SOURCE numbamatic-windows.cpp -quiet -dumpbase numbamatic-windows.cpp -mtune=generic -auxbase numbamatic-windows -version -fstack-protector -fstack-protector -o /tmp/ccYgt8Io.s
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.2.3/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/usr/include/x86_64-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2
/usr/include/c++/4.2/x86_64-linux-gnu
/usr/include/c++/4.2/backward
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.2.3/include
/usr/include
End of search list.
GNU C++ version 4.2.3 (Ubuntu 4.2.3-2ubuntu7) (x86_64-linux-gnu)
compiled by GNU C version 4.2.3 (Ubuntu 4.2.3-2ubuntu7).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: d12ba6ac5ad10f3cd3c194fd1127d2d9
as --traditional-format -V -Qy -o /tmp/cc4aTJB1.o /tmp/ccYgt8Io.s
GNU assembler version 2.18.0 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.18.0.20080103
/usr/lib/gcc/x86_64-linux-gnu/4.2.3/collect2 --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-linux-gnu/4.2.3/../../../../lib/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.2.3/../../../../lib/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.2.3/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.2.3 -L/usr/lib/gcc/x86_64-linux-gnu/4.2.3 -L/usr/lib/gcc/x86_64-linux-gnu/4.2.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.2.3/../../.. /tmp/cc4aTJB1.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.2.3/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.2.3/../../../../lib/crtn.o
dev@dev:~/tutorials/cpp/personal.projects$ i586-mingw32msvc-cc numbamatic-windows.cpp -o numbamatic
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0xe): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x52): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x8b): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0xd0): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x120): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x163): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x1cd): undefined reference to `std::cout'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x1d2): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x1dd): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x1e3): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x1f3): undefined reference to `std::cout'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x1f8): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x22a): undefined reference to `___gxx_personality_sj0'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x281): undefined reference to `std::allocator<char>::allocator()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x2a0): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x2cc): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x2f0): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x30d): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x31d): undefined reference to `std::cout'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x329): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x339): undefined reference to `std::cout'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x33e): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x352): undefined reference to `std::allocator<char>::allocator()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x371): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x38e): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x3db): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x3ff): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x41c): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x43c): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x473): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x49e): undefined reference to `std::cout'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x4aa): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x4ba): undefined reference to `std::cout'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x4c6): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x4d5): undefined reference to `std::cin'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x4da): undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x4e9): undefined reference to `std::allocator<char>::allocator()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x508): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x534): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x558): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x575): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x59a): undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x5bb): undefined reference to `std::cout'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x5c7): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x5e1): undefined reference to `std::cout'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x5ed): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x5ff): undefined reference to `std::cout'
/tmp/ccIgUslU.o:numbamatic-windows.cpp:(.text+0x60b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
.........................
collect2: ld returned 1 exit status
dev@dev:~/tutorials/cpp/personal.projects$ int ClearScreen(std::string os)
bash: syntax error near unexpected token `('
dev@dev:~/tutorials/cpp/personal.projects$ {
> if (os == "unix")
> {
> system("clear");
bash: syntax error near unexpected token `"clear"'
dev@dev:~/tutorials/cpp/personal.projects$ }
bash: syntax error near unexpected token `}'
dev@dev:~/tutorials/cpp/personal.projects$ else if (os == "windows")
bash: syntax error near unexpected token `else'
dev@dev:~/tutorials/cpp/personal.projects$ {
> system("cls");
bash: syntax error near unexpected token `"cls"'
dev@dev:~/tutorials/cpp/personal.projects$ }
bash: syntax error near unexpected token `}'
dev@dev:~/tutorials/cpp/personal.projects$ else
bash: syntax error near unexpected token `else'
dev@dev:~/tutorials/cpp/personal.projects$ {
> std::cout << "Error!" << std::endl;
bash: !": event not found
> std::cout << "The value you passed to ClearScreen() is not valid!\n";
bash: !\n": event not found
> exit(1);
bash: syntax error near unexpected token `1'
dev@dev:~/tutorials/cpp/personal.projects$ }
bash: syntax error near unexpected token `}'
dev@dev:~/tutorials/cpp/personal.projects$
dev@dev:~/tutorials/cpp/personal.projects$ return 0;
bash: return: can only `return' from a function or sourced script
dev@dev:~/tutorials/cpp/personal.projects$ }
As you can see, it's more or less a lot of the same repeated over and over, until the very end.
I'm not an experienced C++ developer, and I'm just trying to get it to work in both Windows and Linux. As I said before, the Linux version compiles fine, and the Windows version compiles fine if I use g++...but this does not produce a Windows binary file, obviously, and is therefore of little use.
What's the deal here?
[NOTE]
I removed a portion of the error report because it causes me to go over the character limit.
[/NOTE]
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.