I'm trying to compile this piece of software called Register3D_wx but have problems when trying to run make. I have installed Open GSL, Open GL and wxWidgets library as required. When I cd into the folder and run make, I get lots of error messages. I'm giving some of the output:
james#james-HP-Z420-Workstation:~/Downloads/Register3D_wx_1.1.1$ sudo make
test -d bin/Release || mkdir -p bin/Release
test -d obj/Release/ann_1.1.2/src || mkdir -p obj/Release/ann_1.1.2/src
test -d obj/Release/ || mkdir -p obj/Release/
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/kd_pr_search.cpp -o obj/Release/ann_1.1.2/src/kd_pr_search.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ZPR.cc -o obj/Release/ZPR.o
ZPR.cc: In member function ‘void ZPR::ZprPick(GLdouble, GLdouble, GLdouble, GLdouble)’:
ZPR.cc:424:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (buffer[j+1]<minZ)
^
ZPR.cc:380:11: warning: variable ‘min’ set but not used [-Wunused-but-set-variable]
GLint min = -1;
^
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/ANN.cpp -o obj/Release/ann_1.1.2/src/ANN.o
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/bd_fix_rad_search.cpp -o obj/Release/ann_1.1.2/src/bd_fix_rad_search.o
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/bd_pr_search.cpp -o obj/Release/ann_1.1.2/src/bd_pr_search.o
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/bd_search.cpp -o obj/Release/ann_1.1.2/src/bd_search.o
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/bd_tree.cpp -o obj/Release/ann_1.1.2/src/bd_tree.o
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/brute.cpp -o obj/Release/ann_1.1.2/src/brute.o
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/kd_dump.cpp -o obj/Release/ann_1.1.2/src/kd_dump.o
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/kd_fix_rad_search.cpp -o obj/Release/ann_1.1.2/src/kd_fix_rad_search.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c PointOP.cc -o obj/Release/PointOP.o
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/kd_search.cpp -o obj/Release/ann_1.1.2/src/kd_search.o
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/kd_split.cpp -o obj/Release/ann_1.1.2/src/kd_split.o
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/kd_tree.cpp -o obj/Release/ann_1.1.2/src/kd_tree.o
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/kd_util.cpp -o obj/Release/ann_1.1.2/src/kd_util.o
g++ -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ann_1.1.2/src/perf.cpp -o obj/Release/ann_1.1.2/src/perf.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c main.cc -o obj/Release/main.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c MainWindow.cc -o obj/Release/MainWindow.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c Cylinder.cc -o obj/Release/Cylinder.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c GLCanvas.cc -o obj/Release/GLCanvas.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c Help.cc -o obj/Release/Help.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ICP.cc -o obj/Release/ICP.o
ICP.cc: In member function ‘void ICP::SetPoints(std::vector<Point>&, std::vector<Point>&, float)’:
ICP.cc:439:73: warning: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<Point>::size_type {aka long unsigned int}’ [-Wformat=]
printf("Number of points after downsampling: %i\n", m_points2.size());
^
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c ICPDialog.cc -o obj/Release/ICPDialog.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c About.cc -o obj/Release/About.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c Math2.cc -o obj/Release/Math2.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c Matrix.cc -o obj/Release/Matrix.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c Misc.cc -o obj/Release/Misc.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c MyANN.cc -o obj/Release/MyANN.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c OGLWrapper.cc -o obj/Release/OGLWrapper.o
gcc -O2 -Wall `wx-config --cflags` `gsl-config --cflags` -Iann_1.1.2/include -c Point.cc -o obj/Release/Point.o
g++ -s `wx-config --libs` `wx-config --libs gl` `gsl-config --libs` -Lann_1.1.2/include obj/Release/ann_1.1.2/src/kd_pr_search.o obj/Release/ZPR.o obj/Release/ann_1.1.2/src/ANN.o obj/Release/ann_1.1.2/src/bd_fix_rad_search.o obj/Release/ann_1.1.2/src/bd_pr_search.o obj/Release/ann_1.1.2/src/bd_search.o obj/Release/ann_1.1.2/src/bd_tree.o obj/Release/ann_1.1.2/src/brute.o obj/Release/ann_1.1.2/src/kd_dump.o obj/Release/ann_1.1.2/src/kd_fix_rad_search.o obj/Release/PointOP.o obj/Release/ann_1.1.2/src/kd_search.o obj/Release/ann_1.1.2/src/kd_split.o obj/Release/ann_1.1.2/src/kd_tree.o obj/Release/ann_1.1.2/src/kd_util.o obj/Release/ann_1.1.2/src/perf.o obj/Release/main.o obj/Release/MainWindow.o obj/Release/Cylinder.o obj/Release/GLCanvas.o obj/Release/Help.o obj/Release/ICP.o obj/Release/ICPDialog.o obj/Release/About.o obj/Release/Math2.o obj/Release/Matrix.o obj/Release/Misc.o obj/Release/MyANN.o obj/Release/OGLWrapper.o obj/Release/Point.o -lz -lGLEW -lGL -lglut -o bin/Release/Register3D_wx
obj/Release/ICP.o: In function `ICP::SetPoints(std::vector<Point, std::allocator<Point> >&, std::vector<Point, std::allocator<Point> >&, float)':
ICP.cc:(.text+0x38c): undefined reference to `wxStringBase::npos'
ICP.cc:(.text+0x3a4): undefined reference to `wxStringBase::InitWith(wchar_t const*, unsigned long, unsigned long)'
ICP.cc:(.text+0x49a): undefined reference to `wxString::Format(wchar_t const*, ...)'
ICP.cc:(.text+0x593): undefined reference to `wxStringBase::npos'
ICP.cc:(.text+0x5ab): undefined reference to `wxStringBase::InitWith(wchar_t const*, unsigned long, unsigned long)'
ICP.cc:(.text+0x614): undefined reference to `wxString::Format(wchar_t const*, ...)'
ICP.cc:(.text+0x6d9): undefined reference to `wxStringBase::npos'
ICP.cc:(.text+0x6f1): undefined reference to `wxStringBase::InitWith(wchar_t const*, unsigned long, unsigned long)'
ICP.cc:(.text+0x7da): undefined reference to `wxString::Format(wchar_t const*, ...)'
I know I need to edit the Makefile but that's where I am stuck. I do have some experience with makesfiles but don't know what to do. Moreover, all the dependencies are are complied and the object files produced so I don't know why ICP.cc is having this undefined reference error. The makefile is:
#------------------------------------------------------------------------------#
# This makefile was generated by 'cbp2make' tool rev.107 #
#------------------------------------------------------------------------------#
WRKDIR = `pwd`
CC = gcc
CXX = g++
AR = ar
LD = g++
WINDRES = windres
INC = -Iann_1.1.2/include
CFLAGS =
RESINC =
LIBDIR = -Lann_1.1.2/include
LIB =
LDFLAGS =
INC_RELEASE = $(INC)
CFLAGS_RELEASE = $(CFLAGS) -O2 -Wall `wx-config --cflags` `gsl-config --cflags`
RESINC_RELEASE = $(RESINC)
RCFLAGS_RELEASE = $(RCFLAGS)
LIBDIR_RELEASE = $(LIBDIR)
LIB_RELEASE = $(LIB) -lz -lGLEW -lGL -lglut
LDFLAGS_RELEASE = $(LDFLAGS) -s `wx-config --libs` `wx-config --libs gl` `gsl-config --libs`
OBJDIR_RELEASE = obj/Release
DEP_RELEASE =
OUT_RELEASE = bin/Release/Register3D_wx
OBJ_RELEASE = $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_pr_search.o $(OBJDIR_RELEASE)/ZPR.o $(OBJDIR_RELEASE)/ann_1.1.2/src/ANN.o $(OBJDIR_RELEASE)/ann_1.1.2/src/bd_fix_rad_search.o $(OBJDIR_RELEASE)/ann_1.1.2/src/bd_pr_search.o $(OBJDIR_RELEASE)/ann_1.1.2/src/bd_search.o $(OBJDIR_RELEASE)/ann_1.1.2/src/bd_tree.o $(OBJDIR_RELEASE)/ann_1.1.2/src/brute.o $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_dump.o $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_fix_rad_search.o $(OBJDIR_RELEASE)/PointOP.o $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_search.o $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_split.o $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_tree.o $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_util.o $(OBJDIR_RELEASE)/ann_1.1.2/src/perf.o $(OBJDIR_RELEASE)/main.o $(OBJDIR_RELEASE)/MainWindow.o $(OBJDIR_RELEASE)/Cylinder.o $(OBJDIR_RELEASE)/GLCanvas.o $(OBJDIR_RELEASE)/Help.o $(OBJDIR_RELEASE)/ICP.o $(OBJDIR_RELEASE)/ICPDialog.o $(OBJDIR_RELEASE)/About.o $(OBJDIR_RELEASE)/Math2.o $(OBJDIR_RELEASE)/Matrix.o $(OBJDIR_RELEASE)/Misc.o $(OBJDIR_RELEASE)/MyANN.o $(OBJDIR_RELEASE)/OGLWrapper.o $(OBJDIR_RELEASE)/Point.o
all: Release
clean: clean_Release
before_Release:
test -d bin/Release || mkdir -p bin/Release
test -d $(OBJDIR_RELEASE)/ann_1.1.2/src || mkdir -p $(OBJDIR_RELEASE)/ann_1.1.2/src
test -d $(OBJDIR_RELEASE)/ || mkdir -p $(OBJDIR_RELEASE)/
after_Release:
Release: before_Release out_Release after_Release
out_Release: $(OBJ_RELEASE) $(DEP_RELEASE)
$(LD) $(LDFLAGS_RELEASE) $(LIBDIR_RELEASE) $(OBJ_RELEASE) $(LIB_RELEASE) -o $(OUT_RELEASE)
$(OBJDIR_RELEASE)/ann_1.1.2/src/kd_pr_search.o: ann_1.1.2/src/kd_pr_search.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/kd_pr_search.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_pr_search.o
$(OBJDIR_RELEASE)/ZPR.o: ZPR.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ZPR.cc -o $(OBJDIR_RELEASE)/ZPR.o
$(OBJDIR_RELEASE)/ann_1.1.2/src/ANN.o: ann_1.1.2/src/ANN.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/ANN.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/ANN.o
$(OBJDIR_RELEASE)/ann_1.1.2/src/bd_fix_rad_search.o: ann_1.1.2/src/bd_fix_rad_search.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/bd_fix_rad_search.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/bd_fix_rad_search.o
$(OBJDIR_RELEASE)/ann_1.1.2/src/bd_pr_search.o: ann_1.1.2/src/bd_pr_search.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/bd_pr_search.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/bd_pr_search.o
$(OBJDIR_RELEASE)/ann_1.1.2/src/bd_search.o: ann_1.1.2/src/bd_search.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/bd_search.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/bd_search.o
$(OBJDIR_RELEASE)/ann_1.1.2/src/bd_tree.o: ann_1.1.2/src/bd_tree.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/bd_tree.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/bd_tree.o
$(OBJDIR_RELEASE)/ann_1.1.2/src/brute.o: ann_1.1.2/src/brute.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/brute.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/brute.o
$(OBJDIR_RELEASE)/ann_1.1.2/src/kd_dump.o: ann_1.1.2/src/kd_dump.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/kd_dump.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_dump.o
$(OBJDIR_RELEASE)/ann_1.1.2/src/kd_fix_rad_search.o: ann_1.1.2/src/kd_fix_rad_search.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/kd_fix_rad_search.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_fix_rad_search.o
$(OBJDIR_RELEASE)/PointOP.o: PointOP.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c PointOP.cc -o $(OBJDIR_RELEASE)/PointOP.o
$(OBJDIR_RELEASE)/ann_1.1.2/src/kd_search.o: ann_1.1.2/src/kd_search.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/kd_search.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_search.o
$(OBJDIR_RELEASE)/ann_1.1.2/src/kd_split.o: ann_1.1.2/src/kd_split.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/kd_split.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_split.o
$(OBJDIR_RELEASE)/ann_1.1.2/src/kd_tree.o: ann_1.1.2/src/kd_tree.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/kd_tree.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_tree.o
$(OBJDIR_RELEASE)/ann_1.1.2/src/kd_util.o: ann_1.1.2/src/kd_util.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/kd_util.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/kd_util.o
$(OBJDIR_RELEASE)/ann_1.1.2/src/perf.o: ann_1.1.2/src/perf.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ann_1.1.2/src/perf.cpp -o $(OBJDIR_RELEASE)/ann_1.1.2/src/perf.o
$(OBJDIR_RELEASE)/main.o: main.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c main.cc -o $(OBJDIR_RELEASE)/main.o
$(OBJDIR_RELEASE)/MainWindow.o: MainWindow.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c MainWindow.cc -o $(OBJDIR_RELEASE)/MainWindow.o
$(OBJDIR_RELEASE)/Cylinder.o: Cylinder.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c Cylinder.cc -o $(OBJDIR_RELEASE)/Cylinder.o
$(OBJDIR_RELEASE)/GLCanvas.o: GLCanvas.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c GLCanvas.cc -o $(OBJDIR_RELEASE)/GLCanvas.o
$(OBJDIR_RELEASE)/Help.o: Help.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c Help.cc -o $(OBJDIR_RELEASE)/Help.o
$(OBJDIR_RELEASE)/ICP.o: ICP.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ICP.cc -o $(OBJDIR_RELEASE)/ICP.o
$(OBJDIR_RELEASE)/ICPDialog.o: ICPDialog.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c ICPDialog.cc -o $(OBJDIR_RELEASE)/ICPDialog.o
$(OBJDIR_RELEASE)/About.o: About.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c About.cc -o $(OBJDIR_RELEASE)/About.o
$(OBJDIR_RELEASE)/Math2.o: Math2.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c Math2.cc -o $(OBJDIR_RELEASE)/Math2.o
$(OBJDIR_RELEASE)/Matrix.o: Matrix.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c Matrix.cc -o $(OBJDIR_RELEASE)/Matrix.o
$(OBJDIR_RELEASE)/Misc.o: Misc.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c Misc.cc -o $(OBJDIR_RELEASE)/Misc.o
$(OBJDIR_RELEASE)/MyANN.o: MyANN.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c MyANN.cc -o $(OBJDIR_RELEASE)/MyANN.o
$(OBJDIR_RELEASE)/OGLWrapper.o: OGLWrapper.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c OGLWrapper.cc -o $(OBJDIR_RELEASE)/OGLWrapper.o
$(OBJDIR_RELEASE)/Point.o: Point.cc
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c Point.cc -o $(OBJDIR_RELEASE)/Point.o
clean_Release:
rm -f $(OBJ_RELEASE) $(OUT_RELEASE)
rm -rf $(OBJDIR_RELEASE)/ann_1.1.2/src
rm -rf $(OBJDIR_RELEASE)/
.PHONY: before_Release after_Release clean_Release
I see two potential problems here:
You should use wx-config --libs std,gl to link with all normal wxWidgets libraries and wxWidgets OpenGL library instead of just the latter.
You should ensure that in your link command LDFLAGS_RELEASE comes after the object files, this is important if you're using static wxWidgets libraries.
Related
My code compiles well in codeblocks, but my makefile can't compile because of undefined reference to items with my namespace Chess
how should i specify the namespace in makefile or fix it?
here's the errors example:
King.cpp:35: undefined reference to `Chess::Board::getPiece(Chess::Position const&) const'
here's my makefile
CXXFLAGS = -ISFML-2.4.2/include -std=c++11
LXXFLAGS = -LSFML-2.4.2/lib -lsfml-graphics-d -lsfml-audio-d -lsfml-network-d -lsfml-window-d -lsfml-system-d -std=c++11
main.exe: main.o bishop.o king.o knight.o pawn.o position.o queen.o rook.o gui.o piece.o board.o Bishop.hpp Board.hpp
g++ -std=c++11 main.o bishop.o king.o knight.o pawn.o position.o queen.o rook.o gui.o piece.o -o main $(LXXFLAGS)
main.o: main.cpp GUI.hpp Board.hpp
g++ -fexceptions -g -std=c++11 -std=c++11 main.cpp -c $(CXXFLAGS)
bishop.o: Bishop.cpp Bishop.hpp Board.hpp
g++ -fexceptions -g -std=c++11 -std=c++11 Bishop.cpp -c $(CXXFLAGS)
king.o: King.cpp King.hpp Rook.hpp Board.hpp
g++ -fexceptions -g -std=c++11 -std=c++11 King.cpp -c $(CXXFLAGS)
pawn.o: Pawn.cpp Pawn.hpp Board.hpp
g++ -fexceptions -g -std=c++11 -std=c++11 Pawn.cpp -c $(CXXFLAGS)
position.o: Position.cpp Position.hpp
g++ -fexceptions -g -std=c++11 -std=c++11 Position.cpp -c $(CXXFLAGS)
queen.o: Queen.cpp Queen.hpp Board.hpp
g++ -fexceptions -g -std=c++11 -std=c++11 Queen.cpp -c $(CXXFLAGS)
rook.o: Rook.cpp Rook.hpp Board.hpp
g++ -fexceptions -g -std=c++11 -std=c++11 Rook.cpp -c $(CXXFLAGS)
knight.o: Knight.cpp Knight.hpp Board.hpp
g++ -fexceptions -g -std=c++11 -std=c++11 Knight.cpp -c $(CXXFLAGS)
gui.o: GUI.cpp GUI.hpp Queen.hpp Rook.hpp Bishop.hpp Knight.hpp
g++ -fexceptions -g -std=c++11 -std=c++11 GUI.cpp -c $(CXXFLAGS)
piece.o: Piece.cpp Piece.hpp Board.hpp
g++ -fexceptions -g -std=c++11 -std=c++11 Piece.cpp -c $(CXXFLAGS)
board.o: Board.cpp Board.hpp Pawn.hpp Rook.hpp Knight.hpp Queen.hpp King.hpp
g++ -fexceptions -g -std=c++11 -std=c++11 Board.cpp -c $(CXXFLAGS)
You forgot to include board.o when compiling main.exe
I want to compile both the node.c,list.c and helper-functions.c with both the tests I built.
I'm sure I did not write my makefile as I should. Can you please check it out?
CFLAGS= -Wall -Wvla -Werror
CXXFLAGS= -lgtest -lgtest_main -pthread
all:
mkdir -p build
gcc -c node.c $(CFLAGS) -o build/node.o
gcc -c list.c $(CFLAGS) -o build/list.o
gcc -c tests/helper-functions.c -o build/helper-functions.o
g++ tests/node-tests.cpp $(CXXFLAGS) -o build/node-tests.o
g++ tests/list-tests.cpp $(CXXFLAGS) -o build/list-tests.o
g++ build/list.o build/node.o build/helper-functions.o build/node-tests.o build/list-tests.o -o build/tests.out
./build/tests.out
When I ran make, the output is:
mkdir -p build
gcc -c node.c -Wall -Wvla -Werror -o build/node.o
gcc -c list.c -Wall -Wvla -Werror -o build/list.o
gcc -c tests/helper-functions.c -o build/helper-functions.o
g++ tests/node-tests.cpp -lgtest -lgtest_main -pthread -o build/node-tests.o
/tmp/ccFTgPVe.o: In function `CreateNode_FirstTest_Test::TestBody()':
node-tests.cpp:(.text+0x21): undefined reference to `createNode'
node-tests.cpp:(.text+0x31): undefined reference to `data'
node-tests.cpp:(.text+0x108): undefined reference to `next'
node-tests.cpp:(.text+0x1db): undefined reference to `freeNode'
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
There is definitly a reference to all those functions in node-test.cpp.
node-tests.cpp:
extern "C"
{
#include "../../../../headers/list.h"
#include "../../../../headers/node.h"
#include "helper-functions.h"
#include <assert.h>
}
#include "gtest/gtest.h"
#include <iostream>
#include <cstdlib>
#include <string>
// Node* CreateNode(void* data,const size_t dataLength,void* deepCopy(void*,const size_t));
TEST(CreateNode, FirstTest) {
int x=10;
Node* pos=createNode(&x,sizeof(x));
EXPECT_TRUE(*(int*)data(pos)==x);
EXPECT_TRUE(next(pos)==NULL);
freeNode(pos);
}
the list-tests.cpp is similar to node-tests.cpp.
CFLAGS= -Wall -Wvla -Werror
CXXFLAGS= -lgtest -lgtest_main -pthread
all:
mkdir -p build
gcc -c node.c $(CFLAGS) -o build/node.o
gcc -c list.c $(CFLAGS) -o build/list.o
gcc -c tests/helper-functions.c $(CFLAGS) -o build/helper-functions.o
g++ -c tests/node-tests.cpp -o build/node-tests.o //added -c, removed $(CXXFLAGS)
g++ -c tests/list-tests.cpp -o build/list-tests.o // added -c, $(CXXFLAGS)
g++ build/list.o build/node.o build/helper-functions.o build/node-tests.o build/list-tests.o $(CXXFLAGS) -o build/tests.out // added $(CXXFLAGS)
./build/tests.out
I have a project that contains a obj and a src subfolder.
When I run make with the following Makefile, it builds each .o with the same src.
CXX = g++
CXXINCDIRS = -I./ext/glui/include -I.
CXXLIBDIR = /usr/lib/
SRCDIR = ./src
OBJDIR = ./obj
INCDIR = ./include
BINDIR = ./bin
EXE = $(BINDIR)/brushwork
CXXFLAGS += -W -Wall -Wextra -Weffc++ -std=c++11 $(CXXINCDIRS)
SRC_CXX = $(wildcard $(SRCDIR)/*.cc)
OBJECTS_CXX = $(patsubst $(SRCDIR)/%.cc, $(OBJDIR)/%.o, $(SRC_CXX))
LIBRARY_CXX = -lglut -lGL -lGLU -L/usr/lib -lglui
$(OBJDIR)/%.o: $(SRCDIR)/%.cc
g++ -o $# -c $<
$(EXE): $(OBJECTS_CXX) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(CXXINCDIRS) -o $# $^ $(CXXLIBDIR) $(LIBRARY_CXX)
$(OBJECTS_CXX): $(SRC_CXX) | $(OBJDIR)
$(CXX) $(CXXFLAGS) -c -o $# $<
$(OBJDIR)/%.o: $(SRC_CXX) $(INCDIR)/%.h | $(OBJDIR)
$(CXX) $(CXXFLAGS) -c -o $# $<
$(BINDIR) $(OBJDIR):
mkdir -p $#
When I run the command
make -B -n
I get
mkdir -p obj
g++ -W -Wall -Wextra -Weffc++ -std=c++11 -I./ext/glui/include -I. -c -o obj/tool.o src/tool.cc
g++ -W -Wall -Wextra -Weffc++ -std=c++11 -I./ext/glui/include -I. -c -o obj/base_gfx_app.o src/tool.cc
g++ -W -Wall -Wextra -Weffc++ -std=c++11 -I./ext/glui/include -I. -c -o obj/color_data.o src/tool.cc
g++ -W -Wall -Wextra -Weffc++ -std=c++11 -I./ext/glui/include -I. -c -o obj/main.o src/tool.cc
g++ -W -Wall -Wextra -Weffc++ -std=c++11 -I./ext/glui/include -I. -c -o obj/pixel_buffer.o src/tool.cc
g++ -W -Wall -Wextra -Weffc++ -std=c++11 -I./ext/glui/include -I. -c -o obj/brushwork_app.o src/tool.cc
mkdir -p bin
g++ -W -Wall -Wextra -Weffc++ -std=c++11 -I./ext/glui/include -I. -I./ext/glui/include -I. -o bin/brushwork obj/tool.o obj/base_gfx_app.o obj/color_data.o obj/main.o obj/pixel_buffer.o obj/brushwork_app.o /usr/lib/ -lglut -lGL -lGLU -L/usr/lib -lglui
I am not sure why each obj file is being built with the same src file.
I have tried $(SRCDIR)/%.cc but make complains that there is no recipe for $(SRCDIR)/%.cc
How can I have make build each src file it's respective src file?
For this:
$(OBJDIR)/%.o: $(SRC_CXX) $(INCDIR)/%.h | $(OBJDIR)
$(CXX) $(CXXFLAGS) -c -o $# $<
I think you need this:
$(OBJDIR)/%.o: $(SRCDIR)/%.cc $(INCDIR)/%.h
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $# $<
I'm not sure what this does:
$(OBJECTS_CXX): $(SRC_CXX) | $(OBJDIR)
$(CXX) $(CXXFLAGS) -c -o $# $<
I suspect you should remove it.
And I think you should also remove this:
$(OBJDIR)/%.o: $(SRCDIR)/%.cc
g++ -o $# -c $<
It looks like you had 3 different rules to build your objects (unless I read it wrong).
Following makefile works except cleaning the object files after compiling and linking. I tried make clean which does exactly what I want: deletes the executable and the object files in all folders. I also included the outputs of make and make clean. Any idea?
Makefile:
CC=g++
CFLAGS=-c -std=c++11 -O2 -O3
SOURCES=main.cpp\
BoundaryConditions/BoundaryConditions.cpp\
Cell/Cell.cpp\
Face/Face.cpp\
Formulation/Explicit/Explicit.cpp\
Formulation/Implicit/Implicit.cpp\
Grid/Grid.cpp\
Grid/ReadGrid.cpp\
Grid/SetGrid.cpp\
Init/Init.cpp\
InterFlux/Interflux.cpp\
InterFlux/Roe/Roe.cpp\
Matrix5/Operators.cpp\
Output/Output.cpp\
Solver/GaussSeidel.cpp\
Vector/Vector.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=codeBaku
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $#
.cpp.o:
$(CC) $(CFLAGS) $< -o $#
.PHONY: clean
clean:
rm -rf $(OBJECTS) $(EXECUTABLE)
Output of make:
g++ -c -std=c++11 -O2 -O3 main.cpp -o main.o
g++ -c -std=c++11 -O2 -O3 BoundaryConditions/BoundaryConditions.cpp -o BoundaryConditions/BoundaryConditions.o
g++ -c -std=c++11 -O2 -O3 Cell/Cell.cpp -o Cell/Cell.o
g++ -c -std=c++11 -O2 -O3 Face/Face.cpp -o Face/Face.o
g++ -c -std=c++11 -O2 -O3 Formulation/Explicit/Explicit.cpp -o Formulation/Explicit/Explicit.o
g++ -c -std=c++11 -O2 -O3 Formulation/Implicit/Implicit.cpp -o Formulation/Implicit/Implicit.o
g++ -c -std=c++11 -O2 -O3 Grid/Grid.cpp -o Grid/Grid.o
g++ -c -std=c++11 -O2 -O3 Grid/ReadGrid.cpp -o Grid/ReadGrid.o
g++ -c -std=c++11 -O2 -O3 Grid/SetGrid.cpp -o Grid/SetGrid.o
g++ -c -std=c++11 -O2 -O3 Init/Init.cpp -o Init/Init.o
g++ -c -std=c++11 -O2 -O3 InterFlux/Interflux.cpp -o InterFlux/Interflux.o
g++ -c -std=c++11 -O2 -O3 InterFlux/Roe/Roe.cpp -o InterFlux/Roe/Roe.o
g++ -c -std=c++11 -O2 -O3 Matrix5/Operators.cpp -o Matrix5/Operators.o
g++ -c -std=c++11 -O2 -O3 Output/Output.cpp -o Output/Output.o
g++ -c -std=c++11 -O2 -O3 Solver/GaussSeidel.cpp -o Solver/GaussSeidel.o
g++ -c -std=c++11 -O2 -O3 Vector/Vector.cpp -o Vector/Vector.o
g++ main.o BoundaryConditions/BoundaryConditions.o Cell/Cell.o Face/Face.o Formulation/Explicit/Explicit.o Formulation/Implicit/Implicit.o Grid/Grid.o Grid/ReadGrid.o Grid/SetGrid.o Init/Init.o InterFlux/Interflux.o InterFlux/Roe/Roe.o Matrix5/Operators.o Output/Output.o Solver/GaussSeidel.o Vector/Vector.o -o codeBaku
Output of make clean:
rm -rf main.o BoundaryConditions/BoundaryConditions.o Cell/Cell.o Face/Face.o Formulation/Explicit/Explicit.o Formulation/Implicit/Implicit.o Grid/Grid.o Grid/ReadGrid.o Grid/SetGrid.o Init/Init.o InterFlux/Interflux.o InterFlux/Roe/Roe.o Matrix5/Operators.o Output/Output.o Solver/GaussSeidel.o Vector/Vector.o codeBaku
It is unusual to automatically remove the object files, since that would mean everything would have to be recompiled each time, even if you only change one source file. However, if you really want to do it, you could do something like this:
all: $(SOURCES) $(EXECUTABLE)
rm $(OBJECTS)
I am making a makefile and one of the targets is exptrtest.o how do I use g++ to create an objectfile with that name, the name of my cpp file is exprtest.cpp not exptrtest.cpp?
exptrtest.o: exprtest.cpp
g++ -Wall -g -c exprtest.cpp
to make it more clear, this is my makefile:
all: exprtest
exprtest: exptrtest.o driver.o parser.tab.o scanner.o
g++ -Wall -g -o exprtest exptrtest.o driver.o parser.tab.o scanner.o
exptrtest.o: exprtest.cpp
g++ -Wall -g -c exptrtest.o exprtest.cpp
driver.o: driver.cpp scanner.hpp driver.hpp
g++ -Wall -g -c driver.cpp
parser.tab.o: parser.tab.hpp parser.tab.cpp
bison parser.ypp
g++ -Wall -g -c parser.tab.cpp
scanner.o: scanner.cpp scanner.hpp
flex -t scanner.ll > scanner.cpp
g++ -Wall -g -c scanner.cpp
clean:
rm parser.tab.hpp parser.tab.cpp scanner.cpp
I'm getting the error:
"g++: error: exptrtest.o: No such file or directory
make: * [exprtest] Error 1"
Use the -o option in conjunction with -c.
exptrtest.o: exprtest.cpp
g++ -Wall -g -c exprtest.cpp -o exptrtest.o