B
Bramz
Hi all,
I have a rather strange linker (?) problem. At least, I think it's a linker
problem, but I'm not so sure. It's a bit lengthy to describe ...
I've implemented a generic factory similar to the one in 'modern c++ design'
(page 208). To initialize this factory with the different products, I'm
using the same technique on page 204-205 that bassicly looks like:
namespace
{
bool foo() { stuff that needs to be done; }
const bool bar = foo();
}
the real thing looks like the following, which is expanded from the macro
LASS_EXECUTE_BEFORE_MAIN(fdtd::rec::deviceGraphicsFactory()->subscribe("avi"
, fdtd::rec:eviceGraphicsAvi::make):
namespace
{
bool lassDummyName12func ()
{
fdtd::rec::deviceGraphicsFactory()->subscribe("avi",
fdtd::rec:eviceGraphicsAvi::make);
return true;
};
const bool lassDummyName12var = lassDummyName12func ();
}
the problem is that i'm doing this inside a project (MSVC7) that creates a
static library "rec", and this static library is inserted in another project
that builds the executable "app".
So far, no problem i thought, but the funny thing is, it doesn't work in the
file i do want it to be in: "device_graphics_avi.cpp".
LASS_EXECUTE_BEFORE_MAIN(...) never does execute its argument. But if I
move the exact same thing to a file "fdtd.cpp" in the main project for the
executable ("app"), it suddenly _does_ work: the product gets subscribed to
the factory, and all works well.
I even managed to move LASS_EXECUTE_BEFORE_MAIN(...) to another file
"recorder_2d_graphical.cpp" inside the static library project ("rec") where
it _does_ gets executed.
I've tried various things. To replace the code to be executed by simple
dummy code, to expand the macro myself and try various variants on it. But
in the file I want it to be (device_graphics_avi.cpp) the start up code
never gets executed. Whatever I try to execute by
LASS_EXECUTE_BEFORE_MAIN(...) will have the following effect depending on
the file it is in:
static library project:
- "device_graphics_avi.cpp" in "rec": not executed
- "recorder_2d_graphical.cpp" in "rec": _is_ executed
executable project:
- "fdtd.cpp" in "app": _is_executed
I have absolutely _no_ idea what's going on. It's about the exact same code
(just placed in different source files), all source files get compiled
without errors, all projects are build without linker errors. "rec" is
linked in "app". And yet, the start up code is not executed if I put it in
device_graphics_avi.cpp.
I _really_ do want it to put in device_graphics_avi.cpp, since its a single
module, a single product in a single source file that register itself to the
object factory.
The question: Does anyone know what might be going on here? It would be
really helpfull.
Thanks a lot in advance,
Bram de Greve
I have a rather strange linker (?) problem. At least, I think it's a linker
problem, but I'm not so sure. It's a bit lengthy to describe ...
I've implemented a generic factory similar to the one in 'modern c++ design'
(page 208). To initialize this factory with the different products, I'm
using the same technique on page 204-205 that bassicly looks like:
namespace
{
bool foo() { stuff that needs to be done; }
const bool bar = foo();
}
the real thing looks like the following, which is expanded from the macro
LASS_EXECUTE_BEFORE_MAIN(fdtd::rec::deviceGraphicsFactory()->subscribe("avi"
, fdtd::rec:eviceGraphicsAvi::make):
namespace
{
bool lassDummyName12func ()
{
fdtd::rec::deviceGraphicsFactory()->subscribe("avi",
fdtd::rec:eviceGraphicsAvi::make);
return true;
};
const bool lassDummyName12var = lassDummyName12func ();
}
the problem is that i'm doing this inside a project (MSVC7) that creates a
static library "rec", and this static library is inserted in another project
that builds the executable "app".
So far, no problem i thought, but the funny thing is, it doesn't work in the
file i do want it to be in: "device_graphics_avi.cpp".
LASS_EXECUTE_BEFORE_MAIN(...) never does execute its argument. But if I
move the exact same thing to a file "fdtd.cpp" in the main project for the
executable ("app"), it suddenly _does_ work: the product gets subscribed to
the factory, and all works well.
I even managed to move LASS_EXECUTE_BEFORE_MAIN(...) to another file
"recorder_2d_graphical.cpp" inside the static library project ("rec") where
it _does_ gets executed.
I've tried various things. To replace the code to be executed by simple
dummy code, to expand the macro myself and try various variants on it. But
in the file I want it to be (device_graphics_avi.cpp) the start up code
never gets executed. Whatever I try to execute by
LASS_EXECUTE_BEFORE_MAIN(...) will have the following effect depending on
the file it is in:
static library project:
- "device_graphics_avi.cpp" in "rec": not executed
- "recorder_2d_graphical.cpp" in "rec": _is_ executed
executable project:
- "fdtd.cpp" in "app": _is_executed
I have absolutely _no_ idea what's going on. It's about the exact same code
(just placed in different source files), all source files get compiled
without errors, all projects are build without linker errors. "rec" is
linked in "app". And yet, the start up code is not executed if I put it in
device_graphics_avi.cpp.
I _really_ do want it to put in device_graphics_avi.cpp, since its a single
module, a single product in a single source file that register itself to the
object factory.
The question: Does anyone know what might be going on here? It would be
really helpfull.
Thanks a lot in advance,
Bram de Greve