Problem when using C object file (.o) on different computers

I am trying to create an object file that can be used on any computer. So what I did was create a bunch of functions and put them in a .c file. Used gcc -c myfile.c which creates myfile.o. (I am running Windows XP and got gcc from DevC ++). Then I create another program that uses my object file.

Everything seems fine except when I try to copy the .o file and use it on another PC. When I copy my file that uses the object file, compiles it and runs it, it just gives a window that tells me the error and if I want to submit a bug report.

When I try to recompile the .c file of my object file on another PC and restart the program, it works.

So I don't understand why I can't just compile the .o file once on one computer, copy it to another computer, and create a program that uses the same object file without recompiling the object file.

Thank!

+2


source to share


2 answers


Why don't you look into creating a shared library for moving object code? (.so or .dll)



+1


source


This is most likely due to the fact that you are using different C libraries. Try using the same version of gcc installed from the same package on all machines.



So you are using the DevC ++ version of gcc, don't mix it with other gcc packages like MinGW.

+3


source







All Articles