LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-19-2009, 10:44 PM   #1
vendtagain
Member
 
Registered: Sep 2009
Distribution: Slackware, Debian, Mac OS X, Zenwalk, Puppy, Gentoo
Posts: 199

Rep: Reputation: 32
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?
 
Old 09-19-2009, 11:23 PM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
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

Last edited by jhwilliams; 09-19-2009 at 11:26 PM.
 
Old 09-20-2009, 12:25 AM   #3
vendtagain
Member
 
Registered: Sep 2009
Distribution: Slackware, Debian, Mac OS X, Zenwalk, Puppy, Gentoo
Posts: 199

Original Poster
Rep: Reputation: 32
I have attempted using "make" a few times now, with no success
 
Old 09-20-2009, 08:08 PM   #4
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
Quote:
Originally Posted by vendtagain View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with script to organise files into folders as part of DVD backup script jasybee2000 Linux - Newbie 5 06-15-2009 08:29 PM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 09:40 AM
set variables in a bash script; ansi PS1 color script donnied Programming 4 11-21-2007 12:33 PM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 10:10 PM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 05:21 PM


All times are GMT -5. The time now is 10:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration