I'm writing my first large program project, and I need header files/modules.

I need to know how to make modules and header files. I need to know how to compile it with gcc on a linux compuputer with the command line.

Also I'm dealing with a lot of classes too(main reason I'm doing this).

How would I go about... My code is all messy/problematic when I try to divide it among three files.

With variables not working etc.
Last edited on
Write code in plain text files using the editor of your choice.

Compile as follows:
g++ one.cpp two.cpp three.cpp

where one.cpp, two.cpp, three.cpp are the cpp files you wish to compile. Be sure that one of them has a main function if you want an output executable. It will be named a.out unless you change that with a compile option.

If you need to link to a library, do as follows:

g++ one.cpp two.cpp three.cpp -lLIBRARYNAME

That's not a -i there in front of LIBRARYNAME, it's a lower-case L.

It's that simple. From there, you can make it more and more sophisticated and start using makefiles to automate things for you.

Here's more detail:
http://homepages.gac.edu/~mc38/2001J/documentation/g++.html
Last edited on
What about a .h or .hpp file?

Where do the header files go?

the library argument? -l".h pathname"?

Edit: Also, my header file contains classes. Where the class initilization is the only thing in it... in a seperate file it has the function definitions and includes that header file. This doesn't work... But all the code I copied it from is in once consolidated file that compiles correctly... Is that using it correctly?
Last edited on
lol... it worked... i just forgot to include the libraries with the damn compilation... I hate silly mindless err like that. Pretty cool... Now i can continue this project.
the library argument? -l".h pathname"?


Header files are not libraries. Header files are copied exactly into the files in which they are #included, by the preprocessor. A library is a binary file, already compiled, containing functions.
Topic archived. No new replies allowed.