1. Using shared objects

I have some shared object written in C.  Below is the code.  
What I want is to write a euphoria include that maps the 
shared object to euphoria.  

What I'd like even more is if the share object could be 
distributed as part of the project and not necessarily 
"installed" on the host.  (ie... no ldconfig).

So my question is, does anyone have the time to show me 
how to do it?

This is what I have ...

#include <stdlib.h>
#define NUM_DOG 10

void mush(char**, int);
int bark();

void mush(char* dogs[], int len)
{
	int i = 0;
	printf("Number of dogs: %d \n", len );
	for (i; i < len; i++)
	{
		printf("Dog named: %s starts mushing...\n", dogs[i]);
	}
}

int bark()
{
	return 1;
}

This is what I want ...

include dog.e
if atom(bark()) then
	mush({"scooby", "dino", "astro", "spike"}) --notice the absence of arg 2
end if


new topic     » topic index » view message » categorize

2. Re: Using shared objects

Ron Weidner wrote:
> 
> 
> I have some shared object written in C.  Below is the code.  
> What I want is to write a euphoria include that maps the 
> shared object to euphoria.  
> 
> What I'd like even more is if the share object could be 
> distributed as part of the project and not necessarily 
> "installed" on the host.  (ie... no ldconfig).
> 
> So my question is, does anyone have the time to show me 
> how to do it?
> 
> This is what I have ...
> 
> }}}
<eucode>
> #include <stdlib.h>
> #define NUM_DOG 10
> 
> void mush(char**, int);
> int bark();
> 
> void mush(char* dogs[], int len)
> {
> 	int i = 0;
> 	printf("Number of dogs: %d \n", len );
> 	for (i; i < len; i++)
> 	{
> 		printf("Dog named: %s starts mushing...\n", dogs[i]);
> 	}
> }
> 
> int bark()
> {
> 	return 1;
> }
> 
> This is what I want ...
> 
> include dog.e
> if atom(bark()) then
> 	mush({"scooby", "dino", "astro", "spike"}) --notice the absence of arg 2
> end if
> 
> <font color="#330033"></eucode>
{{{
</font>
> 

If I'm understanding correctly.. you want to interface those C routines with
Euphoria? If so.. compile that code with your C compiler into a DLL or SO. Name
it Dog.dll (Windows) or Dog.so (Linux/FreeBSD), then try this code:

-- File extention must be EXW or EXU.

include dll.e

atom dllBark, bark, mush

dllBark = open_dll("Dog.dll")   --  make a DLL/SO of that C code
mush = define_c_proc(dllBark, "mush", {C_CHAR, C_INT})
bark = define_c_func(dllBark, "bark", {}, C_INT)

if atom(c_func(bark, {})) then
    c_proc(mush, {"scooby", "dino", "astro", "spike"})
end if

machine_proc(26, 0) -- pause


I didnt try making a DLL of that code, so their could be a error with my
Euphoria code, but perhaps that will help you out, or maybe I'm way off :P.


Regards,
Vincent

--
Without walls and fences, there is no need for Windows and Gates.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Using shared objects

Ron Weidner wrote:
> 
> 
> I have some shared object written in C.  Below is the code.  
> What I want is to write a euphoria include that maps the 
> shared object to euphoria.  
> 
> What I'd like even more is if the share object could be 
> distributed as part of the project and not necessarily 
> "installed" on the host.  (ie... no ldconfig).
> 
> So my question is, does anyone have the time to show me 
> how to do it?
> 
> This is what I have ...
> 
> }}}
<eucode>
> #include <stdlib.h>
> #define NUM_DOG 10
> 
> void mush(char**, int);
> int bark();
> 
> void mush(char* dogs[], int len)
> {
> 	int i = 0;
> 	printf("Number of dogs: %d \n", len );
> 	for (i; i < len; i++)
> 	{
> 		printf("Dog named: %s starts mushing...\n", dogs[i]);
> 	}
> }
> 
> int bark()
> {
> 	return 1;
> }
> 
> This is what I want ...
> 
> include dog.e
> if atom(bark()) then
> 	mush({"scooby", "dino", "astro", "spike"}) --notice the absence of arg 2
> end if
> 
> 

As a reminder, you need to make sure that your routines are exported to the
compiled DLL by perhaps using "__declspec(dllexport)" (you can use #define and
make a macro definition of that too) in front of the routine declarations.

Regards,
Vincent

--
Without walls and fences, there is no need for Windows and Gates.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Using shared objects

On Thu, 02 Jun 2005 13:29:46 -0700, Ron Weidner
<guest at RapidEuphoria.com> wrote:

>I have some shared object written in C.  Below is the code.  
Not entirely sure precisely what you mean by "shared object"..
>What I want is to write a euphoria include that maps the 
>shared object to euphoria.  
The code below may or may not help.
>
>What I'd like even more is if the share object could be 
>distributed as part of the project and not necessarily 
>"installed" on the host.  (ie... no ldconfig).
My understanding of that is you want a file called dog.e that you can
include in multiple projects rather than a dog.dll (or dog.so) which
needs to be installed separately?
>
<snip>
>	mush({"scooby", "dino", "astro", "spike"}) --notice the absence of arg 2
The code below does not pass a length, is that what/all you meant?

--dog.e
global procedure mush(sequence dogs)
integer len
	len=length(dogs)
	printf(1,"Number of dogs: %d \n", len )
	for i=1 to len do
		printf(1,"Dog named: %s starts mushing...\n", {dogs[i]})
	end for
end procedure

global function bark()
	return 1
end function
-- end of dog.e --

include dog.e
if atom(bark()) then
	mush({"scooby", "dino", "astro", "spike"})
end if



Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu