[CMake] g++ -frepo and cmake

Manuel Klimek klimek at box4.net
Wed Jun 14 02:48:25 EDT 2006


Hi,

i'm trying to use cmake with g++ to build template using code
with -frepo for shared libraries.
With -frepo g++ automatically includes the object code only for
template instantiations that are needed at link time. If
you link an executable with g++, say
g++ -frepo -o hello hello.o main.o
and hello.cc uses templates, g++ will insert missing template
instantiations into hello.o until the executable links.
Now this doesn't work for shared libraries:
g++ -frepo -shared -o libhello.so hello.o
will simply compile without adding the extra template instantions
into hello.o.
The gcc mailing list suggests the following solution:
First compile a dummy 'closure' executable, which fails:
g++ -frepo -o libhello_closure hello.cc
(fails complaining about missing symbols)
Afterwards, hello.o contains all the required symbols.
Then
g++ -frepo -shared -o libhello.so hello.o
will yield a library with all symbols as expected.
At the moment I implement this solution using a wrapper
script around g++, which simply looks for -shared, and in
case of -shared first performs the closure step and than
compiles the whole executable.
Because an additional shell indirection slows down my
build process, I wondered if I can integrate the -frepo
concept into my cmake process.
I tried:
- using ADD_EXECUTABLE (with a simple closure.cpp containing a main(...)):
  fails, because in linux symbols are only required at executable
  link time, not at library link time
- using ADD_CUSTOM_COMMAND:
  I don't know how to get the command line cmake would use to create
  a library, so I can't write a custom command - and because g++ would
  return an error code, the build wouldn't work anyways, would it?

So the question is: do you think using a wrapper script is the
only way, or did I miss something and I can do it with cmake?

cheers,
Manuel



More information about the CMake mailing list