Thread: [q-lang-users] modules in c++
Brought to you by:
agraef
From: Brian W. <drc...@gm...> - 2005-08-26 20:54:31
|
Hi folks, I'm sorry if this is off topic, but I'm having a hard time finding doc on the web. I'm trying to write an external module in C++. (It's actually a cover for the Blitz++ array library.) Using the bar.c example from the documentation (reproduced below), the first step in running qcc is always: $ qcc -v bar.c gcc -c bar.c ... So I decided to try the simplest thing I could think of: rename bar.c to bar.cpp, and run g++: g++ -c bar.cpp I get a pack of errors that look like: In file included from bar.cpp:1: C:/Tools/Qpad/include/libq.h:130: error: external linkage required for symbol 'truesym' because of 'dllimport' attribute. C:/Tools/Qpad/include/libq.h:130: error: external linkage required for symbol 'falsesym' because of 'dllimport' attribute. ... My question is: how do I make g++ do the right thing on "dllimport"s? Thanks very much. Brian ----------------- bar.c --------------------- #include <libq.h> MODULE(bar) typedef struct { long i, j; } Bar; FUNCTION(bar,bar,argc,argv) { long i, j; if (argc !=3D 2 || !isint(argv[0], &i) || !isint(argv[1], &j)) return __FAIL; else { Bar *v =3D malloc(sizeof(Bar)); expr x; if (!v) return __ERROR; v->i =3D i; v->j =3D j; return mkobj(type(Bar), v); } } --------------------------------------------- --=20 Brian P. Wilfley, Ph.D. Principal Scientist Voice: 650.331.3476 x102 Fax: 650.887.2205 E-mail: bwi...@tr... Triple Ring Technologies, Inc. 1850 Embarcadero Road Palo Alto, CA 94303 |
From: Brian W. <drc...@gm...> - 2005-08-26 23:19:48
|
Hello again, (I should probably always just wait to email the list until I've done the "next" bit of research...) Here's what I've figured out: 1) The quoted errors can be "fixed" with the following patch to libq.h: ----------------- patch.libq.h ---------------------- *** libq.1.6.h=09Wed Oct 20 01:09:42 2004 --- libq.h=09Fri Aug 26 15:38:04 2005 *************** *** 127,135 **** --- 127,141 ---- =20 /* Predefined function and type symbols. */ =20 + #ifdef __cplusplus + __DLLIMPORT int truesym, falsesym, nilsym, voidsym; + __DLLIMPORT int inttype, floattype, booltype, strtype, filetype, + listtype, tupletype; + #else __DLLIMPORT const int truesym, falsesym, nilsym, voidsym; __DLLIMPORT const int inttype, floattype, booltype, strtype, filetype, listtype, tupletype; + #endif =20 /* Expression construction. */ ---------------------------------------------------- The upshot is that _DLLIMPORT const... is not a happy thing in C++. BUT, not knowing what the heck I'm doing, I don't know what else I've broken. Someone should correct this change before anyone uses it. 2) Also, the cpp source file needs to be changed to protect the exports from name-mangling by enclosing everything in extern "C" {}. The bar.cpp example becomes: ------------------- bar.cpp -------------------- #include <libq.h> extern "C" { MODULE(bar) typedef struct { long i, j; } Bar; FUNCTION(bar,bar,argc,argv) { long i, j; if (argc !=3D 2 || !isint(argv[0], &i) || !isint(argv[1], &j)) return __FAIL; else { Bar *v =3D (Bar *)malloc(sizeof(Bar)); expr x; if (!v) return __ERROR; v->i =3D i; v->j =3D j; return mkobj(type(Bar), v); } } FUNCTION(bar,dump,argc,argv) { long i, j; Bar *v; if (argc !=3D 1 || !isobj(argv[0], type(Bar), (void **)&v)) return __FAIL; else { printf( "i =3D %d, j =3D %d\n", v->i, v->j); return mkint( 0); } } } ------------------------------------------------- Just for completeness, here's the .q file that goes with this: -------------------- bar.q -------------------- // Type Bar public extern type Bar; public extern bar I J; // I, J: integer public extern dump A; // A: Bar test =3D dump (bar 5 3) || =09dump (bar 1000 25); ------------------------------------------------ Lemme know what you think. Brian |
From: Albert G. <Dr....@t-...> - 2005-09-01 00:13:58
|
Brian Wilfley wrote: > + #ifdef __cplusplus > + __DLLIMPORT int truesym, falsesym, nilsym, voidsym; > + __DLLIMPORT int inttype, floattype, booltype, strtype, filetype, > + listtype, tupletype; > + #else > __DLLIMPORT const int truesym, falsesym, nilsym, voidsym; > __DLLIMPORT const int inttype, floattype, booltype, strtype, filetype, > listtype, tupletype; > + #endif Ok, thanks for the fix, I'll commit that asap. > The upshot is that _DLLIMPORT const... is not a happy thing in C++. This entire declspec magic on Windoze is a pita anyway, I wonder what the MS software engineers were smoking when they invented it. ;-) Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikwissenschaft.uni-mainz.de/~ag |
From: Albert G. <Dr....@t-...> - 2005-10-13 09:16:51
|
Hi Brian, I'm about to commit your suggested patch to cvs now. Just to make sure: Which version of mingw/g++ did you use? 2.95.x? 3.x? Brian Wilfley wrote: > Here's what I've figured out: > > 1) The quoted errors can be "fixed" with the following patch to libq.h: > ----------------- patch.libq.h ---------------------- > *** libq.1.6.h Wed Oct 20 01:09:42 2004 > --- libq.h Fri Aug 26 15:38:04 2005 > *************** > *** 127,135 **** > --- 127,141 ---- > > /* Predefined function and type symbols. */ > > + #ifdef __cplusplus > + __DLLIMPORT int truesym, falsesym, nilsym, voidsym; > + __DLLIMPORT int inttype, floattype, booltype, strtype, filetype, > + listtype, tupletype; > + #else > __DLLIMPORT const int truesym, falsesym, nilsym, voidsym; > __DLLIMPORT const int inttype, floattype, booltype, strtype, filetype, > listtype, tupletype; > + #endif > > /* Expression construction. */ -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikwissenschaft.uni-mainz.de/~ag |
From: Brian W. <bwi...@tr...> - 2005-10-29 04:39:06
|
Hi Albert, I'm very sorry for the delay in responding. These emails get sorted into folders, and I've not checked this one in a bit. I rummaged around for some version information. I found the following: in c:\MinGW\include\_mingw.h, #define __MINGW32_VERSION 3.7 And running running the "Add/remove Programs" control panel gives version 1.0.10 for MSYS. Let me know if there's anything else I can help with. Brian On 10/13/05, Albert Graef <Dr....@t-...> wrote: > Hi Brian, > > I'm about to commit your suggested patch to cvs now. Just to make sure: > Which version of mingw/g++ did you use? 2.95.x? 3.x? > > Brian Wilfley wrote: > > Here's what I've figured out: > > > > 1) The quoted errors can be "fixed" with the following patch to libq.h: > > ----------------- patch.libq.h ---------------------- > > *** libq.1.6.h Wed Oct 20 01:09:42 2004 > > --- libq.h Fri Aug 26 15:38:04 2005 > > *************** > > *** 127,135 **** > > --- 127,141 ---- > > > > /* Predefined function and type symbols. */ > > > > + #ifdef __cplusplus > > + __DLLIMPORT int truesym, falsesym, nilsym, voidsym; > > + __DLLIMPORT int inttype, floattype, booltype, strtype, filetype, > > + listtype, tupletype; > > + #else > > __DLLIMPORT const int truesym, falsesym, nilsym, voidsym; > > __DLLIMPORT const int inttype, floattype, booltype, strtype, filetype= , > > listtype, tupletype; > > + #endif > > > > /* Expression construction. */ > > -- > Dr. Albert Gr"af > Dept. of Music-Informatics, University of Mainz, Germany > Email: Dr....@t-..., ag...@mu... > WWW: http://www.musikwissenschaft.uni-mainz.de/~ag > > > ------------------------------------------------------- > This SF.Net email is sponsored by: > Power Architecture Resource Center: Free content, downloads, discussions, > and more. http://solutions.newsforge.com/ibmarch.tmpl > _______________________________________________ > q-lang-users mailing list > q-l...@li... > https://lists.sourceforge.net/lists/listinfo/q-lang-users > -- Brian P. Wilfley, Ph.D. Principal Scientist Voice: 650.331.3476 x102 Fax: 650.887.2205 E-mail: bwi...@tr... Triple Ring Technologies, Inc. 1850 Embarcadero Road Palo Alto, CA 94303 |
From: Brian W. <bwi...@tr...> - 2005-10-29 04:40:07
|
I just realized you wanted to know about g++. Its version is 3.4.2. bpw On 10/13/05, Albert Graef <Dr....@t-...> wrote: > Hi Brian, > > I'm about to commit your suggested patch to cvs now. Just to make sure: > Which version of mingw/g++ did you use? 2.95.x? 3.x? > > Brian Wilfley wrote: > > Here's what I've figured out: > > > > 1) The quoted errors can be "fixed" with the following patch to libq.h: > > ----------------- patch.libq.h ---------------------- > > *** libq.1.6.h Wed Oct 20 01:09:42 2004 > > --- libq.h Fri Aug 26 15:38:04 2005 > > *************** > > *** 127,135 **** > > --- 127,141 ---- > > > > /* Predefined function and type symbols. */ > > > > + #ifdef __cplusplus > > + __DLLIMPORT int truesym, falsesym, nilsym, voidsym; > > + __DLLIMPORT int inttype, floattype, booltype, strtype, filetype, > > + listtype, tupletype; > > + #else > > __DLLIMPORT const int truesym, falsesym, nilsym, voidsym; > > __DLLIMPORT const int inttype, floattype, booltype, strtype, filetype= , > > listtype, tupletype; > > + #endif > > > > /* Expression construction. */ > > -- > Dr. Albert Gr"af > Dept. of Music-Informatics, University of Mainz, Germany > Email: Dr....@t-..., ag...@mu... > WWW: http://www.musikwissenschaft.uni-mainz.de/~ag > > > ------------------------------------------------------- > This SF.Net email is sponsored by: > Power Architecture Resource Center: Free content, downloads, discussions, > and more. http://solutions.newsforge.com/ibmarch.tmpl > _______________________________________________ > q-lang-users mailing list > q-l...@li... > https://lists.sourceforge.net/lists/listinfo/q-lang-users > -- Brian P. Wilfley, Ph.D. Principal Scientist Voice: 650.331.3476 x102 Fax: 650.887.2205 E-mail: bwi...@tr... Triple Ring Technologies, Inc. 1850 Embarcadero Road Palo Alto, CA 94303 |
From: Albert G. <Dr....@t-...> - 2005-10-29 08:34:56
|
Brian Wilfley wrote: > I just realized you wanted to know about g++. Its version is 3.4.2. Ok, thanks. That seems to be a fairly new version. I just wanted to make sure that I don't break any recent setups with the patch. -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikwissenschaft.uni-mainz.de/~ag |