Makefile for g++

Hi All,

We have moved our OS from Sun Solaris to Linux and also some of the compilers.
Our old makefile used to be as below:

CC=cc
FLAGS=-G -KPIC -DLG_SOLARIS_OS
DEFINES=-DSunOS
SYSLIBS=-lc
.SUFFIXES : .c
.c.o : ;$(CC) -c $(FLAGS) $(DEFINES) $*.c -o $*.o

TARGET=libBnkgIMDFIDSModelExecution.so

OBJS=$(SRCS:%.c=%.o)

SRCS= \
C0001apc.c \
 C0001bdc.c \
 C0001bfc.c \
 C0001bnc.c \
 C0001bsc.c \
 C0001buc.c \
 C0001chc.c \
 C0001cpc.c \
 C0001fnc.c \
 C0001gcc.c \
 C0001gvc.c \
 C0001utc.c

all : $(TARGET)

$(TARGET) : $(OBJS)
        CC -o $(TARGET) -G -mt $(OBJS) $(SYSLIBS)

Can you please let me know how to create one using g++ compiler?
I tried different things but getting an error.

Thanks
Shash

Your makefile is specifying that the compiler is to be used to compile code to run on Solaris systems and is telling the compiler to predefine the macro SunOS before compiling any of the source files used to build your project.

If you are hoping to build your project on a Linux system creating object files that will run on Solaris/SunOS systems, I don't think that will work unless Linux has recently added some cross-compilation environments that I have seen advertised.

If you are hoping to build your project to run on a Linux system as well as to be built on a Linux system, you will need to examine each of the source files in your project to find out what macros need to be predefined so that they will build correctly in your specific Linux environment instead of in the Solaris/SunOS environment your makefile specifies. If your code does not have #ifdef statements to select appropriate alternatives to SunOS specific segments of your code, you will need to modify those source files to #ifdef code in for your new environment and add the macros that your modified source uses by changing the line in your makefile from:

DEFINES=-DSunOS

to instead define the macros your sources files expect when building your project to run in your specific Linux environment as well as changing the two lines at the top of your makefile :

CC=cc
FLAGS=-G -KPIC -DLG_SOLARIS_OS

to:

CC=gcc

and set FLAGS to whatever options are appropriate for gcc in your environment for the type of code you're trying to build.

Thanks for the reply Don Cragun. Apologies, I 'm not into C programming.
The code does have #ifdef in one of the .c file. Can you please let me know how to determine the flags/macros to be used.

Not without:

  1. seeing the code,
  2. knowing complete details about the environment in which you plan to build your software,
  3. and complete details about the environment(s) in which you plan to run your software.

If your source code is depending on Solaris C library features and doesn't already include #ifdefs to use alternative glibc interfaces for general Linux systems or distribution specific libraries for the particular Linux system(s) you have decided to use instead of Solaris/SunOS, just changing macros in your makefile is not going to work. You have to actually write C source code that will work in your new, different environment(s).