[odb-users] Bug: Schema catalog registration not initialized in Visual Studio 2012 RC

Boris Kolpackov boris at codesynthesis.com
Fri Jun 15 06:42:41 EDT 2012


Hi Philippe,

Philippe Cadieux-Pelletier <philly.dilly at gmail.com> writes:

> The code is generated in the same file. The generated code and the code
> that uses it is in the same project put it is a lib.

Ok, I am pretty sure this is the "linking only what's referenced" .lib
behavior. If none of the object files that end up in the executable
reference any symbols from the object file with the registration code,
then it won't be linked to the executable. So, for example, if all your
executable does is create the database schema (and not call any database
operations on persistent classes from this file), then the registration
code won't end up in the executable.

GNU linker has the --whole-archive option which allows you to force
it to add all the files from the static library:

ld ... --whole-archive libgencode.a --no-whole-archive ...

But there doesn't seem to be a similar option in Microsoft linker.
Instead, it is recommended that you use the /INCLUDE:<symbol> option
or #pragma comment(linker, "/INCLUDE:<symbol>") to force the linker
to include the object file that defines this symbol. Of course, if
you try to use one of the C++ symbols from the generated code, then
you will have to provide it in a mangled form, which can be a pain.
Instead, you could add a phony extern "C" symbol to the generated
source file with the --cxx-epilogue option. Then you would use it
in the /INCLUDE option:

odb ... --cxx-epilogue 'extern "C" int person_phony_symbol = 0;' person.hxx

And then in your source file that uses the generated code, you can
add:

#pragma comment(linker, "/INCLUDE:person_phony_symbol")

Boris



More information about the odb-users mailing list