Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8837361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:42:15+00:00 2026-06-14T09:42:15+00:00

I’ve already wasted time trying to figure this out but no luck so far…I’ve

  • 0

I’ve already wasted time trying to figure this out but no luck so far…I’ve tried looking through StackOverflow for the same problem but mostly it’s related to the IDE people are using, such as VS or Eclipse.

I was doing some examples from the Stanford Reader for their C++ course but the code won’t work right. I’m trying to figure out how to use external libraries but something keeps going wrong. I’m probably not using the right command but then I don’t know which command to use.

I’m using Cygwin and it’s terminal to do the c++ exercises. I have all the files in the same folder. I am using windows 7 but that shouldn’t be the biggest problem though.

As an example this error shows well what I get when writing g++ Craps.cpp:

$ g++ Craps.cpp

/tmp/ccdTdi0t.o:Craps.cpp:(.text+0x1cf): undefined reference to `randomInteger(int, int)’

/tmp/ccdTdi0t.o:Craps.cpp:(.text+0x1e6): undefined reference to `randomInteger(int, int)’

/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../i686-pc-cygwin/bin/ld: /tmp/ccdTdi0t.o: bad

reloc address 0x0 in section `.ctors’

collect2: ld returned 1 exit status

The example I was running this time is just one of the ones with external libraries which gives me the same kind of error if I wrong the other. It won’t find the library.

This is my main also called Craps.cpp:

#include <iostream>
#include "random.h"
using namespace std;

bool tryToMakePoint(int point);
int rollTwoDice();
int main() {
   cout << "This program plays a game of craps." << endl;
   int point = rollTwoDice();
   switch (point) {
    case 7: case 11:
      cout << "That's a natural. You win." << endl;
      break;
    case 2: case 3: case 12:
      cout << "That's craps. You lose" << endl;
      break;
    default:
      cout << "Your point is " << point << "." << endl;
      if (tryToMakePoint(point)) {
         cout << "You made your point. You win." << endl;
         } else {
            cout << "You rolled a seven. You lose." << endl;
         }
   }
   return 0;
}


bool tryToMakePoint(int point) {
   while (true) {
      int total = rollTwoDice();
      if (total == point) return true;
      if (total == 7) return false;
   }
}


int rollTwoDice() {
   cout << "Rolling the dice . . . " << endl;
   int d1 = randomInteger(1, 6);
   int d2 = randomInteger(1, 6);
   int total = d1 + d2;
   cout << "You rolled " << d1 << " and " << d2 
        << " - that's " << total << endl;
   return total;
}

My random.cpp:

#include <cstdlib>
#include <cmath>
#include <ctime>
#include "random.h"
using namespace std;

void initRandomSeed();

int randomInteger(int low, int high) {
   initRandomSeed();
   double d = rand() / (double(RAND_MAX) + 1);
   double s = d * (double(high) - low + 1);
   return int(floor(low + s ));
}

double randomReal(double low, double high) {
   initRandomSeed();
   double d = rand() / (double(RAND_MAX) + 1);
   double s = d * (high - low);
   return low + s;
}

bool randomChance(double p) {
   initRandomSeed();
   return randomReal(0, 1) < p;
   
}

void setRandomSeed(int seed) {
   initRandomSeed();
   srand(seed);
}

void initRandomSeed() {
   static bool initialized = false;
   if (!initialized) {
      srand(int(time(NULL)));
      initialized = true;
   }
}

and lastly my random.h:

#ifndef _random_h
#define _random_h

int randomInteger(int low, int high);

double randomReal(double low, double high);

bool randomChance(double p);

void setRandomSeed(int seed);

#endif

I hope someone can help me. If it’s the Cygwin command that’s wrong it would be great if I could see what I should write.

Edit:
Just found out that I couldn’t even write down the examples in the book right. Fixed now and should be without mistakes…I dearly hope so. Sorry about that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:42:16+00:00Added an answer on June 14, 2026 at 9:42 am

    Shortly, you should add random.cpp (or, if you already compiled it, an object file or a library where its compiled code resides) into your command line:

    g++ Craps.cpp random.cpp
    

    The problem you face is that the command line says the code in Craps.cpp should be compiled and then linked into an executable. While it’s sufficient to have forward declarations of external functions to compile the file, you should provide the code of these functions to the linker for it to be able to create an executable.

    As for libraries, you usually specify ones that you need to use with -l option to GCC. And you might need to specify (with -L) the path where to take libraries from, even if they all are in the current directory. E.g. provided that you have a library called librandom.a or librandom.so in the current directory:

    g++ Craps.cpp -L. -l random
    

    For external libraries, other directories may need to be specified so that the linker knows where to find the libraries it needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.