compile program?

This is a discussion on compile program? within the C++ Programming forums, part of the General Programming Boards category; Ok, 1 question (this one is more from my lazyness...), im on a linux computer and whenever i want to ...

  1. #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

  2. #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

  3. #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.

  4. #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

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    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.

  6. #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

  7. #7
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    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.

  8. #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

  9. #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.

  10. #10
    #include<xErath.h> xErath's Avatar
    Join Date
    Jun 2004
    Posts
    722
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

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

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