solver icon indicating copy to clipboard operation
solver copied to clipboard

Support CMake/Make in addition to Bazel

Open solanu opened this issue 4 years ago • 7 comments

I get the following error when I run the example of the readme.md:

$ go run main.go 
# github.com/irfansharif/solver/internal
wrapper.cc:355:10: fatal error: ortools/base/basictypes.h: No such file or directory
 #include "ortools/base/basictypes.h"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

solanu avatar Sep 23 '21 07:09 solanu

Are you using bazel for your build? For now this library comes with the caveat that you need to use bazel (though PRs to make it work with make/etc. are welcome, just not something I'll get to until a month or two). https://github.com/irfansharif/allocator/tree/210808.debuggability is an example of a package that uses this library if you want pointers on how.

irfansharif avatar Sep 23 '21 14:09 irfansharif

Can you please give an example/advice how to build a project with this library as a dependency? (with the included top Makefile a project like the following main.go is not working)

package main

import (
	"github.com/irfansharif/solver"
	"log"
)

func main() {
	model := solver.NewModel("test")

	var numVals int64 = 3
	x := model.NewIntVar(0, numVals-1, "x")
	y := model.NewIntVar(0, numVals-1, "y")
	z := model.NewIntVar(0, numVals-1, "z")

	ct := solver.NewAllDifferentConstraint(x, y, z)
	model.AddConstraints(ct)

	result := model.Solve()
	log.Printf("optimal result: %v", result.Optimal())
	log.Printf("x: %v, y: %v, z: %v", result.Value(x), result.Value(y), result.Value(z))
}

RobinKamps avatar Mar 23 '22 08:03 RobinKamps

https://github.com/irfansharif/allocator is one example (https://github.com/irfansharif/allocator/tree/210808.debuggability is a branch using a more recent version of this library).

irfansharif avatar Mar 23 '22 11:03 irfansharif

Thank you very much.

RobinKamps avatar Mar 23 '22 13:03 RobinKamps

I agree with @RobinKamps , it would be most welcomed to have something simpler for compiling with dependencies. Go is the promise of a simple toolchain and I feel like "pre go" times with bazel & makefile & long compile time. I would have contributed for this with pleasure but I am not at all familiar with the techniques involved.

thomaspeugeot avatar Apr 12 '22 06:04 thomaspeugeot

There’s a C++ dependency involved, and consequently cgo; some of this pain is unavoidable. What I’ve seen work for dependencies like this is linking against pre-built binary archives for various architectures and distributing that as part of the library itself. That’s a sizeable amount of work however and I’m unlikely to be able to do it.

irfansharif avatar Apr 12 '22 09:04 irfansharif

Ok, I understand. I surmise this is the kind of work they have done with the sqlite3 wrap. Thks for your answer.

thomaspeugeot avatar Apr 12 '22 09:04 thomaspeugeot