User forums > Help

How to setup for G++

(1/4) > >>

DanW_58:
There are many compilers in the list, including GCC;  but G++ I cannot see;  and I know I have it installed...

EDIT:  Also, could someone recommend a link where I can read how to make a makefile?  I tried to make
one from an example I found in Stack Overflow, but now the compiler says there are no instructions for
how to build a Debug target.  I want life to be easy...

EDIT2:  A set of official makefile examples would be nice;  in fact, why can't the setup write a basic makefile that one can then modify as needed?  The example I found in Stack Overflow has gazillions of arguments I have no idea what they are for, namely, this is what it is with my renaming of files from the example:


--- Code: ---DL3D: DL3D.o math/numrepr.o
g++ -g -o DL3D DL3D.o math/numrepr.o -L/sw/lib/root -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint \
-lPostscript -lMatrix -lPhysics -lMathCore -lThread -lz -L/sw/lib -lfreetype -lz -Wl,-framework,CoreServices \
-Wl,-framework,ApplicationServices -pthread -Wl,-rpath,/sw/lib/root -lm -ldl

DL3D.o: DL3D.cpp math/numrepr.h
g++ -g  -c -pthread -I/sw/include/root DL3D.cc

math/numrepr.o: math/numrepr.h math/numrepr.cpp
g++ -g -c -pthread -I/sw/include/root math/numrepr.cpp

--- End code ---

but I have no idea what those libraries, if they are libraries, are, or weather I need them.
I understand that Code Blocks is just an environment;  but it would be a nice little extra...
Or, could someone recommend a GUI tool I could use to generate a makefile?

UPDATE:  Found cbp2make and used it to get an initial makefile.
I'm now in the process of learning to understand the format and customizing it.
The main problem is my project was not properly set up;  I had a math cpp file that my main.cpp needed, but
creating the file in CB doesn't add it to the project necessarily;  so cbp2make read the project file and re-created
the problem I had.
Another bug in cbp2make is it names the targets in lowercase;  CB expects them capitalized.  Another problem
is it assumes the main file is named "main.cpp", which for me wasn't true;  I had renamed it to DL3D.cpp.
 So, but I managed to add the math file to the make.

This is what my makefile looks like so far:


--- Code: ---#------------------------------------------------------------------------------#
# This makefile was generated by 'cbp2make' tool rev.147                       #
#------------------------------------------------------------------------------#

WORKDIR = `pwd`

CC = g++
CXX = g++
AR = ar
LD = g++
WINDRES = windres

INC =
CFLAGS = -Wall
RESINC =
LIBDIR =
LIB = -lGL -lX11
LDFLAGS = -L/sw/lib/root

INC_DEBUG = $(INC)
CFLAGS_DEBUG = $(CFLAGS) -g
RESINC_DEBUG = $(RESINC)
RCFLAGS_DEBUG = $(RCFLAGS)
LIBDIR_DEBUG = $(LIBDIR)
LIB_DEBUG = $(LIB)
LDFLAGS_DEBUG = $(LDFLAGS)
OBJDIR_DEBUG = obj/Debug
DEP_DEBUG =
OUT_DEBUG = bin/Debug/DL3D

INC_RELEASE = $(INC)
CFLAGS_RELEASE = $(CFLAGS) -O2
RESINC_RELEASE = $(RESINC)
RCFLAGS_RELEASE = $(RCFLAGS)
LIBDIR_RELEASE = $(LIBDIR)
LIB_RELEASE = $(LIB)
LDFLAGS_RELEASE = $(LDFLAGS) -s
OBJDIR_RELEASE = obj/Release
DEP_RELEASE =
OUT_RELEASE = bin/Release/DL3D

OBJ_DEBUG = $(OBJDIR_DEBUG)/DL3D.o $(OBJDIR_DEBUG)/num_repr.o

OBJ_RELEASE = $(OBJDIR_RELEASE)/DL3D.o $(OBJDIR_RELEASE)/num_repr.o

all: debug release

