Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Compiling and linking a static C++ library usable from C without linking libstdc++



Hello,

I have a program written in C++ and C that exports C functions. I have been able to create a dynamic library, using:
gcc -dynamiclib ofile1.o ofile2.o -o libfile.dylib -shared-libgcc - lstdc++-static
such that I may simply compile and link a vanilla C program without having to link to the C++ runtime library. For example:
gcc -O3 my_test.c -o my_test -L../libdir -lfile
NOT
gcc -O3 my_test.c -o my_test -L../libdir -lfile -shared-libgcc -lstdc ++-static


The reason I need a static C++ library that can be used by C programs is this: I have a C++ library that will be embedded in the runtime system of a program language compiler that produces assembly code through gcc (not g++). I cannot change the linker flags the compiler passes to gcc, just for a problem on OS X and I cannot require every developer who uses the system to bundle the dynamic library (libfile.dylib) with every program they ship.

I have also created a static library using libtool:
libtool -static -o libfile.a -s -arch_only ppc *.o
but when I want to link to that library, I have to append -shared- libgcc -lstdc++-static (that is, I have to link to the C++ runtime library) every time.


I cannot create a static library using:
	ld -static ...
because ld (or ld called through "gcc -static") produces errors:
	(1) if I specify only -fno-weak, I get an error for:
		lazy symbol pointers (.non_lazy_symbol_pointer),
	(2) if I specify -fno-weak AND -mdynamic-no-pic, I get an error for:
		symbol_stubs

Does anyone here have experience with this sort of thing?
Thanks in advance for any help you can give.

Peter


_______________________________________________ Do not post admin requests to the list. They will be ignored. Unix-porting mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/unix-porting/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.