Re: Using gcc
Re: Using gcc
- Subject: Re: Using gcc
- From: Danny Swarzman <email@hidden>
- Date: Fri, 28 Nov 2003 18:11:03 -0800
On Nov 28, 2003, at 1:11, Alastair Houghton wrote:
On 28 Nov 2003, at 01:57, Danny Swarzman wrote:
I want to compile a program to run as cgi using gcc. I have it
working with project builder but I need to be able to move it to
another unix. There are a lot of options for gcc. My case is simple,
maybe someone has done it.
I have one source file, main.cpp. I use standard libraries. Nothing
special.
This doesn't seem to be a Cocoa-related question. However, seeing as
it's pretty simple...
I guess it's off topic. Sorry.
Anyway, I found the answer is simple:
c++ -o objectCodeFileName main.cpp
That invokes gcc with the right libraries to use std.
-Danny
What you should really do is create a simple Makefile, the contents of
which should look something like:
# Makefile for my-cgi-program
CXXFLAGS=-g -W -Wall
SRCS=main.cpp
OBJS=$(SRCS:.cpp=.o)
.PHONY: all clean
all: my-cgi-program
clean:
$(RM) my-cgi-program $(OBJS)
my-cgi-program: $(OBJS)
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
# If you have any other files (e.g. header files) on which main.o
depends, then you
# should add a rule to list them; Make will figure-out the
dependency between main.o
# and main.cpp automatically. e.g.
#
# main.o: main.cpp my-header-file.h my-other-header.h
Then you can just go to the directory containing Makefile and main.cpp
and type "make" at a prompt. The major advantage over just running
the compiler directly from the shell is that the Makefile records all
of the settings you want enabled for your program. The above Makefile
just enables debug symbols and all warnings; you might also want to
enable the optimiser (-Os is a reasonable choice on most platforms),
but that's up to you.
A few other quick comments:
1. ".cpp" isn't the standard extension for C++ code on UNIX. It came
from Windows, and, until fairly recently, wasn't supported even by
GCC. If you're using a non-GNU variant of make or a different
compiler (even an older version of GCC), you might have more luck if
you rename your file to "main.cc". (The reason people sometimes have
problems is that ".cpp" used to be used for preprocessed C code, not
C++.)
2. You might find that using GNU make works better than the vendor's
make on whichever platform you're using; sometimes it's installed as
"gmake", rather than "make".
3. If you need to add include paths, add a line that says
"CPPFLAGS=-I<path> -I<other path>".
4. If you need to add linker flags, put them in LDFLAGS. Similarly,
add libraries to LDLIBS.
Kind regards,
Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: | |
| >Using gcc (From: Danny Swarzman <email@hidden>) |
| >Re: Using gcc (From: Alastair Houghton <email@hidden>) |