C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-22-2005, 12:12 PM   #1
------------
 
Join Date: Jun 2005
Posts: 79
compile program?

Ok, 1 question (this one is more from my lazyness...), im on a linux computer and whenever i want to compile a program i have to type:
c++ (program name.cpp) -o (program name) -Wall -O2
just to compile it and wanted to know if there was a program that cam automatically make it so when i type something like:
compile (program.cpp)
it automatically adds in the extra info? i know it can be coded in c++ but i dont know how to do that yet and wanted to know if there was one already written?
__________________
CAUTION: Newbie at programming!
-------------------------------------------------
Thanks everyone who helped me with all the questions, and utter lost-ness i happen to have... it is VERY VERY much appreciated
Goosie is offline   Reply With Quote
Old 06-22-2005, 12:19 PM   #2
Registered User
 
mitakeet's Avatar
 
Join Date: Jun 2005
Location: Maryland, USA
Posts: 212
echo "c++ (program name.cpp) -o (program name) -Wall -O2" > batch.sh
chmod 700 batch.sh
./batch.sh

Or learn to make 'make' files.
__________________

Free code: http://sol-biotech.com/code/.

It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
--Me, I just made it up

The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
--George Bernard Shaw
mitakeet is offline   Reply With Quote
Old 06-22-2005, 01:08 PM   #3
Registered User
 
Join Date: Mar 2002
Posts: 1,595
You could always download the latest version of Dev-C++. It's an Integrated Development Environment (IDE), which is a fancy way of saying you don't need to use command line statements, do your own linking, etc. You just select the type of project you want to work on, write your code in the text editor, click the compile button, and if you don't get any errors, click the execute button and see if you get the desired behavior or a run time error. Works smooth as silk (well, most of the time anyway).

Oh, and did I mention; it's free.
__________________
You're only born perfect.
elad is offline   Reply With Quote
Old 06-22-2005, 01:24 PM   #4
------------
 
Join Date: Jun 2005
Posts: 79
I was thinking about using an IDE but i was told by a ton of people that it does some of the work for you other than compile, and makes you not do some of the work... I wanted to make sure that I actualy know how to do everything that my program is doing... its OK, i guess it isnt that bad to type that to compile a program...
__________________
CAUTION: Newbie at programming!
-------------------------------------------------
Thanks everyone who helped me with all the questions, and utter lost-ness i happen to have... it is VERY VERY much appreciated
Goosie is offline   Reply With Quote
Old 06-22-2005, 01:34 PM   #5
Registered User
 
Join Date: Apr 2003
Posts: 2,662
Quote:
OK, i guess it isnt that bad to type that to compile a program...
What are you learning by typing that every time?

Do you feel that using a card punch machine to make a stack of 1,000 punch cards representing your program, which you leave in the inbox at your computer center overnight, and then return the next day or maybe the day after that to get the results produced by your program when after the computer operator fed your punch cards into the computer would also teach you something?

Last edited by 7stud; 06-22-2005 at 01:40 PM.
7stud is offline   Reply With Quote
Old 06-22-2005, 01:36 PM   #6
------------
 
Join Date: Jun 2005
Posts: 79
nothing, but they said that the IDE's will add stuff to the program that I didnt put there. and by it doing that it might add something and I dont know how to do...
__________________
CAUTION: Newbie at programming!
-------------------------------------------------
Thanks everyone who helped me with all the questions, and utter lost-ness i happen to have... it is VERY VERY much appreciated
Goosie is offline   Reply With Quote
Old 06-22-2005, 01:40 PM   #7
Registered User
 
Join Date: Apr 2003
Posts: 2,662
Quote:
but they said
They also said UFO's land on Earth everyday.

I click on a compile button and a run button everytime I execute a C++ program, and yet I have still been able learn about pointers, classes, inheritance, and polymorphism.

Don't tell anyone, but I also use the following template for every program so I don't have to type it every time:
Code:
#include <iostream>
using namespace std;

int main()
{

     return 0;
}

