undefined reference to `_mainFlags'(solved)

http://www.stanford.edu/class/cs106b/assignments/Assignment1-linux.zip

I am self-studying this assignment for an upcoming Coursera course. I modified Warmup.cpp in 0-Warmup folder as following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <string>
#include "StanfordCPPLib/console.h"
using namespace std;

/* Constants */

const int HASH_SEED = 5381;               /* Starting point for first cycle */
const int HASH_MULTIPLIER = 33;           /* Multiplier for each cycle      */
const int HASH_MASK = unsigned(-1) >> 1;  /* All 1 bits except the sign     */

/* Function prototypes */

int hashCode(string key);

/* Main program to test the hash function */

int main() {
   string name;
   cout << "Please enter your name: "; 
   getline(cin, name); 
   int code = hashCode(name);
   cout << "The hash code for your name is " << code << "." << endl;
   return 0;
}
int hashCode(string str) {
   unsigned hash = HASH_SEED;
   int nchars = str.length();
   for (int i = 0; i < nchars; i++) {
      hash = HASH_MULTIPLIER * hash + str[i];
   }
   return (hash & HASH_MASK);
}


It gives me this error:

andre@ubuntu-Andre:~/Working/Assignment1-linux/0-Warmup$ g++ Warmup.cpp -o a
/tmp/ccawOOKW.o: In function `main':
Warmup.cpp:(.text+0xb): undefined reference to `_mainFlags'
Warmup.cpp:(.text+0x21): undefined reference to `startupMain(int, char**)'
collect2: ld returned 1 exit status


What is wrong here?
Last edited on
I've found startupMain() which can be found in Assignment1-linux/0-Warmup/StanfordCPPLib/platform.cpp on line 954, and _mainFlags in Assignment1-linux/0-Warmup/StanfordCPPLib/startup.cpp.

Now I am guessing the problem is to link them up, but I've not able to do so even if I #include "private/main.h" in platform.cpp and startup.cpp.
andrenvq57 wrote:
$ g++ Warmup.cpp -o a
This is not sufficient, you must compile all the cpp files:

$ g++ *.cpp -o a


If you just compile one cpp file then you will not be linking up with the things defined in other files.
Thank you L B. I now have a better understanding on how the provided libraries work. And I only pick files that are needed and compile them together.
Topic archived. No new replies allowed.