- #1
- 14,981
- 26
Here's my (UNIX) situation.
I have three object files:
program.o
public.o
private.o
public.o is "standalone" -- it is entirely self-contained.
program.o refers to functions defined in public.o
private.o is "hidden" -- neither program.o nor private.o make any reference to anything contained in private.o. However, private.o contains some static initialization that calls functions in public.o. (Essentially registering itself with the features that public.o provides)
Linking them together is no problem. I simply do:
g++ program.o public.o private.o
and a.out does exactly what I expect it to do.
Then, I tried a variation. I put public.o and private.o into a library. I think the command was
ar crsu libtest.a public.o private.o
Now, I link program.o with this library
g++ program.o -L. -ltest
This doesn't work, because private.o's startup code is never executed.
I also tried
g++ program.o libtest.a
and got the same result.
Can I do anything to have this all behave like I want? (But without having program.o or public.o reference anything in private.o?)
I have three object files:
program.o
public.o
private.o
public.o is "standalone" -- it is entirely self-contained.
program.o refers to functions defined in public.o
private.o is "hidden" -- neither program.o nor private.o make any reference to anything contained in private.o. However, private.o contains some static initialization that calls functions in public.o. (Essentially registering itself with the features that public.o provides)
Linking them together is no problem. I simply do:
g++ program.o public.o private.o
and a.out does exactly what I expect it to do.
Then, I tried a variation. I put public.o and private.o into a library. I think the command was
ar crsu libtest.a public.o private.o
Now, I link program.o with this library
g++ program.o -L. -ltest
This doesn't work, because private.o's startup code is never executed.
I also tried
g++ program.o libtest.a
and got the same result.
Can I do anything to have this all behave like I want? (But without having program.o or public.o reference anything in private.o?)