Re: A problem building shared library with -single_module and g++
Re: A problem building shared library with -single_module and g++
- Subject: Re: A problem building shared library with -single_module and g++
- From: Rua Haszard Morris <email@hidden>
- Date: Tue, 17 Apr 2007 09:46:36 +1200
Is -fvisibility=hidden what you need?
"When enabled, all symbols are declared 'private extern' unless
explicitly marked to be exported using '__attribute__((visibility
("default")))' in code. If not enabled, all symbols are exported
unless explicitly marked as 'private extern'.
For more information, see <file:///Developer/ADC%
20Reference Library/documentation/DeveloperTools/Conceptual/
CppRuntimeEnv/Articles/SymbolVisibility.html>.
[GCC_SYMBOLS_PRIVATE_EXTERN, -fvisibility=hidden]"
This may work nicely for you the symbols you want exported are marked
as such or if it is feasible to do so (which I understand may not be
the case).
On the other hand I think if you do some doc searches on fvisibility
or __attribute((visibility())) you may also find a way to mark the
'i' specifically as _not_ globally visible (so you don't get a clash
with the one in the other file).
Hope this is helpful
Rua HM.
On Apr 17, 2007, at 2:44 AM, Rustam Muginov wrote:
Hello all.
I had run into problem creating the shared library using common
data and g++.
Here is code snippet:
file 1.c:
int i;
extern void Set(int param)
{
i = param;
}
file 2.c:
int i;
extern int Get()
{
return i;
}
I am compiling it using the command:
gcc -single_module -dynamiclib -o libcommon.dylib 1.c 2.c
everything builds nice, test programm calling Set(123) then Get()
is getting 123 as a result.
Then i try to compile with:
g++ -single_module -dynamiclib -o libcommon.dylib 1.c 2.c
and getting errors:
ld: multiple definitions of symbol _i
/var/tmp//ccTkzUQE.o definition of _i in section (__DATA,__common)
/var/tmp//ccH8kBtk.o definition of _i in section (__DATA,__common)
/usr/bin/libtool: internal link edit command failed
So g++ failed to compile this shared library. I tryed to break
problem down and use separate compile/build stage.
Use C approach
Compile: gcc -c 1.c 2.c
Link: g++ -single_module -dynamiclib -o libcommon.dylib
1.o 2.o
This worked (as well as using other link commands, like
"gcc -single_module -dynamiclib -o libcommon.dylib 1.o 2.o"
or
ld -single_module -dylib -o libcommon.dylib 1.o 2.o
Use C++ approach
Compile: g++ -c 1.c 2.c
Link: g++ -single_module -dynamiclib -o libcommon.dylib 1.o 2.o
This failed with error:
ld: multiple definitions of symbol _i
1.o definition of _i in section (__DATA,__common)
2.o definition of _i in section (__DATA,__common)
/usr/bin/libtool: internal link edit command failed
I tryed to use
gcc -single_module -dynamiclib -o libcommon.dylib 1.o 2.o
and
ld -single_module -dylib -o libcommon.dylib 1.o 2.o
They failed with same diagnostics
So, C does like -single_module. C++ does not.
Next step i went to watch to the object files.
nm -mg 1.o 2.o
For files compiled with g++
1.o:
00000000 (__TEXT,__text) external __Z3Seti
00000000 (absolute) external [no dead strip] __Z3Seti.eh
00000018 (__TEXT,__textcoal_nt) weak private external
___i686.get_pc_thunk.cx
0000001c (__DATA,__common) external _i
2.o:
00000000 (__TEXT,__text) external __Z3Getv
00000000 (absolute) external [no dead strip] __Z3Getv.eh
00000016 (__TEXT,__textcoal_nt) weak private external
___i686.get_pc_thunk.cx
0000001c (__DATA,__common) external _i
For files compiled with gcc
1.o:
00000000 (__TEXT,__text) external _Set
0000001e (__TEXT,__textcoal_nt) weak private external
___i686.get_pc_thunk.cx
00000010 (common) external _i
2.o:
00000000 (__TEXT,__text) external _Get
0000001b (__TEXT,__textcoal_nt) weak private external
___i686.get_pc_thunk.cx
00000010 (common) external _i
So as far as I see, gcc generate symbol which is
(common) external
g++ generates symbol which is
(__DATA,__common) external
A question is:
How can I use g++ compiler and still be able to link dylibs with
common symbols? I do know about "-m" linker flag, but man warns
that it could produce error-prone result, plus i failed to find the
way to supress "duplicated symbols" warning.
Any ideas, please? Thank you in advance.
--
Sincerely,
Rustam Muginov
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40adinstruments.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden