LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   C Program Compiles and Library PATHS (https://www.linuxquestions.org/questions/linux-newbie-8/c-program-compiles-and-library-paths-4175520092/)

swamprat 09-25-2014 07:34 PM

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

rtmistler 09-26-2014 12:03 PM

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


swamprat 09-30-2014 09:30 AM

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.


All times are GMT -5. The time now is 10:00 AM.