Hi,
I want a library (libdata.a) with a static bool initialized only to call
a function "Function"
So, I create a library (using ar) and link with an empty main
(make; make main)
When I launch ./test_data nothing happen
But if I link main.cpp and data.o directly (make main_a) and launch
./test_data,
I have got "Calling Function" has expected.
So, what is the difference between linking with a .a and a .o ?
I though that *.a was only a set of .o and there were no difference for
the link. (Clearly I am wrong).
And How do I force the wanted effect using a library ?
(The goal is to have a static library with a factory where each Concrete
object register
Itself to the factory using a initialized bool - cf Modern C++ Design
c.8 )
Here my samples with two files and a makefile
// BEGIN data.cpp
#include <iostream>
bool Function() { return std::cout << "Calling Function" << std::endl;
}
namespace { bool staticCall = Function(); }
// END data.cpp
// BEGIN main.cpp
Int main() {}
// END main.cpp
# BEGIN Makefile
libdata.a:data.o
ar -r $@ $^
main:libdata.a
g++ -o test_data main.cpp -L. -ldata
main_a:
g++ -o test_data main.cpp data.o
.cpp.o:
g++ -c -o $@ $<
#END Makefile
Thanks for your help,
David
----------
Ce message et ses pièces jointes (le "message") est destiné à l'usage
exclusif de son destinataire.
Si vous recevez ce message par erreur, merci d'en aviser immédiatement
l'expéditeur et de le détruire ensuite. Le présent message pouvant
être altéré à notre insu, CALYON Crédit Agricole CIB
ne peut pas être engagé par son contenu. Tous droits réservés.
This message and/or any attachments (the "message") is intended for
the sole use of its addressee.
If you are not the addressee, please immediately notify the sender and
then destroy the message. As this message and/or any attachments may
have been altered without our knowledge, its content is not legally
binding on CALYON Crédit Agricole CIB. All rights reserved.
[Non-text portions of this message have been removed]