views:

112

answers:

3

I'm trying to compile a set of .c files from an open source project into a static library. I've created a VC++9 project file, set everything up as usual. I add two .c files into the project. They don't have any special compilation settings - all the settings are set at the project level and are set to default except that I turned off the precompiled headers.

I press "Build project" - VC++ says "Done", two .obj files and a .lib file are created but functions from one of the .c files are not present in the resulting .lib file.

If I add #error at the very beginning of one of the two files VC++ stops compilation and reports. But if I do the same with the other file, it just silently compiles and doesn't report the error, so it obviously doesn't compile the file and that's why the functions don't get to the .lib file.

Now I suppose that if I add some text (like #error) as the first line of a .c file the compiler would see it regardless of any preprocessor settings, compiler options, etc. Yet I have a file log.c:

#error
whatever text follows

and Visual C++ reports:

1>------ Build started: Project: MyProject, Configuration: Debug Win32 ------
1>Compiling...
1>log.c
1>Build log was saved at "file://whatever\Debug\BuildLog.htm"
1>MyProject - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

What is happening to the compiler and how do I make it change its mind?

+1  A: 

Go to the Build | Configuration menu.

Is the project checked on for building in your current configuration?

Also check this:

Right click on the .c (or .obj) file and go to properties. Under Configuration Properties -> General, make sure that Excluded From Build is set to No

Also check if you are possibly building via a makefile?

You could also check the 2nd file's .c timestamp. Perhaps it is in the future and so VC++ isn't detecting a change and hence no need to recompile.

Brian R. Bondy
Yes, sure. When a project is not checked VS doesn't even say "Compiling".
sharptooth
@sharptooth: Added a second suggestion to check
Brian R. Bondy
And added another.
Brian R. Bondy
And added another.
Brian R. Bondy
+1  A: 

If you compile it as a right click and then build the project does the linker find the functions and put them in the library.

rerun
Nope, that doesn't change anything.
sharptooth
what happens if you put a call from the one that does compile to the one that doesn't. I would assume you should get an error that it can't link but it would be interesting to see if that comes up.
rerun
+2  A: 

The compiler may think that the object file is up to date with the source. Is the timestamp of one of the object files in the future?

Joe Gauterin