LinuxQuestions.org
Visit Jeremy's Blog.
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-25-2014, 07:34 PM   #1
swamprat
Member
 
Registered: Sep 2005
Location: New Jersey, (Which Exit LOL), USA
Distribution: Centos 6.7 Under VMware in Win7
Posts: 473

Rep: Reputation: 34
C Program Compiles and Library PATHS


Greetings, I have to write a few C programs.

I would like to keep the source code in libaryA, The compiled object code in libraryB (before the Make) the object code after the Make in libraryC and a completed module (program) ready to execute in libraryD. The reason for all of this is for production control purposes.

I would like your advise in the best way to do this and would like to know if it's possible to do all of this and how to use The GCC command to do all of this.

Is it advisable to add all the libraries listed above to my PATH statement for my initial testing or is there some other recommended way to do this.

Your help is appreciated. Thanks

Using CentOS 6.3
 
Old 09-26-2014, 12:03 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,711
Blog Entries: 12

Rep: Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973
While GCC would be involved, you'd need to do this with a Makefile.

Here's a sample Makefile which comes close; however when I tried to use different object sub-directories, it had problems with the definition strings for those sub-directory references. It however does work to compile in the main directory and then from there in the "make install" you can move files to the locations you wish them to be in. Where it ran into trouble was when I tried to say that the objects would be in a sub-directory. The Makefile is like a shell script, but make has more stringent syntax restrictions; for instance those indentations absolutely MUST be TAB characters, not 8 SPACES. So my assumption is that the notations for sub-directories in the view of make must be different from what a bash script accepts. Hope this helps you to get started.
Code:
#!/bin/sh
# Sample Makefile

START=`pwd`
OBJA=$(START)/obja
OBJB=$(START)/objb
IMAGE=$(START)/image

CFLAGS= -I.

DFLAGS=

#OBJS= $(OBJA)/signed.o
OBJS= signed.o

GCC= /usr/bin/gcc

%.o:	%.c
	$(GCC) $(CFLAGS) $(DFLAGS) -c $<

rebuild:
	make clean
	make signed
	make install

signed:	$(OBJS)
	$(GCC) $(OBJS) $(LFLAGS) -o wandd

install:
	cp -f $(OBJS) $(OBJB)/.
	cp -f signed $(IMAGE)/.

clean:
	rm -f $(OBJB)/*
	rm -f $(OBJS)
	rm -f $(IMAGE)/signed
 
1 members found this post helpful.
Old 09-30-2014, 09:30 AM   #3
swamprat
Member
 
Registered: Sep 2005
Location: New Jersey, (Which Exit LOL), USA
Distribution: Centos 6.7 Under VMware in Win7
Posts: 473

Original Poster
Rep: Reputation: 34
Thanks Mistler...Being a newbie at this I'm guess I'll just compile the C code and move the executable to a different production directory.
 
  


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
Program compiles and runs on 12.0-32 compiles on 14.0-64 but won't run. stf92 Slackware 6 01-23-2014 06:43 AM
Simple C++ Program: Program Compiles But Won't Run (Segmentation Fault) violagirl23 Programming 3 01-09-2008 12:09 AM
Runtime problem with library paths v8dave Slackware 0 12-30-2004 06:45 PM
kde library paths redjokerx Programming 9 11-28-2004 04:26 PM
G++ compiles fine but program does not work MaddDog696 Programming 3 04-15-2004 05:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:33 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