LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   script (https://www.linuxquestions.org/questions/linux-newbie-8/script-756480/)

vendtagain 09-19-2009 09:44 PM

script
 
I have about 30 .cpp and .h files which i moved to my linux box. I'm looking to write a script to compile and link these together into an executable possibly using loop..*.cpp *.h . (so I dont have to type all of them out). any ideas?

jhwilliams 09-19-2009 10:23 PM

Note: the correct way to aproach this would be to write a Makefile and build the software with GNU make. However, here's a short script which accomplishes what you request, assuming that all of the cpp/h files are in the same directory:

Code:

#!/bin/bash

exeuctable="name_of_executable"

for source in *.cpp; do
  g++ -c $source
done

g++ *.o -o $executable


vendtagain 09-19-2009 11:25 PM

I have attempted using "make" a few times now, with no success

jhwilliams 09-20-2009 07:08 PM

Quote:

Originally Posted by vendtagain (Post 3690239)
I have attempted using "make" a few times now, with no success

Yea, I'd believe that. Here's my 30-second Makefile howto (below is a makefile)

Code:

all: executable_name
exeutable_name: cfile1.c cfile2.c cfile3.c
clean:
        rm -f *.o executable_name

in your case, just do an ls *.c, and then copy that list after the "executable-name", which you'll probably want to change to something more interesting anyway.


All times are GMT -5. The time now is 03:21 AM.