473,772 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problems with startup code in static libraries.

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_BE FORE_MAIN(fdtd: :rec::deviceGra phicsFactory()->subscribe("avi "
, fdtd::rec::Devi ceGraphicsAvi:: make);):

namespace
{
bool lassDummyName12 func ()
{
fdtd::rec::devi ceGraphicsFacto ry()->subscribe("avi ",
fdtd::rec::Devi ceGraphicsAvi:: make);
return true;
};
const bool lassDummyName12 var = lassDummyName12 func ();
}

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_graphic s_avi.cpp".
LASS_EXECUTE_BE FORE_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_BE FORE_MAIN(...) to another file
"recorder_2d_gr aphical.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_graphic s_avi.cpp) the start up code
never gets executed. Whatever I try to execute by
LASS_EXECUTE_BE FORE_MAIN(...) will have the following effect depending on
the file it is in:
static library project:
- "device_graphic s_avi.cpp" in "rec": not executed
- "recorder_2d_gr aphical.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
Jul 22 '05 #1
2 1621
"Bramz" <br**********@m ail.be> wrote...
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 ...
[...]
The question: Does anyone know what might be going on here? It would be
really helpfull.


Yes, somebody in a newsgroup dedicated to your compiler is bound to know.
Linking is compiler- and platform-specific and as such OT here.
Jul 22 '05 #2
Victor: my apologies, I'm not a frequent user of newsgroups, and I wasn't
really aware I should ask this question in here. Next time, I'll try to
find a more proper newsgroup :)

Martijn: thank you for your answer. It confirms what I already suspected.

Thank you for your time,
Bramz


Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2268
by: Nolan Martin | last post by:
How would I go about calling a function before the main function is called? The function needs to be called multiple times from different locations. I have something like this working but it is more of a hack than anything... ---FOO.cpp--- bool func() { dostuff; return 0; };
1
2543
by: rajesh_krec | last post by:
Hello Everybody, I'm using Microsoft Visual Studio .NET 2003 (with Vc7 compiler) I have some 15 projects each of which generate a static library when i build the solution in release mode. The solution also contains a project which includes all the above generated static libraries.I have set all the above projects as dependent projects in the 'Project Dependencies' option.
2
20635
by: Tom | last post by:
Hi all In winform application I am trying to start 2 forms I am trying to show the 2nd winform on a separate thread. using Thread mainapp = new Thread(new ThreadStart(loadmainscm)); mainapp.Start(); //where
16
2539
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
2
1574
by: Marcelo Fernandez | last post by:
Hi ! I am having a lot of trouble compiling my directshow filter with third party libraries. In fact, I would like to know if there is an application that can tell me if the library has been generated in MT, MD, MDd or MTd mode. I do not have direct access to this libraries so I cannot recompile them as I would like them to be.
84
3542
by: jacob navia | last post by:
As many people know, I think that garbage collection is a good solution for many memory allocation problems. I am aware however, that nothing is "the silver bullet", not even the GC. A recent article in slashdot http://developers.slashdot.org/article.pl?sid=07/11/17/0552247 proves that.
0
1649
by: ycinar | last post by:
hey all, i am working on a Java project using JBuilder.. when i build my code its fine, but when comes to run, it doesnt run and displays the following logs.. i think there is JDK conflict.. actually when i build it, it creates a jar file which is totally fine (i can confirm that because i use that jar file in another project) any idea on how to get around this? maybe i could try to run it from the command line, but dont know how to run...
4
4385
by: mechphisto | last post by:
I'm working on a friend's box, Fedora Core 6. It has PHP 5.1.6. I need to install mcrypt into it, and the only way I can find to do it is from source then recompile PHP. So I did all that, and got the latest PHP, 5.2.5. The ./configure finally went through OK. Make and make install. Then I restarted Apache... but the phpinfo() shows no change. It's still using 5.1.6. When I run "php -v" from command line I get a huge error I'll include...
1
4524
by: BobLewiston | last post by:
I tried to compile a Windows Forms Application in Visual C# 2008 Express with this source code from the CSharpSchool tutorial at Programmer's Heaven:using System; using System.Windows.Forms; using System.Drawing; namespace CSharpSchool { class HelloWinForm { static void Main () { Application.Run (new MyWindow ());
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.