3

I understand that if it even exists it's N times slower than compiler written in native code and compiled for concrete arch. But anyway.

The main purpose is to compile few small c/c++ source files on android device (arm/x86, linux-based os, dalvik jvm). The sources can be created on users android device and compiler should work on users device too.

Any thoughts?

4ntoine
  • 19,816
  • 21
  • 96
  • 220
  • 4
    You don't need a compiler written in Java. You need a compiler that compiles code into Java bytecode. Those are two different things. – Alexey Frunze Mar 31 '13 at 08:26
  • 3
    @AlexeyFrunze I think he mean to compile the files ON the device, not to run on the device. – fbafelipe Mar 31 '13 at 09:20
  • @fbafelipe Actually, you may be right! – Alexey Frunze Mar 31 '13 at 09:23
  • There are a few compilers that run ON Android, but AFAIC the implementations are far from complete, good enough for playing perhaps. Your best option is to get some "cloud" solution that will do remote compilation to you and send you back the results. – dtech Mar 31 '13 at 09:28
  • I meant i need a compiler written in java, which compiles c/c++ sources (for AVR to be more detailed) – 4ntoine Mar 31 '13 at 09:56
  • related to [C compiler written in java](http://stackoverflow.com/q/6276976/309483) – Janus Troelsen Sep 02 '14 at 15:10

4 Answers4

2

There is C4droid, which is an IDE and a C++ compiler on Android. Some plugins enable you to use libraries, such as the SDL, or to use gcc.

If you want to compile really small sources (1 file, no custom libs), you can use codepad or liveworkspace to code on your smartphone. The code is not compiled as an executable, you just see the output (error, stdout, ...).

Synxis
  • 9,236
  • 2
  • 42
  • 64
  • Thanks for the links, i will try it. Codepad and liveworkspace are online tools so they don't suit. – 4ntoine Mar 31 '13 at 10:00
2

If your objective is to compile c/c++ files on an android device, you can still use a C++ compiler written with C++ if you use NDK

fbafelipe
  • 4,862
  • 2
  • 25
  • 40
  • to use gcc for linux i don't need NDK - just execute gcc process with arguments. it's undesired as it requires ROOT permissions and it is platform-dependent as android devices can be ARM or x86 – 4ntoine Mar 31 '13 at 09:57
  • 2
    Running a native compiler on the device does not require root. But you would require multiple versions for the different platforms you wish to support. I think this is likely your best option. – JesusFreke Mar 31 '13 at 19:50
  • sorry, what's native compiler? ndk compiler runs on developer machine and then compiled binary files are just copied in app resources. I need to compile the sources on user device as used is able to edit the sources. – 4ntoine Apr 01 '13 at 07:40
  • 2
    @4ntoine By native compiler he mean compiler compiled in a native language (in this case C or C++). The idea was to port a C++ compiler to NDK, so you compile the *compiler code* on your developer computer, and you run the compiler on the device, so you can compile other sources. – fbafelipe Apr 01 '13 at 08:03
  • oh, i did not catch that. That can probably be the right direction: compile avr-gcc using ndk to make it running on android devices – 4ntoine Apr 01 '13 at 08:06
1

Well, after few weeks of research i can say there is no such thing in nature. For android you should use native compiler but you'l have a lot of compatibility issues so get ready to apply patches, catch exceptions and dive into hundreds of megabytes of native code..

4ntoine
  • 19,816
  • 21
  • 96
  • 220
1

I see several approaches to getting a compiler on your Android device:

Linux on Android

Full blown virtual machine

Compiling to assembly and assembling

From C source to assembly

From assembly to native code

Compiling to JVM bytecode and interpreting

From C source to JVM bytecode

JVM interpreters for the JVM

Community
  • 1
  • 1
Janus Troelsen
  • 20,267
  • 14
  • 135
  • 196