I have copied this program from this site, and simply copied as a new C++ file
but when run I got a number of error. so I included Myheader file which amongs other includes, the iostream.h, and stlib.h, that is why they have been commented out below. Any way doing this I have then run the program, and got a syntax error so I commented out line six as well, as shown below, but then still couldn't get the program to run, I keep getting this error

Linker error: undefined sysmbol_system in module game1.cpp
"game1 is what have named the program"

#include"myheader.h"
#include<iostream.h>
#include<time.h>
#include<stdlib.h>
#include<windows.h>
//using namespace std;
void one();
void two();
void three();
void four();
void five();
void six();
//Declare Functions used
int main()
{
   short unsigned int score = 0;
   short unsigned int compScore = 0;
   short unsigned int num = 0;
   short unsigned int num2 = 0;
   short unsigned int compNum = 0;
   short unsigned int compNum2 = 0;
   short unsigned int sum = 0;
   short unsigned int compSum = 0;
   char letter='j';
//Declare Variables
   srand(time(NULL));
//Initialize random number generator
   system("title Joe's Dice Game");
   while ( letter != 'q' )
   {
      cout << "Your Score: " << score << endl;
      cout << "computer's Score: " << compScore << endl << endl;
      cout << "Press r to roll or q to quit: ";
      cin >> letter;
      num = 1 + rand() % (6 - 1 + 1);
      num2 = 1 + rand() % (6 - 1 + 1);
      compNum = 1 + rand() % (6 - 1 + 1);
      compNum2 = 1 + rand() % (6 - 1 + 1);

//Random numbers

      sum = num + num2;
      compSum = compNum + compNum2;

//Calculate Sums

      if ( letter == 'q' )
         break;
      if ( letter != 'r' )
      {
         system("cls");
         continue;
      }

      switch ( num )
      {
      case 1:
         one();
         break;
      case 2:
         two();
         break;
      case 3:
         three();
         break;
      case 4:
         four();
         break;
      case 5:
         five();
         break;
      case 6:
         six();
         break;
      default:
         cout << "Error...";
         break;
      } //end switch

      switch ( num2 )
      {
      case 1:
         one();
         break;
      case 2:
         two();
         break;
      case 3:
         three();
         break;
      case 4:
         four();
         break;
      case 5:
         five();
         break;
      case 6:
         six();
         break;
      default:
         cout << "Error...";
         break;
      } //end switch

      cout << endl << "Yours: " << num << ", " << num2 << endl;
      cout << "Computer's: " << compNum << ", " << compNum2 << "\n\n";

//Display dice and numbers

      if ( sum > compSum )
      {
         cout << "You won!!" << endl << endl;
         score++;
      }
      else
      {
         compScore++;
         cout << "you lost..." << endl << endl;
      }

//Calculate score

      system("pause");
      system("cls");

      if ( score == 12 )
      {
         MessageBox(0, "You Won!!!", "Results:", MB_ICONEXCLAMATION);
         break;
      }
      if ( compScore == 12 )
      {
         MessageBox(0, "You lost...", "Results:", MB_ICONEXCLAMATION);
         break; 
      }
   }
   return 0;
}

void one()
{
   cout << " -----" << endl;
   cout << "| |" << endl;
   cout << "| O |" << endl;
   cout << "| |" << endl;
   cout << " -----" << endl;
}
void two()
{
   cout << " -----" << endl;
   cout << "| O|" << endl;
   cout << "| |" << endl;
   cout << "|O |" << endl;
   cout << " -----" << endl;
}
void three()
{
   cout << " -----" << endl;
   cout << "| O|" << endl;
   cout << "| O |" << endl;
   cout << "|O |" << endl;
   cout << " -----" << endl;
}
void four()
{
   cout << " -----" << endl;
   cout << "|O O|" << endl;
   cout << "| |" << endl;
   cout << "|O O|" << endl;
   cout << " -----" << endl;
}
void five()
{
   cout << " -----" << endl;
   cout << "|O O|" << endl;
   cout << "| O |" << endl;
   cout << "|O O|" << endl;
   cout << " -----" << endl;
}
void six()
{
   cout << " -----" << endl;
   cout << "|O O|" << endl;
   cout << "|O O|" << endl;
   cout << "|O O|" << endl;
   cout << " -----" << endl;
}

<< moderator edit: added [code][/code] tags and indenting >>

Dani AI

Generated

The linker message shown by — “undefined symbol _system in module game1.cpp” — means the linker could not find the definition of the C library function system. That usually comes from one of three root causes: a header/ macro collision that changes or hides the symbol, the C runtime not being linked, or a calling‑convention/name‑mangling mismatch. was right to ask for the exact error text and the compiler: those two facts dramatically narrow the diagnosis. ’s quick test (removing myheader.h) is a reasonable diagnostic step, but removing the header wholesale may simply reveal other missing declarations the header provided.

Practical checklist to isolate and fix the problem

  • Inspect myheader.h for anything that touches system (search for #define system, a stray prototype like int system(...);, or any identifier named system). Any macro or conflicting declaration there can break the link to the C runtime.

  • Build a tiny standalone test to verify the toolchain can link system. For example, compile a minimal file that calls system and observe whether the linker succeeds. If that test links, the problem is inside myheader.h or the project settings. If it fails, the toolchain or linker flags need checking.

    #include <cstdlib>
    #include <iostream>
    
    int main() {
        std::cout << "system test\n";
        return std::system("echo hello") ? 1 : 0;
    }

    Compile with g++ test.cpp -o test or cl /EHsc test.cpp and inspect full linker output.

  • If the tiny test links, reintroduce myheader.h and add its includes one at a time to see which line causes the break. If the test fails, check project/linker settings (avoid suppressing default libraries, ensure the C runtime is linked). On Windows, also remember that WinAPI functions like MessageBox require linking user32 (add user32.lib if you get undefined MessageBox later).

Summary: the likely culprit is myheader.h colliding with the standard system symbol or the project/linker configuration excluding the C runtime. Exact compiler name and the full linker output (including symbol decoration) point to the precise fix.

Recommended Answers

All 3 Replies

Is that the exact error or your rendition of the error?

I think you should comment out the first line.

[B]//#include"myheader.h"[/B]
#include<iostream.h>
#include<time.h>
#include<stdlib.h>
#include<windows.h>
...

yes that's exactly the error have got.

once i comment the first line, I get loads more errors.

Am guessing maybe that game is rather a C++ project, but i have tried creating it as a project but still no success. Uhh I don't know

can smeone please try and copy the game from http://www.daniweb.com/techtalkforums/thread5123.html
and see if you can get it to work.

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.