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
Related
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.
I have been looking this up for a while and there are a bunch of solutions but I don't think they are quite what my problem is,
at the moment I have a folder with some classes for a 'UI' for my client, I have compiled and tested these classes separate to my main project and they all work great, and my current makefile for my project without this new package works fine, but when I add my new package to my project and update my makefile and include the new UI files in my main I get a problem saying that previous classes in my project that I have already tested no longer work, for a better Idea of what I mean here
Terminal:
make -f makeLedger2.mk
gcc -o sqlite3 SQLite/sqlite3.c SQLite/shell.c -lm -lrt -lpthread -ldl
g++ -c rsa/Number.cpp
g++ -c rsa/BigInt.cpp -lm -lrt -lpthread -ldl
g++ -c rsa/Rsa.cpp -lm -lrt -lpthread -ldl
g++ -c database/Entry.cpp
g++ -c rsa/Key.cpp
g++ -c database/PersonalDataBase.cpp -lm -lrt -lpthread -ldl
gcc -o sqlite.o -c SQLite/sqlite3.c -lm -lrt -lpthread -ldl
g++ -c ClientUI/UIOutput.cpp
g++ -c ClientUI/UserCommand.cpp
g++ -c ClientUI/KeyboardController.cpp
g++ -c Network/P2P/Network.cpp -lm -lrt -lpthread -ldl
g++ -c main.cpp -lm -lrt -lpthread -ldl
main.cpp: In function ‘int main()’:
main.cpp:23:11: error: ‘overlay’ was not declared in this scope
main.cpp:23:25: error: expected type-specifier before ‘Network’
main.cpp:23:25: error: expected ‘;’ before ‘Network’
make: *** [main.o] Error 1
The biggest problem here is this is untouched from before I updated my makefile, (i.e. my Network class does not run into this error before I include, or all my code would compile without the addition of this new package 'ClientUI')
my makefile:
CXX = g++
CC = gcc
LIB = -lm -lrt -lpthread -ldl
BIN = SQLite ledger database Network/P2P Control ClientUI
****Added : UIOutput.o UserCommand.o KeyboardController.o***
OBJECTS = Number.o BigInt.o Rsa.o LedgerEntry.o Entry.o Key.o PersonalDataBase.o sqlite.o UIOutput.o UserCommand.o KeyboardController.o Network.o main.o
VPATH = SQLite rsa database Network/P2P Control ClientUI
all : $(BIN)
sqlite3: sqlite3.c shell.c
$(CC) -o $# $^ $(LIB)
ledger: $(OBJECTS)
$(CXX) -o $# $^ $(LIB)
Number.o: rsa/Number.cpp rsa/Number.h
$(CXX) -c rsa/Number.cpp
BigInt.o: rsa/BigInt.cpp rsa/BigInt.h rsa/Number.h
$(CXX) -c rsa/BigInt.cpp$(LIB)
Rsa.o: rsa/Rsa.cpp rsa/Rsa.h rsa/BigInt.h rsa/Number.h
$(CXX) -c rsa/Rsa.cpp $(LIB)
Key.o: rsa/Key.cpp rsa/Key.h rsa/Number.h
$(CXX) -c rsa/Key.cpp
Entry.o: database/Entry.cpp database/Entry.h rsa/Number.h
$(CXX) -c database/Entry.cpp
PersonalDataBase.o: database/PersonalDataBase.cpp database/PersonalDataBase.h SQLite/sqlite3.h database/Entry.h rsa/Key.h
$(CXX) -c database/PersonalDataBase.cpp $(LIB)
*****NEW PACKAGE******
UIOutput.o: ClientUI/UIOutput.h ClientUI/UIOutput.cpp
$(CXX) -c ClientUI/UIOutput.cpp
UserCommand.o: ClientUI/UserCommand.cpp ClientUI/UserCommand.h
$(CXX) -c ClientUI/UserCommand.cpp
KeyboardController.o: ClientUI/KeyboardController.cpp
$(CXX) -c ClientUI/KeyboardController.cpp
*****NEW PACKAGE End******
Network.o: Network/P2P/Network.cpp
$(CXX) -c Network/P2P/Network.cpp $(LIB)
***Include KeyboardController below***
main.o: main.cpp database/PersonalDataBase.h Network/P2P/Network.h ClientUI/KeyboardController.h
$(CXX) -c main.cpp $(LIB)
sqlite.o: sqlite3.c
$(CC) -o $# -c $^ $(LIB)
clean:
rm -f $(BIN)
rm -f $(OBJECTS)
.PHONEY: all, clean
for New Dependencies,
Message includes UIOutput
UserCommand Extends Message (includes)
KeyboardController includes UserCommand
this makefile for jsut these files works (and a test main.cpp for them)
out: UIOutput.o UserCommand.o KeyboardController.o main.o
g++ -o out UIOutput.o UserCommand.o KeyboardController.o main.o
UIOutput.o: UIOutput.h UIOutput.cpp
g++ -c UIOutput.cpp
UserCommand.o: UserCommand.cpp UserCommand.h Message.h UIOutput.h
g++ -c UserCommand.cpp
KeyboardController.o: KeyboardController.cpp KeyboardController.h UserCommand.h Message.h UIOutput.h
g++ -c KeyboardController.cpp
main.o: KeyboardController.h main.cpp
g++ -c main.cpp
main.cpp
#include "Network/P2P/Network.h"
#include "rsa/BigInt.h"
#include "rsa/Number.h"
#include "rsa/Rsa.h"
#include "database/PersonalDataBase.h"
//****Litterally All I do is include it here and I get an issue
//if I commented it out I would be fine and all the .o files would be built, including my new ones, and this can compile
#include "ClientUI/KeyboardController.h"
#include <iostream>
#include <sys/time.h>
#include <stdlib.h>
#include <limits>
using namespace std;
using namespace BigIntOperators;
using namespace RSA;
int main()
{
Network *overlay = new Network("Alice", "LOLO1");
....
.....
I'm doing nothing different to how I import my other packages, and I have compiled all the newly added files and tested them without problem seperatley, furthermore the packages ClientUI shares no dependancies with any other file, except in my main function... what's happening here?
After try to use this attached makefile the error that appears is :
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
make: *** [Ass1F] Error 1
the makefile is :
all: Ass1F
Ass1F: bin/main.o bin/x.o bin/y.o bin/z.o bin/w.o
g++ -o bin/main.o bin/x.o bin/y.o bin/z.o bin/w.o
#echo 'Finished building target: Ass1F'
#echo ' '
bin/x.o: src/x.cpp
g++ -g -Wall -Weffc++ -c -Linclude -o bin/x.o src/x.cpp
bin/y.o: src/y.cpp
g++ -g -Wall -Weffc++ -c -Linclude -o bin/y.o src/y.cpp
bin/z.o: src/z.cpp
g++ -g -Wall -Weffc++ -c -Linclude -o bin/z.o src/z.cpp
bin/w.o: src/w.cpp
g++ -g -Wall -Weffc++ -c -Linclude -o bin/w.o src/w.cpp
bin/main.o: src/main.cpp
g++ -g -Wall -Weffc++ -c -Linclude -o bin/main.o src/main.cpp
clean:
rm -f bin/*
what should I do with this problem?
the reason is the makefile or something in the code?
just to let you know we used eclipse to write the code and everything work perfectly- no any bugs.
thanks
Line g++ -o bin/main.o bin/x.o bin/y.o bin/z.o bin/w.o tries to create executable named bin/main.o, overwriting its previous contents.
It should be e.g. g++ -o Ass1F bin/main.o bin/x.o bin/y.o bin/z.o bin/w.o
Your makefile recipe for Ass1F is incorrect, it doesn't specify the output file, os make uses bin/main.o as the output file instead of one of the input files.
You can simplify the makefile by using pattern rules (i.e. with wildcards) and using pre-defined variables such as $# (the name of the target) and $^ (the list of prerequisites) and CXX (the C++ compiler):
CXXFLAGS = -g -Wall -Weffc++
CPPFLAGS =
LDFLAGS =
LDLIBS =
all: Ass1F
Ass1F: bin/main.o bin/x.o bin/y.o bin/z.o bin/w.o
$(CXX) $(LDFLAGS) -o $# $^ $(LDLIBS)
#echo 'Finished building target: Ass1F'
#echo ' '
bin/%.o: src/%.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $# $^
clean:
rm -f bin/*
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