[gecode-users] Copiling with gcc on OpenSuSE 10.0

Vladimír Dusa neachem at volny.cz
Tue Nov 29 12:33:55 CET 2005


Hi,

Thank you very much for your help. Now I can successfully compile the
project and I would like to describe "how did I made it" for other users:

I am using OpenSuSE 10.0 with KDevelop 3.2.2 as a tool for programming in
C/C++.

0. Install the gecode library:
  a) ./configure
  b) make install (examples will be not installed. It is needed to use only
"make" for installing examples. But then will be the gecode library
installed in the current folder. If "make install" is used, then was at me
gecode installed in the directory /usr/local/lib/...,
/usr/local/include/...)
1. Create new C++ Project (e.g. Simple Hello World program).
2. Compile this project.
3. In Menu Project/Project Options is there a section "Configure Options".
  a) For debugging:
    i) in "C/C++ preprocessor flags (CPPFLAGS):" should stay:
	-I/usr/local/include/gecode (maybe -I$GPREFIX/include/gecode can be used)
    ii) in "Compiler flags (CXXFLAGS):" should stay:
	-L/usr/local/lib -O0 -g3 -lgecodeminimodel -
lgecodeset -lgecodeint -lgecodesearch -lgecodekernel (maybe -I$GPREFIX/lib
... can be used)
    iii) Select OK and then in the message box "Re-run configure for debug
now?" select Yes.
4. As an example can be used following code (SEND+MORE=MONEY) in the main
project cpp file instead of original code from the wizard:

//begin of file **************************************
#include <iostream>
#include <cstdlib>

#include "minimodel.hh"
#include "search.hh"

using namespace std;
using namespace Gecode;

class Money: public Space{
	private:
		static const int nl = 8;
		IntVarArray le;
	public:
		Money();
		Money(bool share, Money &s): Space(share, s){
			le.update(this, share, s.le);
		}
		Space* copy(bool share);
		void print();
};

Money::Money(): le(this, nl, 0, 9)
{
	IntVar s(le[0]), e(le[1]), n(le[2]), d(le[3]), m(le[4]), o(le[5]),
r(le[6]), y(le[7]); //variables

	//s and m must not be = 0
	rel(this, s, IRT_NQ, 0);
	rel(this, m, IRT_NQ, 0);

	//main money constraint

post(this,1000*s+100*e+10*n+d+1000*m+100*o+10*r+e==10000*m+1000*o+100*n+10*e
+y);

	//it must not be two variables with same value (all variables must be
distinct)
	distinct(this, le, ICL_DEF);

	//search the tree
	branch(this, le, BVAR_SIZE_MIN, BVAL_MIN);
};

Space* Money::copy(bool share){
	return new Money(share,*this);
}

void Money::print() {
	cout << "Solution:" << endl;
	for (int i = 0; i < nl; i++)
		cout << le[i] << " ";

	cout << std::endl;
}

int main(int argc, char *argv[])
{
	Money* m = new Money;
	DFS<Money> e(m, 1, 1);
	delete(m);

	Money* ex = e.next();

	while(ex){
		ex->print();
		delete(ex);
		ex = e.next();
	}

  return EXIT_SUCCESS;
}
//end of file **************************************

After compiling this code should be everything ok. For compiling as
"optimized" should be used some different flags in 3)a)i) and 3)a)ii). This
flags for optimisation can be found in the makefile in the gecode directory.
Now I do not need it :-). The moment I now what flags must be set for
optimized compilation, I write it here.

Thank you very much again.

Best regards from Prag

Vladimir Dusa

-----Original Message-----
From: tack at ps.uni-sb.de [mailto:tack at ps.uni-sb.de]
Sent: Saturday, November 26, 2005 3:07 PM
To: Vladimír Dusa
Cc: users at gecode.org
Subject: RE: [gecode-users] Copiling with gcc on OpenSuSE 10.0


Hi.

> Hello,
>
> Maybe I have explained my problem not good. I would like to use gecode for
> solving my problems. If I try to include some gecode header file (e.g.
> #include "minimodel.hh"), I become similar errors as in previous email. I
> used the money.cc as an example. If I make an "empty" cpp file (let's say
> test.cpp):

Sorry, I should have read your first mail more carefully. I think there
are two problems with the way you try to compile your example: you use
gcc, which doesn't like .cc as input file name, and you don't link against
the gecode library.

The easiest way to try your own examples is to copy them into the examples
folder. Assuming your example is called myexample.cc, just do
make examples/myexample
in the Gecode main directory. This will use our Makefile rules to build
your example.
If this works, you can look at the g++ invocation that built your example
and use similar options for building your stuff in other directories.

After installation, you should be able to use the options you saw when
invoking make example/myexample, but add -I<prefix>/include
-L<prefix>/lib.

Hope this helps,
   Guido








More information about the gecode-users mailing list