From: SourceForge.net <no...@so...> - 2005-08-03 20:08:47
|
Bugs item #1251320, was opened at 2005-08-03 14:08 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=1251320&group_id=2435 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: gcc Group: None Status: Open Resolution: None Priority: 5 Submitted By: cfis (cfis) Assigned to: Danny Smith (dannysmith) Summary: gcc ignores __declspec Initial Comment: I'm using mingw/msys to build an extension for a windows build of ruby. The ruby header files have the following code (from defines.h): //#undef RUBY_EXTERN //#if defined _WIN32 && !defined __GNUC__ #if defined _WIN32 # ifndef RUBY_EXPORT # define RUBY_EXTERN extern __declspec(dllimport) # endif #endif For the extension to work RUBY_EXTERN needs to be defined as extern __declspec(dllimport). However, when I run this: gcc my_test.c -U__GNUC__ -I/(..path to ruby.h..) I get an extension that does not work. Using the gcc -E switch to investigate further, I've found that the preprocessor is defining RUBY_EXTERN as just "extern" - the __declspec is ignored (yes I've verified this part of the code is called because I can change it to anything else and it is picked up by the preprocessor). Investigating further, the problem appears to be somehow related to the !defined __GNUC__ call. Thus, if I modify the ruby code to uncomment the __GNUC__ check like below things work: //#undef RUBY_EXTERN //#if defined _WIN32 // && !defined __GNUC__ #if defined _WIN32 # ifndef RUBY_EXPORT # define RUBY_EXTERN extern __declspec(dllimport) # endif #endif Thus there appears to be something strange going on in the preprocessor. Note if you change the code as above you can run gcc like this, without the undefine. gcc my_test.c -I/(..path to ruby.h..) This works fine. Thanks, Charlie ------------------------------------------------------------ My setup: windows xp, sp 2 $ gcc -v Reading specs from d:/mingw/bin/../lib/gcc/mingw32/3.4.4/specs Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug Thread model: win32 gcc version 3.4.4 (mingw special) $ ld -v GNU ld version 2.15.94 20050118 Release: MinGW-4.1.0.exe $ uname -a MINGW32_NT-5.1 TRILOBITE 1.0.11(0.46/3/2) 2004-04-30 18:55 i686 unknown ------------------------------- Simple Ruby extension: #include "ruby.h" static int id_push; static VALUE t_init(VALUE self) { VALUE arr; arr = rb_ary_new(); rb_iv_set(self, "@arr", arr); return self; } static VALUE t_add(VALUE self, VALUE obj) { VALUE arr; arr = rb_iv_get(self, "@arr"); rb_funcall(arr, id_push, 1, obj); return arr; } VALUE cTest; void Init_my_test() { cTest = rb_define_class("MyTest", rb_cObject); rb_define_method(cTest, "initialize", t_init, 0); rb_define_method(cTest, "add", t_add, 1); id_push = rb_intern("push"); } -------------------- To compile (and the resulting error): $ reimp /c/Development/ruby/lib/msvcrt-ruby18.lib [creates libmsvcrt-ruby18.a in current directory] $ gcc -g -c my_test.c -I/c/Development/ruby/lib/ruby/1.8/i386-mswin32 $gcc -shared my_test.o -o my_test.so -lmsvcrt-ruby18 -L. $ ruby -C . -e "require 'my_test'" ./my_test.so: wrong argument type Fixnum (expected Class) (TypeError) from c:/Development/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require' from -e:1 ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=1251320&group_id=2435 |