clean: clean_debug clean_release

before_debug:
test -d bin/Debug || mkdir -p bin/Debug
test -d $(OBJDIR_DEBUG) || mkdir -p $(OBJDIR_DEBUG)

after_debug:

Debug: before_debug out_debug after_debug

out_debug: before_debug $(OBJ_DEBUG) $(DEP_DEBUG)
$(LD) $(LIBDIR_DEBUG) -o $(OUT_DEBUG) $(OBJ_DEBUG)  $(LDFLAGS_DEBUG) $(LIB_DEBUG)

$(OBJDIR_DEBUG)/DL3D.o: DL3D.cpp
$(CC) $(CFLAGS_DEBUG) $(INC_DEBUG) -c DL3D.cpp -o $(OBJDIR_DEBUG)/DL3D.o

$(OBJDIR_DEBUG)/num_repr.o: math/num_repr.cpp
$(CC) $(CFLAGS_DEBUG) $(INC_DEBUG) -c math/num_repr.cpp -o $(OBJDIR_DEBUG)/num_repr.o

clean_debug:
rm -f $(OBJ_DEBUG) $(OUT_DEBUG)
rm -rf bin/Debug
rm -rf $(OBJDIR_DEBUG)

before_release:
test -d bin/Release || mkdir -p bin/Release
test -d $(OBJDIR_RELEASE) || mkdir -p $(OBJDIR_RELEASE)

after_release:

Release: before_release out_release after_release

out_release: before_release $(OBJ_RELEASE) $(DEP_RELEASE)
$(LD) $(LIBDIR_RELEASE) -o $(OUT_RELEASE) $(OBJ_RELEASE)  $(LDFLAGS_RELEASE) $(LIB_RELEASE)

$(OBJDIR_RELEASE)/DL3D.o: DL3D.cpp
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c DL3D.cpp -o $(OBJDIR_RELEASE)/DL3D.o

$(OBJDIR_RELEASE)/num_repr.o: math/num_repr.cpp
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c math/num_repr.cpp -o $(OBJDIR_RELEASE)/num_repr.o

clean_release:
rm -f $(OBJ_RELEASE) $(OUT_RELEASE)
rm -rf bin/Release
rm -rf $(OBJDIR_RELEASE)

.PHONY: before_debug after_debug clean_debug before_release after_release clean_release

--- End code ---

It works as far as compiling the two files;  but the linker tells me that all the functions from the math file
are undefined...   :(

By the way, my first question still stands;  why is there not G++ in the list of compilers to choose from?
I even changed the first definition in the make file from "CC = gcc" to "CC = g++", to try and force it to
use G++, but the compiler output still announces itself as GCC...  ::)

DanW_58:
Could someone PLEASE help?!
Why does G++ not show in the list of compilers?
I also want to understand the purpose and relation between the cbp file and the makefile:  I used cbp2make yesterday, but if the cbp is not right it makes a makefile that is not right;  so how do I fix the cbp file in the first place?  How do I tell it what files to compile and link?  I edited the cbp manually to add my other cpp file;  but it is not linking them together.  Is this a programming question?  I don't think it is.

Miguel Gimenez:
G++ is part of GCC. C::B will use GCC for .c files and G++ for .cpp files (see Toolchain executables in Settings -> Compiler).

If you want to add files to the CBP project just right-click on the name of the project and select "Add files...".

You don't need makefiles when working with C::B, but if you need to use one then you can check "This is a custom Makefile" in Project/target options -> Project settings.

DanW_58:
Ah, okay;  many thanks;  I was having a compile problem that I found an answer for saying "I had the same problem with GCC;  just switch to G++", so I thought they were separate compilers.
I have the "This is a custom makefile" check on.
I will try removing the makefile and using "add files", though I have a feeling I already tried that before.

DanW_58:
Okay, I removed the makefile, and I added my two .cpp files with right-click Add Files...;  but when I try to build project I get "No input files".

Navigation

[0] Message Index

[#] Next page

Go to full version