[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: c and C++ source files in one makefile
From: |
John Calcote |
Subject: |
Re: c and C++ source files in one makefile |
Date: |
Mon, 05 May 2008 10:25:20 -0600 |
User-agent: |
Thunderbird 2.0.0.12 (X11/20080226) |
-----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
> address@hidden
> 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/Y27rDACdENPx
nUESK/StlFWcUIeSs/E/6/8=
=OFAe
-----END PGP SIGNATURE-----