PDA

View Full Version : Having trouble compiling a C++ program in eclipse under OSX



Amablue
February 17th, 2009, 04:47 AM
I originally wrote a program called classparser in visual studio and it worked great. I'm migrating to OSX and Ubuntu and trying to get it to compile for those systems too. I made an eclipse project on my ubuntu machine and it worked fine after fixing it up a bit. I copied it to my macbook, and I can't get it to compile there. I'm also running eclipse on my macbook.

The problem I'm getting is that the makefile seems to be getting generated incorrectly. The error says "unknown option: -oclassparser". I'm sure there's supposed to be a space between the -o and classparser, but I have no idea why it's omitting it, nor do I know where to go to fix it.

dwhitney67
February 17th, 2009, 12:05 PM
It seems that you are more interested in getting Eclipse to work that you are with compiling your program. Since I'm not knowledgeable with Eclipse, I cannot help you with that.

However, if you open a terminal, and compile/link manually, at a minimum, something similar to the following should work:


g++ myprog.cpp -o myprog

When you open a terminal, if you source code is not in the current working directory, then 'cd' to the approriate directory.

P.S. GCC has numerous compiler flags that can be used to augment the capabilities of GCC. The ones I use most often are '-Wall -ansi -pedantic'. I have no evidence that the option '-oclassparser' exists. Perhaps you meant to specify '-o classparser' (note the white-space). Perhaps this is why the OSX complained.

Amablue
February 17th, 2009, 07:16 PM
Yes, this is more about getting eclipse to work than just compiling the program I probably should have included that in the topic title. It works in Ubuntu just fine. I literally copied the entire project over and it doesn't want to work :-(

As I said in my second paragraph, I'm aware -oclassparser isn't an option. It should be -o classparser, but the autogenerated makefile isn't spitting that out.

Since you bring up the command line though, I have a related question: How would I compile the program if there's more than just one .cpp and .h file in it? My program uses about 6 .cpps and their corresponding .h's

dwhitney67
February 17th, 2009, 10:26 PM
To compile multiple source files:


g++ file1.cpp file2.cpp ... file6.cpp -o myprog


or create and use a Makefile:


# Application name
APP = myprog

# List of source files
SRCS = File1.cpp File2.cpp ... File6.cpp

# Compiler flags
CXXFLAGS = -Wall -ansi -pedantic

# Edits below this line are generally not necessary

OBJS = $(SRCS:.cpp=.o)

# Define header file paths
INCPATH = -I./

# Define the -L library path(s)
LDFLAGS =

# Define the -l library name(s)
LIBS =

# The file name where to collect dependency info
DEP_FILE = .depend


.PHONY = all clean distclean


# Main entry point
#
all: depend $(APP)


# For linking object file(s) to produce the executable
#
$(APP): $(OBJS)
@echo Linking $@
@$(CXX) $^ $(LDFLAGS) $(LIBS) -o $@


# For compiling source file(s)
#
.cpp.o:
@echo Compiling $<
@$(CXX) -c $(CXXFLAGS) $(INCPATH) $<


# For cleaning up the project
#
clean:
$(RM) $(OBJS)

distclean: clean
$(RM) $(APP)
$(RM) $(DEP_FILE)


# For determining source file dependencies
#
depend: $(DEP_FILE)
@touch $(DEP_FILE)

$(DEP_FILE):
@echo Generating dependencies in $@
@-$(CXX) -E -MM $(CXXFLAGS) $(INCPATH) $(SRCS) >> $(DEP_FILE)

ifeq (,$(findstring clean,$(MAKECMDGOALS)))
ifeq (,$(findstring distclean,$(MAKECMDGOALS)))
-include $(DEP_FILE)
endif
endif

Amablue
February 18th, 2009, 03:04 AM
Thanks, I'll just make the make file manually for now.

It'd be nice if I could figure out what the problem with Eclipse is though.