Thread: Problems compiling world's easiest program

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    20

    Problems compiling world's easiest program

    Hi, I'm having trouble compiling my program.

    main.cpp file:
    Code:
    #include <iostream>
    
    #include "Test.h"
    
    using namespace std;
    
    int main()
    {
       Test a;
       a.printSomething();
       cout << "Hello World" ;
       return 0;
    }
    Test.h file:
    Code:
    #ifndef TEST_H
    #define TEST_H
    
    class Test
    {
    public:
       void printSomething();
    };
    #endif
    Test.cpp file:
    Code:
    #include <iostream>
    #include "Test.h"
    
    using namespace std;
    
    void Test::printSomething();
    {
       cout << "Hi";
    }
    If I comment a.printSomething(); in my main.cpp file, I won't get compilation errors.

    But if I do, I get a "Undefined first referenced symbol in file" error

    Can anyone help?

    Okay, compiling with
    g++ main.cpp Test.cpp
    gives me no errors.

    But if I compile using
    g++ main.cpp Test.h
    I do get errors.

    Which is the correct way to compile?
    Last edited by markcls; 03-25-2007 at 09:27 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Needed with Compiling C program
    By girishaneja in forum C Programming
    Replies: 2
    Last Post: 05-20-2009, 08:10 AM
  2. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  3. Few problems with my program
    By kzar in forum C Programming
    Replies: 6
    Last Post: 06-22-2005, 07:58 AM
  4. GPA Program Problems
    By Clint in forum C Programming
    Replies: 3
    Last Post: 04-28-2005, 10:45 AM