Last edited by 7stud; 06-22-2005 at 01:46 PM.
7stud is offline   Reply With Quote
Old 06-22-2005, 01:49 PM   #8
------------
 
Join Date: Jun 2005
Posts: 79
UFO's do land on earth everyday! they stole my uncle...
well, i guess i might go and try one out
__________________
CAUTION: Newbie at programming!
-------------------------------------------------
Thanks everyone who helped me with all the questions, and utter lost-ness i happen to have... it is VERY VERY much appreciated
Goosie is offline   Reply With Quote
Old 06-22-2005, 01:58 PM   #9
myNegReal
 
Join Date: Jun 2005
Posts: 100
Dev-C++ is great, and like most IDE's, there's also Compile+Run buttons. As long as your program won't cause any compile time errors, click one buttons, it compiles and right after is automatically executed. I've always used IDE's never bothered with that command line compiling.
Ganoosh is offline   Reply With Quote
Old 06-22-2005, 02:26 PM   #10
#include<xErath.h>
 
xErath's Avatar
 
Join Date: Jun 2004
Posts: 724
you're in luck. I made a great makefile that compiles all source files it can find and link then in a final application. Currently it only works for *.cpp file.. I stil haven't added suport to mix *.c files...
here it is
Code:
DIRS := ./ src/
OBJDIR := obj/
EXE  = app

#all .cpp/.c
SRC := $(filter %.cpp, $(foreach DIR,$(DIRS),$(wildcard $(DIR)*.cpp) ))
#all headers with matching .cpp/.c
HDR := $(filter	$(foreach DIR, $(DIRS),$(wildcard $(DIR)*.h)),$(patsubst %.cpp,%.h,$(SRC)))
#all .o from a .cpp/.c
OBJ := $(foreach FOBJ,$(filter %.o, $(patsubst %.cpp,%.o,$(SRC))),$(OBJDIR)$(FOBJ) )
#all .h with matching .o
HOBJ := $(foreach FOBJ,$(filter %.o, $(patsubst %.h,%.o,$(HDR)) ),$(OBJDIR)$(FOBJ) )
#all .o without matching .h 
COBJ := $(filter-out $(HOBJ),$(OBJ))

FLAGS = -Wall

$(EXE): $(OBJ)
	$(CXX) $(FLAGS) $(OBJ) -o $(EXE)

$(HOBJ): $(OBJDIR)%.o: %.cpp %.h
	-@mkdir -p $(OBJDIR)$(dir $(filter %.cpp, $^))
	@touch -a $@
	$(CXX) $(FLAGS) -c $(filter %.cpp, $^) -o $@

$(COBJ): $(OBJDIR)%.o: %.cpp
	-@mkdir -p $(OBJDIR)$(dir $<)
	@touch -a $@
	-$(CXX) $(FLAGS) -c $< -o $@

#clean
.PHONY : c clean
c clean: 
	@echo cleaning temporaries
	-@rm -f $(EXE) $(OBJ) $(foreach DIR,$(DIRS),$(DIR)*.bak "$(DIR)*.*~" )
	-@rmdir -p --ignore-fail-on-non-empty $(filter-out $(OBJDIR)./,$(foreach DIR,$(DIRS),$(OBJDIR)$(DIR) ))
just save this file as 'makefile' and place it in you source directory.
To compile just write 'make' at the commad prompt.
Add/remove directories to the DIRS variable to mntion where your code is
Change EXE variable to your liking. That's the exeutable final name
xErath is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Program Plan Programmer_P C++ Programming 0 05-11-2009 01:42 AM
Compile Public Domain Pocket PC C Program m1l Projects and Job Recruitment 2 07-20-2007 04:02 AM
Using variables in system() Afro C Programming 8 07-03-2007 12:27 PM
new to C--can't get program to compile samerune C Programming 12 04-02-2007 09:44 AM
how do i compile a program that deals w/classes? Shy_girl_311 C++ Programming 5 11-11-2001 02:32 AM


All times are GMT -6. The time now is 11:32 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22