Makefile

Hello, I have a makefile and I need to work with a library ginac.

using namespace GiNaC;

I compile a simple file with g++ file.cpp -lginac but know I have several files and I use a Makefile. The question is, where I put the -lginac in it?

Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  OBJ = main.o GeneticAlgorithm.o Individual.o Chromosome.o Population.o Rama.o

gAlgo:	$(OBJ)
	g++ -o gAlgo $(OBJ)

main.o: main.cc GeneticAlgorithm.h Population.h Individual.h Rama.h
	g++ -c main.cc

GeneticAlgorithm.o: GeneticAlgorithm.cc GeneticAlgorithm.h Population.h
	g++ -c GeneticAlgorithm.cc 

Individual.o: Individual.cc Individual.h Chromosome.h
	g++ -c Individual.cc

Chromosome.o: Chromosome.cc Chromosome.h
	g++ -c Chromosome.cc

Population.o: Population.cc Population.h
	g++ -c Population.cc

Rama.o: Rama.cc Rama.h
	g++ -c Rama.cc

clean:
	rm -f *.o gAlgo
Last edited on
Try the end of the first g++ line:
 
        g++ -o gAlgo $(OBJ) -lginac

Last edited on
I'm afraid that it doesn't work

the message is:
GeneticAlgorithm.cc:8:17: error: ‘GiNaC’ is not a namespace-name
using namespace GiNaC;
that's a compile-time error, it failed on rule lines 9,10 when doing g++ -c GeneticAlgorithm.cc
so don't go blaming the linker.


edit: ¿did you #include <ginac/ginac.h> in `GeneticAlgorithm.cc'?
Last edited on
Thanks, it works
Now I have another problem:

1
2
3
4
5
6
7
8
9
double GeneticAlgorithm::calcFitness(Individual* indiv)
// Calculate fitness based on number of ones in chromosome
{
	Rama rama = new Rama[indiv->getChromosomeLength()]
	for (int i=0; i<indiv->getChromosomeLength();i++)
	{
		rama[i]=indiv->getGene(i);
	}


that throws an error message:
GeneticAlgorithm.cc:115:14: error: conversion from ‘Rama*’ to non-scalar type ‘Rama’ requested
Rama rama = new Rama[indiv->getChromosomeLength()]
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GeneticAlgorithm.cc:116:16: error: ‘i’ was not declared in this scope
for (int i=0; i<indiv->getChromosomeLength();i++)




Thanks
Rama *rama
also, you are missing a semicolon (;) at the end of the line.

I'll recommend you to use std::vector instead of trying to manually manage the memory.
1
2
std::vector<Rama> rama(indiv->getChromosomeLength());
for(int i=0; i<rama.size(); ++i)
Topic archived. No new replies allowed.