1. Compiling to platform independent code

Hey guys, it has been kind of an itch to me. What if you could simply translate the source code of a Euphoria to C, on say Linux then take that C code and compile it on Linux. Then take that C code again and compile it on Apple and then the same C code and compile it on Windows?

For distribution of a new version of Euphoria, we could simply distribute translated C source.

   euc myportable_program.ex 

You get a bunch of C files and now you have something that will compile anywhere. And by anywhere I mean Linux, BSD variants, Apple and Windows only. :) Why mess around with a "plat" argument? We will need to keep the "plat" argument in order to support ifdef, but the Euphoria source that has to do something differently between different platforms can use platform().

new topic     » topic index » view message » categorize

2. Re: Compiling to platform independent code

Euphoria to C. Then take the C files and compile them anywhere. If anyone has a 32-bit machine try to compile these files located over at https://www.steemfiles.com/cgi-bin/view.cgi?id=290 https://www.steemfiles.com/cgi-bin/view.cgi?id=291. Choose "Purchase" and the download will come for free anyway.

Try to compile it on Windows. Try any OS with 32-bit addresses. If it works or not, I want to hear about it!

SD Pringle

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

3. Re: Compiling to platform independent code

You download link gave me:

helloworld.c
main-.c
init-.c

On a 32bit atom linux, so I type: gcc helloworld.c

I had to provide /include/euphoria.h

But, where does "main-.h" come from?

_tom

(Coming from me, who gave up on C when it was still an 8bit language.)

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

4. Re: Compiling to platform independent code

It didn't work but it is not your fault! I forgot to include euphoria.h and main-.h! Yes, you need that and the standard euphoria.h wont work. LOL. Sorry. I'll create a new link with everything that's required. I created these files on Linux. So, if they work on your system, that tells us nothing. It's got to be on a system with a distinct OS.

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

5. Re: Compiling to platform independent code

Okay. It should be easier now that I put wheels on the car. https://www.steemfiles.com/cgi-bin/view.cgi?id=291 . I never thought I would have difficulty finding a Windows user. It makes me smile.

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

6. Re: Compiling to platform independent code

$ gcc helloworld.c 
/usr/lib/gcc/i686-linux-gnu/5/../../../i386-linux-gnu/crt1.o: In function `_start': 
(.text+0x18): undefined reference to `main' 
collect2: error: ld returned 1 exit status 

This is why I use Euphoria.

_tom

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

7. Re: Compiling to platform independent code

same computer 32bit atom, but Win7

found "digital mars" compiler

looks like I a got an executable

can't tell what it is doing because it flashes the console on and off too quickly

_tom

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

8. Re: Compiling to platform independent code

If you run the one liner Euphoria program with the Interpreter does it do the same thing? I think the program is working in GUI mode for Euphoria rather than Console mode. After looking in traninit.e, I think it is possible to recompile it in a way so it becomes a console program.

To compile under Linux using gcc, I did the following:

   gcc -I. *.c -o helloworld /usr/local/lib/eu.a -lm -ldl -lpthread 

Under Watcom, there are distinct link flags necessary you want the program to be used from the command line, and we do want that. It is very encouraging that you got a Windows executable from those files generated on Linux.

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

9. Re: Compiling to platform independent code

Try adding the following options : /SUBSYSTEM:CONSOLE /INFORMATION

So, I'll commit this. And I'll see if I can make the translators create the various build files. Please post the full command line you used to build with Digital Mars.

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

10. Re: Compiling to platform independent code

Unzipped you test program to:

c:\helloworld

Selecting a 'C' compiler was a random walk:

  • turboC [required some .net files which I did not bother with]
  • mingc [files were for 64bit only]
  • digital mars -- no special requirements

Digital Mars unzips to c:/dm

  • no installation needed

$> c:/dm/bin/dmc 

gives you the compiler and a list of flags; no flag for console choice

I randomly tried the -6 flag (which is for 686 code)

From the c:/helloworld folder I type:

$> c:\dm\bin\dmc -6 helloworld.c 

gives me a compiled program which runs just a bit slower than the default of no flags (or my eyes are a bit faster this morning!)

the console lasts just long enough to show that the program compiled correctly 

_tom

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

11. Re: Compiling to platform independent code

On Linux

 $  gcc -I. *.c -o helloworld /usr/local/lib/eu.a -lm -ldl -lpthread  
gcc: error: /usr/local/lib/eu.a: No such file or directory 

_tom

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

12. Re: Compiling to platform independent code

Works on OpenIndiana a.k.a SunOS with some extra libs.
gcc -I. *.c -o helloworld /export/home/agrellum/euphoria/bin/eu.a -lm -ldl -lpthread -lsocket -lnsl

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

13. Re: Compiling to platform independent code

Tom, even if you installed Euphoria to a place other than /usr/local, eu.a should be close to where your eui is installed. If you have it in say /home/tom/euphoria/bin/eui then it would be /home/tom/euphoria/lib/eu.a.

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

14. Re: Compiling to platform independent code

For some reason gcc is not finding eu.a. Using gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5) Using atom 32bit Mint18.3 linux.

My OE has /user/local/euphoria/bin/eu.a

So I copied eu.a to the folder containing helloworld

$ gcc -I. *.c -o helloworld eu.a -lm -ldl -lpthread  
init-.c: In function ‘init_literal’: 
init-.c:27:5: warning: implicit declaration of function ‘setran’ [-Wimplicit-function-declaration] 
     setran(); /* initialize random generator seeds */ 
 

_tom

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

15. Re: Compiling to platform independent code

Trying with Mint 18 (64-bit):

