Thread: Issues embedding Guile in C++

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    1

    Issues embedding Guile in C++

    I'm a Scheme programmer, and I'm attempting to use Guile to call Scheme functions from C++ code within a Bison specification. The documentation concerning Guile and C is great; however, I haven't found much relevant, up-to-date information about Guile and C++. Because every C program is technically a C++ program, calling Scheme functions from C++ via Guile should be easy enough. Alas, I'm not a C/C++ programmer, so I was hoping some of the C++ gurus on here could help me out. Here is some of my code:

    Code:
    %{
    #include <fstream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    #include "List.h"
    
    #include "paslex.h"
    #include "paspar.h"
    
     extern "C" {
    #include <libguile.h>
    #include "symtable.h"
     }
    
    void yyerror(char* m);
    
    extern ofstream tfs;
    extern int line;
    extern int col;
    
     extern "C" {
    // Create namespace stack and lexical level 0 with built-in types.
       SCM namespace_stack;
       SCM namespace0;
       SCM real_type;
       SCM real_type_sym;
       SCM integer_type;
       SCM integer_type_sym;
    
       // errors begin here
       namespace_stack = make_name_stack();
       namespace0 = make_namespace();
       real_type = make_type_attr(64, 64);
       real_type_sym = make_type_sym("real", real_type);
       integer_type = make_type_attr(32, 32);
       integer_type_sym = make_type_sym("integer", integer_type);
    
       insert_symbol(real_type_sym, namespace0);
       insert_symbol(integer_type_sym, namespace0);
       push(namespace0, namespace_stack);
     }
    
    %}
    My wrapper functions for the Scheme code are in symtable.c. Using these same functions from pure C works just fine. Calling them from C++ generates the following compiler error:

    paspar.y:33: error: expected constructor, destructor, or type conversion before ‘=’ token
    ...and a similar error for lines 34 through 42. I'm using GCC 4.4.5 and Guile 1.6.8 on Ubuntu 10.10. I'm sure this is a newbie mistake, but help with this problem would be greatly appreciated. Let me know if more information is needed.

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    You probably cannot call functions in the global level, though I believe you can call them as an initializer. So try
    Code:
    extern "C" {
    // Create namespace stack and lexical level 0 with built-in types.
       SCM namespace_stack = make_name_stack();;
       SCM namespace0 = make_namespace();;
       SCM real_type = make_type_attr(64, 64);;
       SCM real_type_sym = make_type_sym("real", real_type);;
       SCM integer_type = make_type_attr(32, 32);;
       SCM integer_type_sym = make_type_sym("integer", integer_type);;
    
       insert_symbol(real_type_sym, namespace0);
       insert_symbol(integer_type_sym, namespace0);
       push(namespace0, namespace_stack);
     }
    If not, try initializing them from main()

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Dude, it isn't cool to spam your problem around the internet.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging issues
    By melodia in forum C Programming
    Replies: 1
    Last Post: 11-21-2010, 07:56 AM
  2. I hate pointers or Pointer Issues
    By bolivartech in forum C Programming
    Replies: 9
    Last Post: 11-14-2009, 11:48 AM
  3. Solution to culling issues?
    By VirtualAce in forum Game Programming
    Replies: 4
    Last Post: 03-14-2006, 06:59 PM
  4. gphoto2 issues
    By axon in forum Tech Board
    Replies: 3
    Last Post: 03-21-2004, 08:33 PM
  5. hexdump issues
    By daluu in forum C Programming
    Replies: 2
    Last Post: 03-04-2003, 09:01 PM

Tags for this Thread