# Newbie Header Question (OS X)

• 07-05-2006
Pantheon
I've been working on a very simple exercise meant to show how to use header files. The program takes a user specified range of temperatures and displays a three column table of the tempuratures converted into two different forms, the functions that actually do the conversion are stored in a header file , I am programming using Pico through the terminal in OS X and compiling using g++. Here is the code for my header (convert.h):

Code:

```#ifndef CONVERT_H #define CONVERT_H double celsius_of(int fahr); double ab_value_of(int fahr); #endif```
The code for the headers cpp file. "convert.cpp"

Code:

```#include<iostream> #include"convert.h" using namespace std; double celsius_of(int fahr) { return (static_cast<double>(5)/9) * (fahr - 32); } double ab_value_of(int fahr) { return ((static_cast<double>(5)/9) * (fahr - 32)) + 273.15; }```
And the code for the main program:

Code:

``` #include <iostream> #include <iomanip> #include"convert.h" using namespace std; void print_prelim_message() { cout << "This program outputs a list of temperatures converted into various forms" << endl; } void print_message_echoing_input(int lower,int upper,int step) { cout << "A chart of temperatures between " << lower << " and " << upper << " in the increment of " << step << " is as follows:" << endl; } int print_table(int lower,int upper,int step) { cout << setw(10) << "Fahrenheit" << setw(10) << "Celsius" << setw(10) << "Kelvin" << endl; for (; lower <= upper; lower = lower+step) { cout << setw(10) << lower << setw(10) << celsius_of(lower) << setw(10) << ab_value_of(lower) << endl ; } } int main () { int lower = 0; int upper = 0; int step = 1; print_prelim_message(); cout << "Please enter a minimum temp." << endl; cin >> lower; cout << "Please enter a maximum temp." << endl; cin >> upper; cout << "Please enter an increment." << endl; cin >> step; print_message_echoing_input(lower, upper, step); print_table(lower, upper, step); return 0; }```
I've gone over the syntax about a million times, yet when I try to compile it g++ spits out the following error:

/usr/bin/ld: Undefined Symbols:
celsius_of(int)
ab_value_of(int)
collect2: ld returned 1 exit status

I have no idea what's going wrong.
• 07-05-2006
whiteflags
> using namespace std;
You need to not use this anymore (at least not in global scope). As soon as you start splitting up files, this becomes difficult to use correctly and causes trouble for the linker, because things that don't belong to that namespace can become implicitly resolved with std::
• 07-05-2006
JaWiB
How are you calling g++? Something like this should work:
Code:

`g++ main.cpp convert.cpp -o convert`
• 07-07-2006
Pantheon
Aha
Thanks for the help, turns out the problem was in the way I was using g++.