List Info

Thread: c and C++ source files in one makefile




c and C++ source files in one makefile
country flaguser name
India
2008-05-05 05:38:57
I need to make c or c++ source files into object files and then include both for a library. 

Below is the way srcs and objects get defined.  How do get foo.o and bar.o to combine to get the lib.

export SRCS = foo.cpp
         ;     bar.c

.SUFFIXES: .cpp  .c

ifeq ($(firstword $(suffix $(SRCS))),.cpp)
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:.cpp=.o))
else
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))
endif

$(OBJDIR)/%.o: %.cpp
&nbsp; &nbsp; $(CXX) $(COPTS) $(OSDEFINES) $(EXTRA_DEFINES) $(INCLUDES) -o $ -c $<

$(OBJDIR)/%.o: %.c
   ; $(CC) $(COPTS) $(OSDEFINES) $(EXTRA_DEFINES) $(INCLUDES) -o $ -c $<

$(SHARED_LIB): $(OBJS)
&nbsp; &nbsp; $(CXX) $(SHLDFLAGS) $(OBJS) $(LDFLAGS) $(LIBS) $(SYSLIBS) -o $(OBJDIR)/$
 &nbsp;  $(CP) $(OBJDIR)/$ $(PRJLIB)

Rupal Desai





Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
Re: c and C++ source files in one makefile
country flaguser name
United States
2008-05-05 11:25:20
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rupal,

Once you've compiled C or C++ source files in to object
files, the
linker can't really tell the difference between them -
they're both
object files. The only differences will (probably) be the
export
signatures - that is, C++ symbols will be exported in the
usual C++
mangled form, while C symbols will be unmangled. But if you
export
public symbols using "extern C", then there'll be
even less differences
between the two.

BTW, I assume you're creating a SHARED library, and not a
STATIC
library. To create a static library, you use the ar utility
to just
combine object files into a static archive. To create a
shared library,
you'd use the linker (ld) to link your object files together
into a
shared object.

To build a shared object, just pass the "-shared"
flag to the $(CXX)
tool (usually gcc). Also pass any additional libraries
needed to resolve
symbols, and use the "-o" option to specify the
output library name.

John

rupal.desai wrote:
> I need to make c or c++ source files into object files
and then include both for a library.  
> 
> Below is the way srcs and objects get defined.  How do
get foo.o and bar.o to combine to get the lib.
> 
> export SRCS = foo.cpp 
>               bar.c
> 
> .SUFFIXES: .cpp  .c
> 
> ifeq ($(firstword $(suffix $(SRCS))),.cpp)
> OBJS := $(addprefix $(OBJDIR)/, $(SRCS:.cpp=.o))
> else
> OBJS := $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))
> endif
> 
> $(OBJDIR)/%.o: %.cpp
>     $(CXX) $(COPTS) $(OSDEFINES) $(EXTRA_DEFINES)
$(INCLUDES) -o $ -c $<
> 
> $(OBJDIR)/%.o: %.c
>     $(CC) $(COPTS) $(OSDEFINES) $(EXTRA_DEFINES)
$(INCLUDES) -o $ -c $<
> 
> $(SHARED_LIB): $(OBJS)
>     $(CXX) $(SHLDFLAGS) $(OBJS) $(LDFLAGS) $(LIBS)
$(SYSLIBS) -o $(OBJDIR)/$
>     $(CP) $(OBJDIR)/$ $(PRJLIB)
> 
> Rupal Desai
> 
> 
> 
> 
> 
>        
> ---------------------------------
> Be a better friend, newshound, and know-it-all with
Yahoo! Mobile.  Try it now.
> 
> 
>
------------------------------------------------------------
------------
> 
> _______________________________________________
> Help-make mailing list
> Help-makegnu.org
> http:
//lists.gnu.org/mailman/listinfo/help-make

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org


iD8DBQFIHzTwdcgqmRY/OH8RAuvKAKCW6j0INaSyeiS/krMl7YB/Y27rDACd
ENPx
nUESK/StlFWcUIeSs/E/6/8=
=OFAe
-----END PGP SIGNATURE-----


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )