Hello,
I am new to this list, so "HELLO TO EVERYBODY"
About my programming subject: I am investigating for a small naval architectural bureau, If they can port their DOS/WIN pascal programs to linux. I am a student of naval architecture with small programming experience under Pascal and C++. The company also asked me to have a look at GUI toolkits and write a graphical subsystem for their pascal program. I would like to use QT for this purpose. I made some small tests already, and found out that the compatibility with GPC and Prospero extended pascal is sufficient (small problems). My problem is that I can not use a c++ library in my pascal program. For C everything works allright, but as soon as I compile with g++ I get errors. I also noticed that the assembler output of the compiler is different when compiling C or C++ sources. I tried compiling with gpc -x, etc. Still I run into problems. I use gpc based on egcs 1.1.2 as well as based on gcc 2.95.2 (on two different pc's).
Attached is a small, very dumb test program, partially stolen from the excellent info pages of gpc.
It consists of two files: add_one.c and test.pas
test.pas is the program; it writes the number five, and lets the function number_pp add one (+1) to the number. It then displays number again.
I compiled it in several ways, of which this one is the simplest:
gcc -c add_one.c gpc -o test test.pas add_one.o
If the first line is replaced with: g++ -c add_one.c line number two fails linking.
Does anybody have an idea of how to use c++ libraries in pascal? Help is very much appreciated.
Greetings,
Menno Schaap
Menno Schaap wrote:
About my programming subject: I am investigating for a small naval architectural bureau, If they can port their DOS/WIN pascal programs to linux. I am a student of naval architecture with small programming experience under Pascal and C++. The company also asked me to have a look at GUI toolkits and write a graphical subsystem for their pascal program. I would like to use QT for this purpose. I made some small tests already, and found out that the compatibility with GPC and Prospero extended pascal is sufficient (small problems). My problem is that I can not use a c++ library in my pascal program. For C everything works allright, but as soon as I compile with g++ I get errors. I also noticed that the assembler output of the compiler is different when compiling C or C++ sources. I tried compiling with gpc -x, etc. Still I run into problems. I use gpc based on egcs 1.1.2 as well as based on gcc 2.95.2 (on two different pc's).
It is possible to combine Pascal, C and C++ code using the GNU compilers (I did such a group project last year), but there's a few things to note.
The problem you're experiencing is the "name mangling" C++ does: Because it allows function overloading, it has to change the "asmname" of each function, so they become distinct. You can prevent this with an `extern "C"' directive (that's how C++ programs use the usual system routines, AFAIK). E.g., the following works for me with your Pascal code:
extern "C" { int number = 0; void number_pp (void); }
void number_pp (void) { number = number + 1; }
If, however, the C++ code is in a library you can't (or don't want to) change this way, you'll have to use wrapper routines (i.e. small routines written in C++, declared as `extern "C"' which call the library and can be called by Pascal code).
Other things to note:
- Both C++ and Pascal use specific runtime libraries (-lstdc++ for C++, AFAIK, and -lgpc for GPC). Whether you use g++ or gpc for the final linking compilation, only one of them will be linked automatically. So you'll have to add the other one explicitly on the command line, but that shouldn't be a problem.
E.g., if you use gpc for linking, give `-lstdc++', or put a `{$L stdc++}' directive in the Pascal source. If you use g++ for linking, note that GPC also needs the math library, so give `-lgpc -lm' on the command line.
(In the example you gave, this was not necessary, probably because nothing of libstdc++ was actually used, but for non-trivial programs, it will become necessary.)
It is very much recommended that the gpc and g++ used are based on the same backend (i.e., gcc) version (2.95.x these days), otherwise things become more difficult (e.g., you'll have to specify paths to the libraries, and they might not even cooperate well)...
- The objects of C++ and GPC are different internally. AFAIK, there's no direct way to safely use them from the other language. If you need to use them, you might have to write non-OOP wrapper routines.
Finally, please note that in current GPC versions, the syntax:
VAR Number : asmname 'number' Integer;
was changed to:
VAR Number : Integer; asmname 'number'; external;
(Not yet for procedures, but that'll happen soon.)
Frank
Menno Schaap mennos@capitolonline.nl el dÃa Mon, 28 Aug 2000 15:21:20 +0200, escribió:
Hello,
I am new to this list, so "HELLO TO EVERYBODY"
About my programming subject: I am investigating for a small naval architectural bureau, If they can port their DOS/WIN pascal programs to linux. I am a student of naval
architecture
with small programming experience under Pascal and C++. The company also
asked
me to have a look at GUI toolkits and write a graphical subsystem for their pascal program. I would like to use QT for this purpose.
I think using Qt for this purpose involves buying a license from Troll Tech... have you looked at gtk ? (wich is in C and LGPL'ed) http://www.gtk.org
sergio
Hello Sergio,
I think using Qt for this purpose involves buying a license from Troll Tech... have you looked at gtk ? (wich is in C and LGPL'ed) http://www.gtk.org
sergio
Thanks for your suggestion. You are right about the license, which is indeed very expensive. But I think that the company is willing to pay for it. I have no experience yet with either toolkits but a small study at the structure tips the balance to QT, at least for me. I am a naval architect (almost) not a programmer, and so are the people of the company, I think that if the code is well written in QT it is clearer and better reusable (e.g. inheritance) for them. But a final decision is not made yet. If other people have ideas about this, feel free to mail me, but maybe off this mailing list (??), since it has nothing to do with GPC.
Thanks, Menno
Hi Frank,
Thanks a lot, as a non-programmer, I did not take the name mangling of c++ in account. Your explanation is well understandable and clear, as I have written c++ programs with overloading. Now I remember from my C++ book that the compiler distinguishes functions by the types used in its declaration. Also thanks for your compilation and linking options as well as the syntax change. BTW, I am planning to move to a new distro, slackware 7.1. GPC is not included, so I have to build it from source. Do you recommend to install ("patch") it on top of gcc or egcs. egcs is standard for slack, but if I am meddling around already, why not change this also. I am not certain yet if the work on this subject will continue for me, we are just looking for possibilities. Anyway, you will hear more from me about it.
Thanks again, looking forward to hear more from you.
Greetings, Menno
On Mon, 28 Aug 2000, you wrote:
Menno Schaap wrote:
About my programming subject: I am investigating for a small naval architectural bureau, If they can port their DOS/WIN pascal programs to linux. I am a student of naval architecture with small programming experience under Pascal and C++. The company also asked me to have a look at GUI toolkits and write a graphical subsystem for their pascal program. I would like to use QT for this purpose. I made some small tests already, and found out that the compatibility with GPC and Prospero extended pascal is sufficient (small problems). My problem is that I can not use a c++ library in my pascal program. For C everything works allright, but as soon as I compile with g++ I get errors. I also noticed that the assembler output of the compiler is different when compiling C or C++ sources. I tried compiling with gpc -x, etc. Still I run into problems. I use gpc based on egcs 1.1.2 as well as based on gcc 2.95.2 (on two different pc's).
It is possible to combine Pascal, C and C++ code using the GNU compilers (I did such a group project last year), but there's a few things to note.
The problem you're experiencing is the "name mangling" C++ does: Because it allows function overloading, it has to change the "asmname" of each function, so they become distinct. You can prevent this with an `extern "C"' directive (that's how C++ programs use the usual system routines, AFAIK). E.g., the following works for me with your Pascal code:
extern "C" { int number = 0; void number_pp (void); }
void number_pp (void) { number = number + 1; }
If, however, the C++ code is in a library you can't (or don't want to) change this way, you'll have to use wrapper routines (i.e. small routines written in C++, declared as `extern "C"' which call the library and can be called by Pascal code).
Other things to note:
Both C++ and Pascal use specific runtime libraries (-lstdc++ for C++, AFAIK, and -lgpc for GPC). Whether you use g++ or gpc for the final linking compilation, only one of them will be linked automatically. So you'll have to add the other one explicitly on the command line, but that shouldn't be a problem.
E.g., if you use gpc for linking, give `-lstdc++', or put a `{$L stdc++}' directive in the Pascal source. If you use g++ for linking, note that GPC also needs the math library, so give `-lgpc -lm' on the command line.
(In the example you gave, this was not necessary, probably because nothing of libstdc++ was actually used, but for non-trivial programs, it will become necessary.)
It is very much recommended that the gpc and g++ used are based on the same backend (i.e., gcc) version (2.95.x these days), otherwise things become more difficult (e.g., you'll have to specify paths to the libraries, and they might not even cooperate well)...
The objects of C++ and GPC are different internally. AFAIK, there's no direct way to safely use them from the other language. If you need to use them, you might have to write non-OOP wrapper routines.
Finally, please note that in current GPC versions, the syntax:
VAR Number : asmname 'number' Integer;
was changed to:
VAR Number : Integer; asmname 'number'; external;
(Not yet for procedures, but that'll happen soon.)
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/ GPC To-Do list, latest features, fixed bugs: http://agnes.dida.physik.uni-essen.de/~gnu-pascal/todo.html
On Mon, 28 Aug 2000 ser@perio.unlp.edu.ar wrote:
I think using Qt for this purpose involves buying a license from Troll Tech... have you looked at gtk ? (wich is in C and LGPL'ed) http://www.gtk.org
I don't think so; Qt for Linux is under a free software license (the QPL), so there shouldn't be any problem.
However, writing Pascal bindings for Qt and gtk might be difficult, because you would have to adapt somehow Qt's metacompiler (moc) or gtk's macros to Pascal. Perhaps it would be easier to use the existent Pascal code as a backend, and do all the GUI work in C or C++ with the toolkit of your choice (I like Qt better, but that is a matter of taste).
Just a thought.
-- Miguel
Menno Schaap wrote:
BTW, I am planning to move to a new distro, slackware 7.1. GPC is not included, so I have to build it from source. Do you recommend to install ("patch") it on top of gcc or egcs. egcs is standard for slack, but if I am meddling around already, why not change this also.
egcs is not supported anymore with GPC, so try gcc-2.95.x (or perhaps soon gcc-3.x... :-)
Frank
On 28 Aug 00, at 21:28, Menno Schaap wrote:
Hi Frank,
Thanks a lot, as a non-programmer, I did not take the name mangling of c++ in account. Your explanation is well understandable and clear, as I have written c++ programs with overloading. Now I remember from my C++ book that the compiler distinguishes functions by the types used in its declaration. Also thanks for your compilation and linking options as well as the syntax change. BTW, I am planning to move to a new distro, slackware 7.1. GPC is not included, so I have to build it from source. Do you recommend to install ("patch") it on top of gcc or egcs. egcs is standard for slack, but if I am meddling around already, why not change this also. I am not certain yet if the work on this subject will continue for me, we are just looking for possibilities.
Do you have any specific reason for choosing Qt? Gtk might be easier to use with Pascal. I know that the FreePascal people already have Pascal units for the Gtk libraries. You might be able to use thoseas a starting point.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) Author of: Chief's Installer Pro v5.22.1 for Win32 http://www.bigfoot.com/~African_Chief/chief32.htm Email: African_Chief@bigfoot.com
Hello Chief,
The program I (maybe) have to write an interface for, is written in such a way, that no direct graphical calls (to xlib, qt, or gtk) are done in the pascal program. In the program, there are only calls to a graphical sublayer (own design). The reason for this is that now only the graphical layer has to be rewritten, and the port to an other operating system is finished. Ofcourse the operating system needs a Pascal compiler (in this case extended pascal).
This approach also means that this layer does not need to be written in Pascal. Since QT is mainly designed for C++, and GTK+ mainly for c / obj-c, it is as far as I can see easier to write in C/C++. Personally I also prefer to write in C++, since it's OOP structure is IMO superior to a procedural approach. But I will try to find some Pascal units where GTK+ is used, since it is interesting anyway.
Thanks, Menno
On Wed, 30 Aug 2000, Prof Abimbola Olowofoyeku wrote: > On 28 Aug 00, at 21:28, Menno Schaap wrote:
Hi Frank,
Thanks a lot, as a non-programmer, I did not take the name mangling of c++ in account. Your explanation is well understandable and clear, as I have written c++ programs with overloading. Now I remember from my C++ book that the compiler distinguishes functions by the types used in its declaration. Also thanks for your compilation and linking options as well as the syntax change. BTW, I am planning to move to a new distro, slackware 7.1. GPC is not included, so I have to build it from source. Do you recommend to install ("patch") it on top of gcc or egcs. egcs is standard for slack, but if I am meddling around already, why not change this also. I am not certain yet if the work on this subject will continue for me, we are just looking for possibilities.
Do you have any specific reason for choosing Qt? Gtk might be easier to use with Pascal. I know that the FreePascal people already have Pascal units for the Gtk libraries. You might be able to use thoseas a starting point.
Best regards, The Chief
Prof. Abimbola A. Olowofoyeku (The African Chief) Author of: Chief's Installer Pro v5.22.1 for Win32 http://www.bigfoot.com/~African_Chief/chief32.htm Email: African_Chief@bigfoot.com
Thanks a lot, as a non-programmer, I did not take the name mangling of c++ in account. Your explanation is well understandable and clear, as I have written c++ programs with overloading. Now I remember from my C++ book that the compiler distinguishes functions by the types used in its declaration. Also thanks for your compilation and linking options as well as the syntax change. BTW, I am planning to move to a new distro, slackware 7.1. GPC is not included, so I have to build it from source. Do you recommend to install ("patch") it on top of gcc or egcs. egcs is standard for slack, but if I am meddling around already, why not change this also. I am not certain yet if the work on this subject will continue for me, we are just looking for possibilities.
Do you have any specific reason for choosing Qt? Gtk might be easier to use with Pascal. I know that the FreePascal people already have Pascal units for the Gtk libraries. You might be able to use thoseas a starting point.
Kylix (Delphi for Linux) will be in QT.
But if you do commercial programming with GPC and QT, you must pay licenses!!!
On 30 Aug 00, at 7:42, Menno Schaap wrote:
Hello Chief,
The program I (maybe) have to write an interface for, is written in such a way, that no direct graphical calls (to xlib, qt, or gtk) are done in the pascal program. In the program, there are only calls to a graphical sublayer (own design). The reason for this is that now only the graphical layer has to be rewritten, and the port to an other operating system is finished. Ofcourse the operating system needs a Pascal compiler (in this case extended pascal).
Well you are in luck. GPC is such a compiler, and it is available on many platforms. You mentioned earlier some minor compatibility problems with Prospero EP. You might want to provide details of these to Peter, to see if he can do anything about it.
This approach also means that this layer does not need to be written in Pascal. Since QT is mainly designed for C++, and GTK+ mainly for c / obj-c, it is as far as I can see easier to write in C/C++. Personally I also prefer to write in C++, since it's OOP structure is IMO superior to a procedural approach.
The advantage of Gtk, AFAICS is that the libraries can be linked directly with GPC programs, without any fuss. This becomes significant when you are thinking of possibly porting your application to other platforms apart from the one that you currently have in mind. There is of course nothing stopping anyone from providing OOP wrappers (either in C++ or Pascal) for the Gtk functions.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) Author of: Chief's Installer Pro v5.22.1 for Win32 http://www.bigfoot.com/~African_Chief/chief32.htm Email: African_Chief@bigfoot.com
On Wed, Aug 30, 2000 at 09:23:34AM +0200, Marco van de Voort wrote:
Thanks a lot, as a non-programmer, I did not take the name mangling of c++ in account. Your explanation is well understandable and clear, as I have written c++ programs with overloading. Now I remember from my C++ book that the compiler distinguishes functions by the types used in its declaration. Also thanks for your compilation and linking options as well as the syntax change. BTW, I am planning to move to a new distro, slackware 7.1. GPC is not included, so I have to build it from source. Do you recommend to install ("patch") it on top of gcc or egcs. egcs is standard for slack, but if I am meddling around already, why not change this also. I am not certain yet if the work on this subject will continue for me, we are just looking for possibilities.
Do you have any specific reason for choosing Qt? Gtk might be easier to use with Pascal. I know that the FreePascal people already have Pascal units for the Gtk libraries. You might be able to use thoseas a starting point.
Kylix (Delphi for Linux) will be in QT.
But if you do commercial programming with GPC and QT, you must pay licenses!!!
That's not quite true; if your program is not open source, you need to buy a license. You're welcome to sell an open source product created with Qt/X11 Free Edition.
Well you are in luck. GPC is such a compiler, and it is available on many platforms. You mentioned earlier some minor compatibility problems with Prospero EP. You might want to provide details of these to Peter, to see if he can do anything about it.
I agree, and ofcourse I will contribute. But at this momen twe are just investigating, and I am busy with other jobs. As soon as I start, I will log everything and try to provide some good documenation. Right now I just know to less.
The advantage of Gtk, AFAICS is that the libraries can be linked directly with GPC programs, without any fuss. This becomes significant when you are thinking of possibly porting your application to other platforms apart from the one that you currently have in mind. There is of course nothing stopping anyone from providing OOP wrappers (either in C++ or Pascal) for the Gtk functions.
I agree again, although the structure of QT looks more promising to me (just because I like C++). But the extern "C" {} declaration which is necessary to link it with other languages such as C, is very well possible, but it does not make a source nice and clean to read. In fact it is quite messy IMO. Also the dependance of trolltech and their moc preprocessor may be dangerous.
Best regards, The Chief
Prof. Abimbola A. Olowofoyeku (The African Chief) Author of: Chief's Installer Pro v5.22.1 for Win32 http://www.bigfoot.com/~African_Chief/chief32.htm Email: African_Chief@bigfoot.com