C object file compatibility between computers

First, I want to indicate for the record that this issue is related to school / homework.

Suppose that computers CP1 and CP2 use the same operating system and machine language. If program C is compiled on CP1, to transfer it to CP2, you need to transfer the source code and recompile to CP2 or simply transfer the object files.

My gut answer is that object files should be sufficient. C code is converted to assembly by the compiler and assembled by assembler into machine code. Since the architecture has the same machine code and operating system, I see no problem.

But the more I think about it, the more confused I start to get.

My questions:

a) Since it refers to object files and not to executable files, Im assumes that there was no connection. Will there be any problems when connecting to CP2?

b) Does it matter if the code used the C11 standard for CP1, but the only compiler on CP2 was C99? I assume that it doesn't matter if the code was compiled / compiled.

c) The question does not indicate shared / dynamic linked libraries. Thus, this will only work if the program does not depend on the .dll / .so / .dylib files, otherwise they will also be required on CP2.

I feel that there are so many mistakes, and given how vague the question is, I now feel that it would be safer to just recompile.

Halp!

+7
source share
3 answers

Answer: it depends. When you compile a program in C and move the object files for communication on another computer, it should work. But due to factors such as endianness or name mangling , your program may not work as intended, and it may even crash when you try to run it.

C11 not supported by the C99 compiler, but it does not matter if the source has been compiled and compiled.

While the source is compiled with libraries on one computer, you do not need libraries to link or run files on another computer ( only for static libraries ), dynamic libraries must be on the computer on which you run the application). This means that you should make the program independent so that you do not face the same problems as before, when the program does not work properly or crashes.

You can get a compiler that supports EABI so you don't run into these problems. Compilers that support EABI create object code that is compatible with code generated by other such compilers, which allows developers to link libraries generated by one compiler with object code generated by another compiler.

I tried to do this before, but not much, but not recently. Therefore, my information may be 100% inaccurate.

+3
source

a) I have already heard that the term “object files” is used to refer to related binaries - although this is inaccurate. So maybe they mean binary files. I would say that a link to another machine can be problematic if it has a different compiler - if the formats of the object files are not standardized, which I'm not sure about.

b) The use of different standards or even compilers does not matter for binary code - if it is linked statically. If it relies on functions from a dynamic lib, there may be problems. What are the answers c) also: Yes, that will be a problem. The program does not start if the required version does not have all the required dynamic libraries. Depends on the binding mode (static or dynamic), again.

+1
source

Q: Suppose that computers CP1 and CP2 use the same operating system and machine language.

A: Then you can run the same .exe on both computers

Q: If program C is compiled to CP1, to move it to CP2, you need to transfer the source code

A: No. You only need the source code if you want to recompile. You only need to recompile if it is a different, incompatible processor and / or OS.

"Object files" are not needed at all for program execution:

http://en.wikipedia.org/wiki/Object_files

An object file is a file that contains machine code with a movable format that is usually not executed directly. Object files are created by an assembler, compiler, or other language translator and are used as input to the linker.

An "executable program" may require one or more "shared libraries" (aka.dll). In this case, the same restrictions apply: shared libraries, if they are not yet resident, must be copied with .exe and must also be compatible with the CPU and OS.

Finally, “scripts” do not need to be recompiled. You can freely copy the script from computer to computer. But every computer must have an “interpreter” to run the script: a Perl script needs a Perl interpreter, a Python script is a python interpreter, etc.

0
source

All Articles