tags:

views:

172

answers:

5
+3  Q: 

What is *.o file?

Hi guys. I'm compiling own project. And it halted by this error:

LINK||fatal error LNK1181: cannot open input file 'obj\win\release\src\lua\bindings.o'|

Compiling using Code::Blocks with VS 2005/2008 compiler under win7. There are also lot of another empty directories where *.o files are missing.

What do they do?

+10  A: 

A file ending in .o is an object file. The compiler creates an object file for each source file, before linking them together, into the final executable.

Ink-Jet
Hm, what reasons can be here? Why compiler doesn't made object-files for all need sources?
Ockonal
A compiler can't make an object file for source it doesn't have.
Liz Albin
Can be a lot of reasons. Most likely you messed up some inclusions or messed up a template. It could also be some linker-setting which is wrong, but I doubt that :)
cwap
for ocktonal : it's probably easier to manage smaller files instead of one huge object file in case of problems.
Max
@Ockonal, review the **entire** output log from the compiler. Visual Studio 2008 has a habit of linking files and trying to build an executable when there are earlier compilation errors causing files not to be translated into ".o" (object) files.
Thomas Matthews
+1  A: 

The following link should help you solve your problem:

Microsoft Support Page

Jamie Keeling
+3  A: 

A .o object file file (also .obj on Windows) contains compiled object code (that is, machine code produced by your C or C++ compiler), together with the names of the functions and other objects the file contains. Object files are processed by the linker to produce the final executable. If your build process has not produced these files, there is probably something wrong with your makefile/project files.

anon
A: 

Ink-Jet is right. More specifically, an .o (.obj) -- or object file is a single source file compiled in to machine code (I'm not sure if the "machine code" is the same or similar to an executable machine code). Ultimately, it's an intermediate between an executable program and plain-text source file.

The linker uses the o files to assemble the file executable.

Wikipedia may have more detailed information. I'm not sure how much info you'd like or need.

Frank V
+3  A: 

You've gotten some answers, and most of them are correct, but miss what (I think) is probably the point here.

My guess is that you have a makefile you're trying to use to create an executable. In case you're not familiar with them, makefiles list dependencies between files. For a really simple case, it might have something like:

myprogram.exe: myprogram.o
    $(CC) -o myprogram.exe myprogram.o

myprogram.o: myprogram.cpp
    $(CC) -c myprogram.cpp

The first line says that "myprogram.exe" depends on "myprogram.o". The second line tells how to create myprogram.exe from myprogram.o. The third and fourth lines say myprogram.o depends on myprogram.cpp, and how to create myprogram.o from myprogram.cpp (respectively).

My guess is that in your case, you have a makefile like the one above that was created for gcc. The problem you're running into is that you're using it with MS VC instead of gcc. As it happens, MS VC uses ".obj" as the extension for its object files instead of ".o".

That means when make (built into the IDE in your case) tries to build the program, it looks at those lines to try to figure out how to build myprogram.exe. To do that, it sees that it needs to build myprogram.o, so it looks for the rule that tells it how to build myprogram.o. That says it should compile the .cpp file, so it does that.

Then things break down -- the VC++ compiler produces myprogram.obj instead of myprogram.o as the object file, so when it tries to go to the next step to produce myprogram.exe from myprogram.o, it finds that its attempt at creating myprogram.o simply failed. It did what the rule said to do, but that didn't produce myprogram.o as promised. It doesn't know what to do, so it quits and give you an error message.

The cure for that specific problem is probably pretty simple: edit the make file so all the object files have an extension of ".obj" instead of ".o". There's room for a lot of question whether that will fix everything though -- that may be all you need, or it may simply lead to more (probably more difficult) problems.

Jerry Coffin