irv@Mint18 ~ $ gcc -I. *.c -o helloworld /usr/local/lib/eu.a -lm -ldl -lpthread 
In file included from helloworld.c:2:0: 
include/euphoria.h:226:7: warning: conflicting types for built-in function ‘malloc’ 
 char *malloc(int); 
       ^ 
In file included from init-.c:1:0: 
include/euphoria.h:226:7: warning: conflicting types for built-in function ‘malloc’ 
 char *malloc(int); 
       ^ 
init-.c: In function ‘init_literal’: 
init-.c:27:5: warning: implicit declaration of function ‘setran’ [-Wimplicit-function-declaration] 
     setran(); /* initialize random generator seeds */ 
     ^ 
In file included from main-.c:3:0: 
include/euphoria.h:226:7: warning: conflicting types for built-in function ‘malloc’ 
 char *malloc(int); 
       ^ 
main-.c: In function ‘main’: 
main-.c:82:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 
     _0switch_ptr = (s1_ptr) NewS1( 17 ); 
                    ^ 
In file included from main-.c:3:0: 
include/euphoria.h:114:31: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] 
 #define MAKE_SEQ(x) ( (int) (((unsigned)(x) >> 3) + (long)0x80000000) ) 
                               ^ 
main-.c:100:18: note: in expansion of macro ‘MAKE_SEQ’ 
     _0switches = MAKE_SEQ( _0switch_ptr ); 

Something tells me that, even if this does work eventually, it isn't going to be exactly user-friendly :)

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

16. Re: Compiling to platform independent code

Another detail. I have OE 4.1 installed. You are hacking 4.0.6

_tom

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

17. Re: Compiling to platform independent code

Installed a fresh virtual Win10 using VirtualBox.

This is on 64bit Mint18 notebook.

A .exe file appears using Digital Mars.

Win10 says it cannot run this file.


For this kind of development we should first start with virtual operating systems. That way at least we can have identical starting points; identical OS and identical OE installations.

_tom

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

18. Re: Compiling to platform independent code

Tried a VirtualBox win7 and I get a message about a cpu violation.

Took a look at my 32bit installation and it now says NTVDM.EXE has stopped working.

Windows does not work.

_tom

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

19. Re: Compiling to platform independent code

So far it is just cross platform (LINUX, Windows, BSD) but not cross architecture (32-bit, 64-bit).

While trying to figure out what options were needed for a Windows build, I found that generation of Makefiles had a flaw: it would always build makefiles for the platform you are on even when alternative platforms were specified. I have a fix for that now, too but I have not done the testing of that fix yet to my satisfaction so I am going to hold off on committing and uploading that one. I want to make sure I didn't accidentally break something.

I need to merge my changes into 4.1 in order to make code generated portable across register sizes (32-bit, 64-bit). I still feel like an idiot sometimes trying to work with git. Can anyone tell me how to merge? This is my last command output uploading to github:

Counting objects: 66, done. 
Delta compression using up to 2 threads. 
Compressing objects: 100% (8/8), done. 
Writing objects: 100% (8/8), 2.22 KiB | 0 bytes/s, done. 
Total 8 (delta 7), reused 0 (delta 0) 
To /home/alumno/development/euphoria-github 
   1fcb6f3..730bb03  git -> git 

How do I merge this into 4.1 and checkout 4.1?

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

20. Re: Compiling to platform independent code

I have figured it out. I am doing some testing on the 4.1 branch with the changes required for it to use git. I will see if it gets a 100% on the unit-tests and if it does, then I'll go on to merge in the 4.0 stuff (including portable source). Meanwhile, for others who want to, they can checkout this https://github.com/shawnpringle/euphoria, run the unit-tests and tell me whether something fails before I put it in the Open Euphoria repo.

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

21. Re: Compiling to platform independent code

Your Branch 4.1 builds OK with my Patches for SunOS:

Hg to Git mkver works.

   Euphoria Interpreter v4.1.0 development 
   32-bit SunOS, Using System Memory 
   Revision Date: 2018-08-30 05:26:57, Id: -1:5f7eedf653d1 
 
ERROR: Must specify the file to be interpreted on the command line 
 
 
Tests Before: My Last Port Work 
Files (run: 406) (failed: 28) (93% success) 
 
Tests After: Your Branch 
Files (run: 406) (failed: 133) (67% success) 
 
But my SunOS port is not ready yet. 
 
Recommendations: 
 
Line 373 euphoria/source/configure * ) could be --help like other projects 
 
Add * ) As ye old build system, Thanks for the flags and variables but we are ok 
 
 
   370          --no-cygwin ) 
   371                  NO_CYGWIN=-mno-cygwin 
   372                  ;; 
   373          * ) 
   374                  echo "Unknown option '$1'" 
   375                  echo "Configures and prepares the euphoria source for building" 
   376                  echo 
   377                  echo "configure [options]" 

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

22. Re: Compiling to platform independent code

By * ) I mean, let UNKNOWN and Boo-boos PASS; Do not exit configure script.

Also note on Tests, I did not watch the offsets my patches suceeded at.

I will look at that when I have time.

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

23. Re: Compiling to platform independent code

Makefile.gnu Lines 808 and 809 are same, latest check-out

   807	test : EUDIR=$(TRUNKDIR) 
   808	test : EUCOMPILEDIR=$(TRUNKDIR) 
   809	test : EUCOMPILEDIR=$(TRUNKDIR)	 
   810	test : C_INCLUDE_PATH=$(TRUNKDIR):..:$(C_INCLUDE_PATH) 

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

Search



Quick Links

User menu

Not signed in.

Misc Menu