Perl/Tk GUI for C++ Application
Asked Answered
R

5

5

I have to do a college project using C++ that requires a GUI. I want to use Perl/Tk for the GUI, but I am not sure how to link the C++ to the Perl. The project requires being able to pass variables back and forth. Could anyone point me in the direction of some good tutorials/books for linking the two, or any ideas on how I should approach the problem as I have never had to link two languages before.

Recriminate answered 17/10, 2008 at 11:44 Comment(0)
S
6

I'm working on a library to make that as simple as possible, but it's still an alpha version.

Sallust answered 17/10, 2008 at 11:52 Comment(0)
I
6

You can also try swig. It's a tool for generating interfaces to several scripting languages from C/C++.

Indigestible answered 17/10, 2008 at 12:12 Comment(0)
S
5

Since Perl is going to be providing the GUI, I'd embed the C++ code into Perl. Assuming that there's going to be a significant amount of C++ code, I'd put that into a library. The traditional way of linking that library to Perl is to create a Perl module using XS. The Tutorial for writing XSUBs and XS language reference manual will help with that.

A somewhat easier way may be to use the Inline module. I've used Inline::C before, and it worked well, but I've never tried Inline::CPP (the C++ version). I see it has mixed reviews.

Stylistic answered 17/10, 2008 at 15:30 Comment(1)
Following-up years later. Inline::CPP hadn't been maintained since 2003. In 2011 I started working on it as a co-maintainer, and committed about 135 patches between Nov-2011 and May-2012. It's in much better shape now. The RT bug list is down to one lingering wishlist item. And the CPAN Testers install success ratio is up to the mid-90% range.Rounder
S
1

If I was tackling this problem I'd be using TCL/TK to create a GUI and then building a TCL extension in C/C++ that can be called from TCL/TK. This is one of the things that TCL/TK is really good at (other dynamic languages can do this as well but I like TCL/TK). You create a shared libray (.so on Unix or .dll on windows) with the C++ bits and they get imported as commands into TCL when you load the library.

Swig, which has already been mentioned, is a tool that helps automate the wrapping process, it can take your C++ code and create a wrapper that allows it to be loaded into a number languages such as TCL, Perl, Python, Ruby ...

Start at http://www.tcl.tk/ for lots of informtion an TCL and TK.

Shellfish answered 17/10, 2008 at 19:3 Comment(0)
S
0

if its a small project, its probably not worth the investment to spend lots of time getting the two languages to talk. you might consider using a more appropriate tool. C# will talk to C++ with a lot less pain.

Seton answered 17/10, 2008 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.