Compiling multiple files in Ubuntu

Hello everyone.
I am very new to C++ as well to Linux and I ran into a problem that I don't seem to solve on my own.

I am doing some C++ exercises and the one that I can not solve is at
http://www.doc.ic.ac.uk/~wjk/C++Intro/RobMillerE3.html
Question 2.

The problem is that compiling my own program as well as example answer program fails.
I have the same file structure as in that example.
Files that I have:
atable.cpp for the main program
tablefunctions.h for prototypes
tablefunctions.cpp for implementation
I hope you guys and girls can help me out on this.

Thanks.

Command: c++ atable.cpp
Error in terminal:
/tmp/ccHFJ02b.o: In function `print_table(double, double, double)':
atable.cpp:(.text+0x1f7): undefined reference to `abs_value_of(double)'
atable.cpp:(.text+0x205): undefined reference to `fahr_to_celsius(double)'
collect2: ld returned 1 exit status
Last edited on
You need to compile multiple files and link the generated object files together. Compiling only a single file (which is what it looks like you're doing) will leave "holes" because code in other source files is missing.

Doing this all via commandline is a nightmare. Save yourself the headaches and time, and pick up an IDE so you don't have to worry about cli arguments or makefiles or any of that junk -- you just press a button and the IDE automates the building process.

As for IDEs -- I use Code::Blocks on Ubuntu. There are packages available -- check Synaptic or `apt-get codeblocks`
Thank you for the answer. I will try some IDE-s.
Thanks to your comment I took the time to learn a bit about makefiles and I managed to make it work trough the terminal.
Last edited on
Topic archived. No new replies allowed.