|
From: | Pascal Bourguignon |
Subject: | Re: Link to C++ library |
Date: | Wed, 11 Sep 2002 01:24:02 +0200 (CEST) |
> From: "Yen-Ju Chen" <yjchenx@hotmail.com> > Date: Tue, 10 Sep 2002 17:55:15 -0400 > > > Which version of GCC are you using ? I use 3.0.4. I still have 2.95.3: [pascal@thalassa]$ g++ --version 2.95.3 > How can you compile .c using g++ and .m using gcc > in the same GNUmakefile ? Actually, when specifying CC=g++ in GNUmakefile, the makefile system of GNUstep will use g++ to compile everything, both .c and .m files. > If I use CC=gcc++ at the beginning, > it will complain that g++ unrecognize option '-MP' > and cc1obj invalide option '-fconstant-string-class=NSConstantString' > Here is what I have: > > g++ main.m -c \ > -MMD -MP -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 ... > -o shared_objc/ix86/freebsd/gnu-gnu-gnu/main.o > ... > > So I use CC=gcc to get the .o file first. > Then use CC=g++ again, I got the error in previous message... > > So weird... need to look into it.... The fact is, when you want to link C++ code with C (or Objective-C) code, you have to take care of the name mangling done by the C++ compiler. One way to do it is to use only a C++ compiler, therefore you only generate mangled names (for C and C++ objects) and there's no linking problem. Another option is to use extern "C"{ ... } in C/C++ code. See attached files. > Yen-Ju > > >From: Pascal Bourguignon <pjb@informatimago.com> > >Reply-To: <pjb@informatimago.com> > >To: yjchenx@hotmail.com > >CC: help-gnustep@gnu.org > >Subject: Re: Link to C++ library > >Date: Tue, 10 Sep 2002 23:28:28 +0200 (CEST) > > > > > From: "Yen-Ju Chen" <yjchenx@hotmail.com> > > > Date: Tue, 10 Sep 2002 16:55:52 -0400 > > > > > > > > > Thanx a lot. It helps. > > > But can I directly link Objective-C to C++ throught > > > the C interface which the C++ library offers ? > > > > > > After apply the CC=g++, the error message becomes > > > > > > .../libgnustep-base.so: undefined reference to '__objc_msg_forward' > > > .../libgnustep-base.so: undefined reference to '__objc_msg_thread_add' > > > .../libgnustep-base.so: undefined reference to > >'__objc_msg_thread_remove' > > > > > > Or do I need to write a C library as the bridge between Objective-C > >and > > > C++ ? > > > >You seem to be missing the Objective-C runtime. I still use a GNUstep > >some months old, but it's makefiles automatically cite -lobjc on the > >link line. I have something like: > > > > g++ -rdynamic \ > > -o MyApp.app/ix86/linux-gnu/gnu-gnu-gnu/MyApp \ > > shared_obj/ix86/linux-gnu/gnu-gnu-gnu/MyObjects.o ... \ > > -L/home/pascal/GNUstep/Libraries/ix86/linux-gnu/gnu-gnu-gnu \ > > -L/home/pascal/GNUstep/Libraries/ix86/linux-gnu \ > > -L/local/gnustep/Local/Libraries/ix86/linux-gnu/gnu-gnu-gnu \ > > -L/local/gnustep/Local/Libraries/ix86/linux-gnu \ > > -L/local/gnustep/Network/Libraries/ix86/linux-gnu/gnu-gnu-gnu \ > > -L/local/gnustep/Network/Libraries/ix86/linux-gnu \ > > -L/local/gnustep/System/Libraries/ix86/linux-gnu/gnu-gnu-gnu \ > > -L/local/gnustep/System/Libraries/ix86/linux-gnu \ > > -L/local/gnustep/System/Libraries/ix86/linux-gnu \ > > -lgnustep-gui -lgnustep-base -lobjc \ > > -lz -lcallback -lavcall -lxml2 -lz -lm -lgmp -lpthread -ldl -lm \ > > $(MyApp_OTHER_LIBRARIES) > > > > > > > Thanx again. > > > > > > Yen-Ju > > > > > > >From: Pascal Bourguignon <pjb@informatimago.com> > > > >Date: Tue, 10 Sep 2002 22:38:13 +0200 (CEST) > > > > > From: "Yen-Ju Chen" <yjchenx@hotmail.com> > > > > > Date: Tue, 10 Sep 2002 15:52:52 -0400 > > > > > > > > > > I try to use the id3lib (http://www.id3lib.org), which is a > > > > > C++ library, but offer the C interface. But I met a problem > > > > > about linking between id3lib and standard C++ library. Is it > > > > > possible to use such C++ library with C interface in GNUstep ? > > > > > > > >I do link routinely C++ libraries into GNUstep / Objective-C > > > >applications without any problem, passing thru a C interface. > > > > > > > >Here is an example of GNUmakefile I used lately. The only notable > > > >thing is the use of the g++ compiler (CC=g++) to compile the > > > >MyCppLibCalls.c file, which contains only simple C functions each > > > >sending a message to a C++ object from libMyCppLib.a, which is a > > > >library of C++ objects. -- __Pascal_Bourguignon__ http://www.informatimago.com/ ---------------------------------------------------------------------- The name is Baud,...... James Baud.
stuff.h
Description: Text document
stuff.h++
Description: Text document
stuff.c++
Description: Text document
main.m
Description: Text document
Makefile
Description: Text document
compile.log
Description: Text document
[Prev in Thread] | Current Thread | [Next in Thread] |