> From: "Yen-Ju Chen" <[EMAIL PROTECTED]>
> 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 <[EMAIL PROTECTED]>
> >Reply-To: <[EMAIL PROTECTED]>
> >To: [EMAIL PROTECTED]
> >CC: [EMAIL PROTECTED]
> >Subject: Re: Link to C++ library
> >Date: Tue, 10 Sep 2002 23:28:28 +0200 (CEST)
> >
> > > From: "Yen-Ju Chen" <[EMAIL PROTECTED]>
> > > 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 <[EMAIL PROTECTED]>
> > > >Date: Tue, 10 Sep 2002 22:38:13 +0200 (CEST)
> > > > > From: "Yen-Ju Chen" <[EMAIL PROTECTED]>
> > > > > 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.
#ifndef stuff_h
#define stuff_h
#ifdef __cplusplus
extern "C" {
#endif
extern void* f_stuff_new(void);
extern int f_stuff_message(void* obj,int a);
#ifdef __cplusplus
}
#endif
#endif
#ifndef stuff_hpp
#define stuff_hpp
class Stuff
{
public:
int x;
int message(int a);
};
#endif
#include <stdio.h>
#include "stuff.h++"
#include "stuff.h"
int Stuff::message(int a)
{
x=a;
return(x+1);
}
void* f_stuff_new(void)
{
return(new Stuff);
}
int f_stuff_message(void* obj,int a)
{
return(((Stuff*)obj)->message(a));
}
#ifdef STANDALONE
int main(void)
{
Stuff* stuff=new Stuff;
printf("first =%d\n",stuff->message(1));
printf("second=%d\n",f_stuff_message((void*)stuff,2));
return(0);
}
#endif
#include "stuff.h"
int main(void)
{
void* stuff=f_stuff_new();
printf("third =%d\n",f_stuff_message(stuff,3));
return(0);
}
all:test-c++ test-objc
test:all
nm test-c++
nm test-objc
./test-c++
./test-objc
test-c++:stuff.c++ stuff.h++ stuff.h
g++ -DSTANDALONE -o test-c++ stuff.c++
stuff.o:stuff.c++ stuff.h++ stuff.h
g++ -c -o stuff.o stuff.c++
main.o:main.m stuff.h
gcc -c -o main.o main.m
test-objc:stuff.o main.o
nm stuff.o
nm main.o
gcc -o test-objc stuff.o main.o
cd /home/pascal/tmp/
make test
g++ -DSTANDALONE -o test-c++ stuff.c++
g++ -c -o stuff.o stuff.c++
gcc -c -o main.o main.m
nm stuff.o
00000000 ? __FRAME_BEGIN__
U __builtin_new
00000050 T f_stuff_message
00000020 T f_stuff_new
00000000 t gcc2_compiled.
00000000 T message__5Stuffi
nm main.o
00000000 d _OBJC_SELECTOR_TABLE
U f_stuff_message
U f_stuff_new
00000000 t gcc2_compiled.
00000000 T main
U printf
gcc -o test-objc stuff.o main.o
nm test-c++
080484b4 t Letext
080497bc A _DYNAMIC
080498a4 A _GLOBAL_OFFSET_TABLE_
080486e0 R _IO_stdin_used
08049898 ? __CTOR_END__
08049894 ? __CTOR_LIST__
080498a0 ? __DTOR_END__
0804989c ? __DTOR_LIST__
0804970c ? __EH_FRAME_BEGIN__
0804970c ? __FRAME_BEGIN__
080497b8 ? __FRAME_END__
080498c8 A __bss_start
U __builtin_new
w __cxa_finalize@@GLIBC_2.1.3
080496fc D __data_start
w __deregister_frame_info
08048680 t __do_global_ctors_aux
080484e0 t __do_global_dtors_aux
w __gmon_start__
U __libc_start_main@@GLIBC_2.0
w __register_frame_info
080498c8 A _edata
080498e0 A _end
080486c0 ? _fini
080486dc R _fp_hw
08048408 ? _init
08048490 T _start
080484b4 t call_gmon_start
08049708 d completed.4
080496fc W data_start
080485e0 T f_stuff_message
080485b0 T f_stuff_new
08048540 t fini_dummy
0804970c d force_to_data
0804970c d force_to_data
08048550 t frame_dummy
080484b4 t gcc2_compiled.
080484e0 t gcc2_compiled.
08048680 t gcc2_compiled.
080486c0 t gcc2_compiled.
08048590 t gcc2_compiled.
08048580 t init_dummy
080486b0 t init_dummy
08048610 T main
08048590 T message__5Stuffi
080498c8 b object.11
08049704 d p.3
U printf@@GLIBC_2.0
nm test-objc
080493b4 t Letext
0804969a t Letext
0804a451 t Letext
0804ab51 t Letext
0804bb52 t Letext
0804bb84 t Letext
0804bc2a t Letext
0804bf87 t Letext
0804cbd2 t Letext
0804d090 W _._10bad_typeid
0804cd70 W _._13bad_exception
0804d1b0 W _._14__si_type_info
0804d470 W _._16__attr_type_info
0804d570 W _._16__func_type_info
0804d670 W _._16__ptmd_type_info
0804d5f0 W _._16__ptmf_type_info
0804d0d0 W _._16__user_type_info
0804d6f0 W _._17__array_type_info
0804d2d0 W _._17__class_type_info
0804d4f0 W _._19__builtin_type_info
0804d3f0 W _._19__pointer_type_info
0804cfd0 W _._8bad_cast
0804cdb0 W _._9bad_alloc
0804cc90 W _._9exception
0804bc30 T _._9type_info
080505bc ? _DYNAMIC
08050694 ? _GLOBAL_OFFSET_TABLE_
0804d7a4 R _IO_stdin_used
0804e974 d _OBJC_SELECTOR_TABLE
0804d060 W __10bad_typeid
0804cd40 W __13bad_exception
0804d280 W __14__si_type_infoPCcRC16__user_type_info
0804d170 W __16__user_type_infoPCc
0804d3a0 W __17__class_type_infoPCcPCQ217__class_type_info9base_infoUi
0804cfa0 W __8bad_cast
0804cc60 W __9exception
0804cee0 W __9type_infoPCc
08050688 ? __CTOR_END__
08050684 ? __CTOR_LIST__
08050690 ? __DTOR_END__
0805068c ? __DTOR_LIST__
0804eacc ? __EH_FRAME_BEGIN__
080504e4 ? __EXCEPTION_TABLE__
08050528 ? __EXCEPTION_TABLE__
08050584 ? __EXCEPTION_TABLE__
0804eacc ? __FRAME_BEGIN__
0804eb50 ? __FRAME_BEGIN__
0804ebdc ? __FRAME_BEGIN__
0804f180 ? __FRAME_BEGIN__
0804f6a0 ? __FRAME_BEGIN__
0804f7bc ? __FRAME_BEGIN__
0804f82c ? __FRAME_BEGIN__
0804fd58 ? __FRAME_BEGIN__
080504e0 ? __FRAME_END__
080507dc A __bss_start
0804bb90 W __builtin_delete
08049550 W __builtin_new
0804a7d0 T __check_eh_spec
0804a550 T __cp_eh_info
0804a520 T __cp_exception_info
0804a6f0 T __cp_pop_exception
0804a680 T __cp_push_exception
0804a610 T __cplus_type_matcher
w __cxa_finalize@@GLIBC_2.1.3
0804e964 D __data_start
080496a0 T __default_terminate
0804a480 T __default_unexpected__Fv
0804b8a0 T __deregister_frame
0804b7e0 T __deregister_frame_info
0804cbe0 t __do_global_ctors_aux
080493e0 t __do_global_dtors_aux
0804c640 T __dynamic_cast
0804a5a0 T __eh_alloc
0804a5e0 T __eh_free
08049c00 T __eh_rtime_match
08049730 T __empty
0804bc70 T __eq__C9type_infoRC9type_info
0804b8d0 T __frame_state_for
080499b0 T __get_dynamic_handler_chain
080497e0 T __get_eh_context
08049800 T __get_eh_info
08049c70 T __get_eh_table_language
08049c60 T __get_eh_table_version
w __gmon_start__
0804e97c d __gthread_active_ptr
0804e990 d __gthread_active_ptr
0804c470 T __is_pointer__FPv
U __libc_start_main@@GLIBC_2.0
0804cf20 W __ne__C9type_infoRC9type_info
08050818 B __new_handler
0804ce60 W __nw__FUiPv
0804b6e0 T __register_frame
0804b660 T __register_frame_info
0804b720 T __register_frame_info_table
0804b7a0 T __register_frame_table
0804a390 T __rethrow
0804c600 T __rtti_array
0804c500 T __rtti_attr
0804bcc0 T __rtti_class
0804c540 T __rtti_func
0804c5c0 T __rtti_ptmd
0804c580 T __rtti_ptmf
0804c4c0 T __rtti_ptr
0804bd10 T __rtti_si
0804bd60 T __rtti_user
08049b00 T __sjpopnthrow
080499e0 T __sjthrow
0804a570 T __start_cp_handler
080496c0 T __terminate
0804e980 D __terminate_func
0804d010 W __tf10bad_typeid
0804ccd0 W __tf13bad_exception
0804d1e0 W __tf14__si_type_info
0804d4a0 W __tf16__attr_type_info
0804d5a0 W __tf16__func_type_info
0804d6a0 W __tf16__ptmd_type_info
0804d620 W __tf16__ptmf_type_info
0804d100 W __tf16__user_type_info
0804d720 W __tf17__array_type_info
0804d300 W __tf17__class_type_info
0804d520 W __tf19__builtin_type_info
0804d420 W __tf19__pointer_type_info
0804cf50 W __tf8bad_cast
0804cdf0 W __tf9bad_alloc
0804cc20 W __tf9exception
0804cea0 W __tf9type_info
0804cb90 T __tfSc
0804cb40 T __tfUc
0804ca00 T __tfUi
0804ca50 T __tfUl
0804caf0 T __tfUs
0804caa0 T __tfUx
0804c820 T __tfb
0804c870 T __tfc
0804c960 T __tfd
0804c9b0 T __tff
0804c780 T __tfi
0804c730 T __tfl
0804c910 T __tfr
0804c7d0 T __tfs
0804c690 T __tfv
0804c8c0 T __tfw
0804c6e0 T __tfx
0804a2d0 T __throw
0804a9b0 T __throw_bad_cast
0804aa50 T __throw_bad_typeid
080496f0 T __throw_type_match
0804bfd0 T __throw_type_match_rtti
080508c4 B __ti10bad_typeid
080508a4 B __ti13bad_exception
080508f0 B __ti14__si_type_info
08050914 B __ti16__attr_type_info
08050908 B __ti16__func_type_info
08050944 B __ti16__ptmd_type_info
08050920 B __ti16__ptmf_type_info
080508e4 B __ti16__user_type_info
0805092c B __ti17__array_type_info
080508fc B __ti17__class_type_info
08050950 B __ti19__builtin_type_info
08050938 B __ti19__pointer_type_info
080508d0 B __ti8bad_cast
080508b8 B __ti9bad_alloc
080508b0 B __ti9exception
080508dc B __ti9type_info
0805089c B __tiSc
08050894 B __tiUc
08050874 B __tiUi
0805087c B __tiUl
0805088c B __tiUs
08050884 B __tiUx
08050844 B __tib
0805084c B __tic
08050864 B __tid
0805086c B __tif
08050834 B __tii
0805082c B __til
0805085c B __tir
0805083c B __tis
0805081c B __tiv
08050854 B __tiw
08050824 B __tix
0804a7a0 T __uncatch_exception
0804e98c d __unexpected_func
08049f40 T __unwinding_cleanup
0804ce80 W __vn__FUiPv
0804ea24 V __vt_10bad_typeid
0804e9ac V __vt_13bad_exception
0804e9fc V __vt_14__si_type_info
0804eaac V __vt_16__attr_type_info
0804ea8c V __vt_16__func_type_info
0804ea6c V __vt_16__ptmd_type_info
0804ea7c V __vt_16__ptmf_type_info
0804ea10 V __vt_16__user_type_info
0804ea5c V __vt_17__array_type_info
0804e9e8 V __vt_17__class_type_info
0804ea9c V __vt_19__builtin_type_info
0804eabc V __vt_19__pointer_type_info
0804ea38 V __vt_8bad_cast
0804e9d4 V __vt_9bad_alloc
0804e9c0 V __vt_9exception
0804ea4c V __vt_9type_info
080507dc A _edata
0805095c A _end
0804d770 ? _fini
0804d7a0 R _fp_hw
08049250 ? _init
08049390 T _start
U abort@@GLIBC_2.0
0804aea0 t add_fdes
0804bf90 T before__C9type_infoRC9type_info
080493b4 t call_gmon_start
0804e970 d completed.4
08049e60 t copy_reg
0804ae70 t count_fdes
0804e964 W data_start
0804bde0 T dcast__C14__si_type_infoRC9type_infoiPvPC9type_infoT3
0804bda0 T dcast__C16__user_type_infoRC9type_infoiPvPC9type_infoT3
0804be40 T dcast__C17__class_type_infoRC9type_infoiPvPC9type_infoT3
0804abb0 t decode_sleb128
0804ab60 t decode_uleb128
080507f4 b eh.127
08049790 t eh_context_free
08049880 t eh_context_initialize
08050810 b eh_context_key
08049950 t eh_context_specific
080498f0 t eh_context_static
08049830 t eh_threads_initialize
0804ac80 t end_fde_sort
0804b270 t execute_cfa_insn
0804b110 t extract_cie_info
080494e0 T f_stuff_message
080494b0 T f_stuff_new
0804ac00 t fde_merge
0804ba50 t fde_split
08049d20 t find_exception_handler
0804b050 t find_fde
08049440 t fini_dummy
0804e974 d force_to_data
0804e9ac d force_to_data
U fprintf@@GLIBC_2.0
08049450 t frame_dummy
0804af10 t frame_init
U free@@GLIBC_2.0
080493b4 t gcc2_compiled.
080493e0 t gcc2_compiled.
0804cbe0 t gcc2_compiled.
0804cc20 t gcc2_compiled.
08049490 t gcc2_compiled.
08049510 t gcc2_compiled.
0804e984 d get_eh_context
08049e10 t get_reg_addr
08049480 t init_dummy
0804cc10 t init_dummy
08050804 b initialized.128
08049510 T main
U malloc@@GLIBC_2.0
U memcpy@@GLIBC_2.0
08049490 T message__5Stuffi
0804cf10 W name__C9type_info
08049740 t new_eh_context
08049ed0 t next_stack_level
0804d829 R nothrow
080507dc b object.11
0804e994 d object_mutex
08050814 b objects
08049c80 t old_find_exception_handler
0804e988 d once.123
0804e96c d p.3
U printf@@GLIBC_2.0
w pthread_create
w pthread_getspecific
w pthread_key_create
w pthread_key_delete
w pthread_mutex_lock@@GLIBC_2.0
w pthread_mutex_trylock
w pthread_mutex_unlock@@GLIBC_2.0
w pthread_once
w pthread_setspecific
0804bb60 T set_new_handler__FPFv_v
0804a4a0 T set_terminate__FPFv_v
0804a4d0 T set_unexpected__FPFv_v
U stderr@@GLIBC_2.0
U strcmp@@GLIBC_2.0
0804a460 T terminate__Fv
08049f50 t throw_helper
08050808 b top_elt.129
0804aaf0 T uncaught_exception__Fv
0804a500 T unexpected__Fv
0804ce40 W what__C9bad_alloc
0804ab20 T what__C9exception
./test-c++
first =2
second=3
./test-objc
third =4
Compilation finished at Wed Sep 11 01:20:27