开发者

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

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 obj开发者_开发技巧ect 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!


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