linux c++ programming

Posted on 2004-11-09
Last Modified: 2010-04-22
I've created a program in c++ that converts celsius to farenheit and vice versa. This program has two conversion functions and each function is it's own separate file. How do I compile each file seperately using the CC commands and create an object file? Also how can I create a file to compile all files?
Question by:jfeltus
    LVL 38

    Expert Comment

    Have a look at the following tutorial:

    Here's the totorials for *nix programming:
    LVL 11

    Accepted Solution

    maybe what you need is a "Make tutorial"
    LVL 1

    Assisted Solution

    I suppose your main program is 'main.cpp' and your 2 functions are in the files 'celsius.cpp' and 'farenheit.cpp' respectively and the celsius.h and farenheit.h for the prototype functions. If your program is C++ then you have to use 'c++' command, and if your proram is C then you can use 'cc' command,

    To compile each file to an object file,
    $ c++ -c celsius.cpp         => Automatically create celsius.o
    $ c++ -c farenheit.cpp   => Automatically create farenheit.o
    $ c++ -c main.cpp  => Automatically create main.o

    To link to the executable file,
    $ c++ celsius.o farenheit.o main.o -o main => Create the executable file main

    To create a file that automatically does the process above, create a new file called 'Makefile' or 'makefile' (Remember that the filename must be the same). The content of the file is below

    all:      main

    celsius.o:      celsius.c celsius.h
          c++ -c celsius.c

    farenheit.o:      farenheit.c farenheit.h
            c++ -c farenheit.c

    main.o:     main.c
           c++ -c main.c

    main:      celsius.o farenheit.o main.o
          c++ celsius.o farenheit.p main.o -o main

          rm *.o main

    Then just type 'make' to compile all the files, and type 'make clean' to delete all the files .o and main program.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
    The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now