[an error occurred while processing this directive] Node:OBJ and LIB, Next:, Previous:ASM and C, Up:Converting

17.5 I want to use a .obj or .lib code with DJGPP

Q: I have a set of useful functions in a .obj format, but no source code. Can I use them with my DJGPP program?

Q: I have this ACMELUXE.LIB library of functions which I want to use. I've extracted all the .obj files, but when I try to link them with my program, GCC complains: "File format not recognized". Can't I use these object files?

Q: I've got a bunch of .obj files I want to use. I've ran AR to make a GCC-style .a object library, but got an error message from GCC saying "couldn't read symbols: No symbols". How can I link them with my code?

A: Sorry, you probably can't. The GNU linker called by GCC doesn't understand the format of .obj files which other DOS-based compilers/assemblers emit. Unless you can get the source of those functions, convert it to protected-mode, flat-address model code and compile them with GCC, you most probably won't be able to use them29.

However, if you are really desperate, one conversion tool you might try is OBJ2BFD. It was written by Robert Hoehne based on the EMXAOUT utility from the emx/gcc package. OBJ2BFD requires the .obj files to be written for the flat-address memory model and will reportedly complain if you feed it with code written for segmented memory models. OBJ2BFD is available from the DJGPP sites.

Another automated conversion tool called OBJ2COFF was written by the SPiRiT team, and it can be used to convert .obj object files and .lib libraries to COFF format, provided that the original .obj files have been written for flat-address memory model.

OBJ2COFF is available via anonymous FTP transfer from the Oulu MSDOS repository. If you have any problems with it or questions about it, send them to its author Rico or to George van Venrooij. Note that the authors of OBJ2COFF have explicitly prohibited commercial use, so you shouldn't use OBJ2COFF for converting commercial object files.

You can also try using LIB32 librarian from Microsoft C8 to convert object files to COFF.

The main problem with these conversion methods is, of course, that most object files you'd want to converted were written for real-mode programs in memory models other than flat, and without extensive modifications would crash your program anyway.... (See previous question.)

[an error occurred while processing this directive]