Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I have a program consists of header files, .cpp, .c, a Makefile and need to include the problem instances file (.tim). May i know how to compile and run ...
  1. #1
    Just Joined!
    Join Date
    Aug 2010
    Posts
    3

    Command make

    Hi,

    I have a program consists of header files, .cpp, .c, a Makefile and need to include the problem instances file (.tim).

    May i know how to compile and run them? From google, i have heard bout the command make. But i have no idea how. Please kindly help..

    Thanks..

    Regards,
    limeng

  2. #2
    Just Joined!
    Join Date
    May 2008
    Location
    Bangalore, India
    Posts
    24
    say you have yourfile.c
    compile it
    gcc -c yourfile.c
    gcc -o yourfile yourfile.o

    you can have make file like

    Makefile
    Code:
    INCLUDES="-I."
    
    yourfile: yourfile.o
       gcc -o yourfile yourfile.o
    
    yourfile.o: yourfile.c
       gcc -c yourfile.c $(INCLUDES)

  3. #3
    Just Joined!
    Join Date
    Aug 2010
    Posts
    3
    Thanks a lot for replying, sanjeevt!

    May i know is there any difference if i compile .cpp using gcc or g++?

    When i type gcc -o myfile myfile.c, it caused an error saying Undefined reference to 'main'. I think it's because the main is in the .cpp file.

    The "yourfile.c" of mine is the Timer.C file to get the program running time whereby the main is in the ts.cpp file. But somehow when i try to follow the steps u've mentioned on ts.cpp, errors occurs.

  4. #4
    Just Joined!
    Join Date
    May 2008
    Location
    Bangalore, India
    Posts
    24
    gcc is supposed to be for c, and g++ for cpp
    but gcc uses g++ internally for cpp programs

    what errors you are getting.

    do gcc -c timer.c
    gcc -c myfile.c

    it will create timer.o, which is object file then link it
    gcc -o myfile myfile.o timer.o

  5. #5
    Just Joined!
    Join Date
    Aug 2010
    Posts
    3
    [lmsiew2@localhost timetabling.ts.ch.1]$ gcc -c Timer.C
    [lmsiew2@localhost timetabling.ts.ch.1]$ gcc -c ts.cpp
    ts.cpp:9: error: expected initializer before ‘*’ token
    ts.cpp: In function ‘int main(int, char**)’:
    ts.cpp:15: error: ‘outs’ was not declared in this scope
    ts.cpp:15: error: ‘class Control’ has no member named ‘os’
    ts.cpp:18: error: ‘class Control’ has no member named ‘getInputStream’

    Below is the main file, ts.cpp:
    #include "Control.h"
    #include "Problem.h"
    #include "Solution.h"
    #include "Random.h"

    #include <fstream>

    Random* rnd;
    extern ostream *outs;

    int main( int argc, char** argv) {

    // create a control object from the command line arguments
    Control control(argc, argv);
    outs = control.os;

    // create a problem, control tells you what input file stream to use
    Problem *problem = new Problem(control.getInputStream());

    // create a Random object
    rnd = new Random((unsigned) control.getSeed());

    // run a number of tries, control knows how many tries there should be done
    while( control.triesLeft())
    {
    // tell control we are starting a new try
    control.beginTry();

    // initialize a random solution
    Solution *currentSolution = new Solution(problem, rnd);
    currentSolution->RandomInitialSolution();
    currentSolution->computeHcv();
    if(currentSolution->hcv == 0)
    {
    control.setCurrentCost(currentSolution);
    }else
    {
    control.setCurrentCost(currentSolution);
    }

    //apply tabu search with paramters given by control for a time limit and probability of each type of move to be performed
    currentSolution->tabuSearch(control.getTimeLimit(), control.alfa, control.prob1, control.prob2);
    currentSolution->computeHcv();
    if(currentSolution->hcv == 0)
    currentSolution->computeScv();

    control.endTry(currentSolution);
    delete currentSolution;
    }

    delete problem;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...