Thread: How to make a (compiled) code that other programmers can use (cross-platform)?

  1. #1
    Registered User
    Join Date
    Mar 2013

    How to make a (compiled) code that other programmers can use (cross-platform)?

    (C++ question) I need to be able make a compiled code (like a .dll?) which other programmers can use on linux, win,, mac, etc.

    The compiled code would simply do calculations and spit out an answer in memory.

    I need it to have certain functions that they can easily call and understand (without actually seeing the source).

    Does anyone know if this is possible and how?

    Thanks in advance,

  2. #2
    Registered User
    Join Date
    Jun 2005
    If you mean a DLL that can be loaded and executed without modification on all platforms, the answer is no. The only exception is if each platform has a virtual machine or emulator for another platform (eg a windows emulator or platform that can run under linux), but few operating systems support such a capability by default (it relies on other software being installed).

    For example, you could build your library for a Java Virtual Machine (JVM). gcc, for example, can be configured to compile C and C++ code for a JVM. In this case, the JVM would effectively define your target platform (that is what a virtual machine is). The catch is, there needs to be a JVM installed on a target machine. There are also potential concerns with quality of implementation of JVMs installed on different operating systems. This practically is why the Java slogan "write once, run everywhere" is often translated to be "write once, debug everywhere".

    If you want to be able to build dlls (and equivalent) from the same source, for a range of target platforms, there are options.

    The obvious is to rebuild the dll from source for each target platform - the problem being that requires you to have access to a sample of each target platform in order to run the build process on each one.

    Another - often more difficult - approach is to use a cross compiler - a program that can create executable programs for a platform other than the one on which the compiler is running. The trade-off here is that setting up cross-compilers is more complicated than straight compilers, as the setup requires knowledge of both the host system and the target system. Cross compiling also doesn't get you away from the need to build distinct versions for each target platform though, and (unless you test on each target platform) you have no way of verifying that your code will work on each target platform.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Easy cross platform dev
    By Witis in forum Tech Board
    Replies: 6
    Last Post: 01-30-2011, 09:56 AM
  2. Cross-Platform GUI
    By @nthony in forum C++ Programming
    Replies: 4
    Last Post: 10-24-2007, 02:51 PM
  3. Cross platform sockets
    By zacs7 in forum Networking/Device Communication
    Replies: 5
    Last Post: 06-27-2007, 05:16 AM
  4. Cross platform question
    By ~Kyo~ in forum Game Programming
    Replies: 8
    Last Post: 08-25-2005, 04:35 PM
  5. Cross-platform code...
    By Sul in forum C++ Programming
    Replies: 10
    Last Post: 06-18-2004, 04:44 PM