Sorry for a basic question. How can I compile and link a program with g++?

Thai Dang Vu thaid@Cybersoft-VN.com
Wed Feb 6 22:39:00 GMT 2002


Hello everybody,

I'd like to ask a basic question.
Suppose that I'm in /home/guest directory. I have a file named tree.hxx
in include directory, a file named tree.cxx in libfile directory and a
file called app1.cpp in app directory.

This is tree.hxx:

#include <string>
class Tree {
    int m_height;

    public:
    Tree(int p_height);
    void say(string p_s);
};

This is tree.cxx:

#include <tree.hxx>
Tree::Tree(int p_height): m_height(p_height) {
    cout << "hello" << endl;
}
void Tree::say(string p_s) {
    cout << p_s << endl;
}

This is tree.cpp:

#include <tree.hxx>
int main() {
    Tree t(6);
    t.say("hi");
}

How can I compile tree.cxx and tree.cpp and link tree.cpp?
I compile three.cxx with
cd libfile
g++ -I../include -c tree.cxx

Is that right? But I don't know what to do with tree.cpp.

Thanks for your help.
Thai



More information about the Gcc-help mailing list