[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

linux c++ programming

Posted on 2004-11-09
5
Medium Priority
?
253 Views
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?
0
Comment
Question by:jfeltus
3 Comments
 
LVL 38

Expert Comment

by:yuzh
ID: 12540541
Have a look at the following tutorial:
http://users.actcom.co.il/~choo/lupg/tutorials/c-on-unix/c-on-unix.html

Here's the totorials for *nix programming:
http://users.actcom.co.il/~choo/lupg/tutorials/
0
 
LVL 11

Accepted Solution

by:
avizit earned 1000 total points
ID: 12540951
maybe what you need is a "Make tutorial"

http://www.eng.hawaii.edu/Tutor/Make/
0
 
LVL 1

Assisted Solution

by:okidachi
okidachi earned 1000 total points
ID: 12655961
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

clean:
      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.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month17 days, 21 hours left to enroll

829 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