I'm doing work remotely by connecting to a Linux terminal with ssh. The machine I'm connecting to is a 64 bit x86 Linux machine. My computer is also 64 bit Ubuntu machine with an x86 processor.

I need to hand in program assignments that compile with gcc and run on remote machine or they will not be graded. The professor mentioned that gcc may compile programs differently on different machines and that C not completely portable like Java.

My question is can I write my programs in gedit and debug them with gdb on my computer and upload them with scp (if I do the work by sshing into the remote unix terminal I can only use nano/pico/vim)? Or will my computer compile differently then the remote machine? Again, they are both x86 64bit Linux machines.

  • Can you clarify this, please: "I need to hand in program assignments that compile with gcc and run on remote machine". Does it mean A: the program should also compile on the remote machine, or B. you want to compile it on your machine, then copy the binary to remote? Variant A is the normal Unix way. The downside is that you must consider portability issues between your machine and the remote. Develop and debug on your machine. When ready - compile and run on the remote. If you're lucky, it will Just Work. Otherwise you'll have to debug on the remote. – ddbug Dec 1 '16 at 23:36

If you submit the binary (I would be surprised if you had to do that) it will work (since you mentioned that the architecture of both the machines are same), most probably, unless there is a difference of the installed libraries and you actually end up using some of them.

But assuming that you just have to submit the source code, your code will be compiled on the remote server. This means that as long as you are not using some specific library present on your system, your programs will compile and run on the remote server. But if you end up using such a library, you can specify the linking flags (in your Makefile or mention it explicitly as part of your submission).


As @rhn-grg pointed out, if both machines have the same processor architecture, then the only difference which may prevent your binary from running on another machine is the libraries which your binary is linked against - by default binaries are linked so they load the libraries dynamically which allows to keep the binaries small and also allows to use RAM more efficiently since the library is loaded once but can be used by multiple processes.

However, in cases where you need to ensure "portability" of a binary, you can tell gcc to link the binary statically - i.e. include all libraries it uses into the binary - this will produce a rather large binary but it will not depend on any external libraries.

I never had a need to do this, however, now when you know the magic words (static linking, portable binary) you can find many suggestions in Google, for example this:

Normally, when you download a tarball of source code, you'll do the standard "configure; make; make install" to build it. If you want a statically linked binary, replace the plain "make" with:

make SHARED=0 CC='gcc -static'

To see which libraries your binary depends on, you can use ldd command:

$ ldd /bin/bash
    linux-vdso.so.1 =>  (0x00007fff6dbff000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f8e37337000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f8e37133000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8e36d75000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f8e37587000)

The issue your professor was probably alluding to is that the sizes of various types in C are platform dependent. For instance, you will be able to store much larger numbers in long variables if they are compiled for an x86-64 Linux system, compared to when they are compiled for i386 Linux. For correct programs this isn't a problem, but if you have a program that e.g. uses int and long interchangeably, it may work fine on i386 but fail when run on 64 bit systems.

In contrast, Java uses the same size for basic types on all platforms, so avoids this class of portability problem.

If both your development system and the remote system are x86-64 Linux, then you shouldn't run into any of these sorts of differences. You shouldn't have any problem writing and debugging your programs locally.

With that in mind, if you are graded based on how your program behaves on the remote system it would be worth while testing your finished programs on the remote system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.