Re: Using C-Predicates in Eclipse

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Tue 10 Dec 2002 12:51:32 PM GMT
Message-ID: <3DF5E354.B79036AD@icparc.ic.ac.uk>
Georg Fette wrote:
> 
> Hiho,
> Could anyone please send me a working example of a c++-function with
> parameters (one already unified in-parameter and one still free
> out-parameter) which can be called from eclipse and which compiler he used
> to compile it. Thanx a lot.
> 
> Georg


See doc/examples/eg_cc_external.cc in your Eclipse distribution.
I attach this file in a slightly modified form, with dllexport
declarations added and the suffix changed to .cpp for Windows.


If you are using Visual C++, you then need to do the following:

1. Create a project of type "Win32 dynamic link library"
2. add the source file to the project
3. make the following three project settings:

    C/C++, Preprocessor, Additional include directories:

        add <eclipsedir>/include/i386_nt

    Link, Input, Additional library path:

        add <eclipsedir>/lib/i386_nt

    Link, Input, Object/library modules:

        add eclipse.lib

where <eclipsedir> is the directory where you have
Eclipse installed. (I attach corresponding Visual C++ 5.0
.dsw and .dsp files. If you want to use them, you have to
adjust the path names)

You should then be able to build example.dll.
Once you have that, start eclipse/tkeclipse and try:

?- load("//Z/Example/Debug/example.dll").
Yes (0.02s cpu)
?- external(sl / 2, p_sumlist).
Yes (0.00s cpu)
?- sl([1, 2, 3, 4, 5], S).
S = 15
Yes (0.00s cpu)

using the correct path name of course...


-- 
 Joachim Schimpf              /             phone: +44 20 7594 8187
 IC-Parc, Imperial College   /            mailto:J.Schimpf@ic.ac.uk
 London SW7 2AZ, UK         /    http://www.icparc.ic.ac.uk/eclipse
Microsoft Developer Studio Workspace File, Format Version 5.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!

###############################################################################

Project: "Example"=.\Example.dsp - Package Owner=<4>

Package=<5>
{{{
}}}

Package=<4>
{{{
}}}

###############################################################################

Global:

Package=<5>
{{{
}}}

Package=<3>
{{{
}}}

###############################################################################


/*
 * Examples for ECLiPSe C++ externals, from the User Manual
 *
 * $Id: eg_cc_external.cc,v 1.2 1999/02/21 18:10:07 js10 Exp $
 *
 */

#include "eclipseclass.h"

#ifdef WIN32
#define EC_EXPORT __declspec(dllexport)
#else
#define EC_EXPORT
#endif

extern "C" EC_EXPORT int
p_string_to_list()
{
    EC_word  the_string(EC_arg(1));
    EC_word  the_list(nil());
    char *s;
    long len;
    int res;

    res = the_string.is_string( &s );
    if (res != EC_succeed) return res;
    len = strlen(s);

    /* the list is built backwards */
    while (len--)
    {
	the_list = list(EC_word(s[len]), the_list);
    }
    return unify(EC_word(EC_arg(2)), the_list);
}


extern "C" EC_EXPORT int
p_sumlist()
{
    int res;
    long x, sum = 0;
    EC_word list(EC_arg(1));
    EC_word car,cdr;

    for ( ; list.is_list(car,cdr) == EC_succeed; list = cdr)
    {
	res = car.is_long( &x);
	if (res != EC_succeed) return res;
	sum += x;
    }
    res = list.is_nil();
    if (res != EC_succeed) return res;
    return unify(EC_arg(2), EC_word(sum));
}


# Microsoft Developer Studio Project File - Name="Example" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 5.00
# ** DO NOT EDIT **

# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102

CFG=Example - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE 
!MESSAGE NMAKE /f "Example.mak".
!MESSAGE 
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE 
!MESSAGE NMAKE /f "Example.mak" CFG="Example - Win32 Debug"
!MESSAGE 
!MESSAGE Possible choices for configuration are:
!MESSAGE 
!MESSAGE "Example - Win32 Release" (based on\
 "Win32 (x86) Dynamic-Link Library")
!MESSAGE "Example - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE 

# Begin Project
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe

!IF  "$(CFG)" == "Example - Win32 Release"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386

!ELSEIF  "$(CFG)" == "Example - Win32 Debug"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept

!ENDIF 

# Begin Target

# Name "Example - Win32 Release"
# Name "Example - Win32 Debug"
# End Target
# End Project
Received on Tue Dec 10 12:52:11 2002

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:19 PM GMT GMT