tags:

views:

119

answers:

2

I'm trying to create an object file which can be useable in any computer. So what I did was create bunch of functions and placed them in a .c file. Used gcc -c myfile.c which produces myfile.o. (I'm running Windows XP and got gcc from DevC++) I then create another program which uses my object file.

All seems fine except when I try copying the .o file and use it in another PC. When I copy my file which uses the object file, compile it and run it, it just gives the window that informs me of an error and if I wish to send it an error report.

When I try recompiling the .c file of my object file in the other PC and rerun the program, it seems to work.

So what I don't understand is why I can't just compile the .o file once in one machine, copy it to another machine and create a program that uses the same object file without having to recompile the object file.

Thanks!

+1  A: 

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

chotchki
how different is a shared library object from the usual object?
Paul
Basically it includes additional information to allow he code to be moved around easier.http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.htmlhttp://en.wikipedia.org/wiki/Shared_library#Shared_libraries
chotchki
+3  A: 

Most likely this is because you're using different C libraries. Try to use the exact same gcc version, installed from the same package, on all machines.

So you use the gcc version from DevC++, do not mix it with other gcc packages sush as MinGW.

andremo