problem with libraries?

Hi all,

Im learning to program in c++ using online lecture notes at http://www.doc.ic.ac.uk/~wjk/C++Intro/CourseStructure.html#S1.

While attempting to compile a program with subroutines in seperate files (conversions.h and conversions.cpp) I get the following errors:

/tmp/ccK05p2w.o: In function `print_table(int, int, int)':
a_path/RobMillerEA3-2.cpp:97: undefined reference to `absolute_value_of(int)'
a_path/freek/freek/programmeren/learningc++/lesson3/RobMillerEA3-2.cpp:97: undefined reference to `celsius_of(int)'
collect2: ld returned 1 exit status

This even happens if I import them directly from their website, it is question 2 of lesson 3, the answers are provided. (http://www.doc.ic.ac.uk/~wjk/C++Intro/RobMillerE3.html).

It seems to me like a library problem, but as I have all my files in the same folder and run the executable from this folder I dont see the problem.
Can someone explain me what I do wrong? Do you get the same errors when using the example answers?
I compile the file in the following way:

g++ -Wall -g file.cpp -o file.x


Thanks

Joop
I can't find the source code that you say you're compiling.
It looks to me like you are not compiling properly.

With multiple source (.cpp) files, there are two basic methods to do it.

The first is to have the compiler do everything for you:

    g++ -Wall RobMillerEA3-2.cpp conversions.cpp -o foo.exe

The second is to compile individually and then use GCC to link the object files:

    g++ -Wall -c RobMillerEA3-2.cpp
    g++ -Wall -c conversions.cpp
    g++ RobMillerEA3-2.o conversions.o -o foo.exe

Now you can run foo.exe as usual.

Hope this helps.
Topic archived. No new replies allowed.