Hi there, I recently had a similar task to do. After a help from Joachem I managed to finally handle things with C. Found it easier than the C++ interface and actually I just needed a simple interfacing. I am sending a sample C and eclipse code for the magic square. I compiled it in .NET so if you use the same environment remember to use Release version for the executable otherwise it keeps asking for some .dlls .. And also the first directives in the .C are necessary if not in unix.. If someone has a similar thing in C++ I would like to see it as well.. Good luck, Christos ===========================test.c=========================================================== /* If we're not using GNU C, elide __attribute__ */ #ifndef __GNUC__ # define __attribute__(x) /*NOTHING*/ #endif #include <iostream> #include "eclipse.h" using namespace std; int main(){ char buf[1024]; int n; int fd; // file descriptor int number; ec_init(); ec_ref toC; toC = ec_ref_create_newvar(); ec_post_goal(ec_term(ec_did("compile",1),ec_string("cmagicsq"))); number = 35; ec_post_goal(ec_term(ec_did("magicsq",2),ec_newvar(),ec_long(number))); ec_resume(); fd = ec_stream_nr("my_out_queue"); n = ec_queue_read((int) fd, buf, 1024); buf[n] = 0; printf("eclipse returned: %s\n", buf); ec_cleanup(); } =========================cmagicsq.ecl============================================================== :- lib(ic). :- lib(ic_global). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% :- set_stream(error,null). :- set_stream(warning_output,null). %:- set_stream(output,null). %:- set_stream(log_output,null). :- open(queue(""), write, my_out_queue). %% for output in memory-stream %:- open(tmpfile, write, my_out_queue). %% for output in file "tmpfile" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% magicsq( Digits, N) :- Digits = [A1,A2,A3,B1,B2,B3,C1,C2,C3], Digits :: [-20..20], ic_global:alldifferent(Digits), A1+A2+A3 #= N, B1+B2+B3 #= N, C1+C2+C3 #= N, A1+B1+C1 #= N, A2+B2+C2 #= N, A3+B3+C3 #= N, writeln("hi from here !!"), labeling(Digits), write(my_out_queue, Digits), %% writing to output queue stream write(my_out_queue, N), flush(my_out_queue). %% flushing the queue stream ============================================================================== --- Στις Τρίτ., 29/04/08, ο/η Soheil Samii <sohsa_at_...107...> έγραψε: Από: Soheil Samii <sohsa@...109...7...> |
This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST