Le Lundi, 17 Mars 2003, à 02:32 Australia/Melbourne, Jean Richelle a écrit :

Hi all,

I'm trying to compile kdevelop but it fails ( cf end of compilation msgs).
Any idea of what to do to solve that ?

Regards,

Jean

scriptingpart.cpp:131: syntax error before `<<' token
scriptingpart.cpp:133: `guiDocument' was not declared in this scope
scriptingpart.cpp:133: warning: ISO C++ forbids declaration of `setDOMDocument'
with no type
scriptingpart.cpp:135: `Py_None' was not declared in this scope
scriptingpart.cpp:135: warning: ISO C++ forbids declaration of `Py_INCREF' with
no type
scriptingpart.cpp:136: parse error before `return'
scriptingpart.cpp:141: syntax error before `*' token
scriptingpart.cpp: In member function `void ScriptingPart::slotScriptAction()':
scriptingpart.cpp:153: `kdDebug' cannot be used as a function
scriptingpart.cpp:155: `PyObject' undeclared (first use this function)
scriptingpart.cpp:155: `arglist' undeclared (first use this function)
scriptingpart.cpp:155: `Py_BuildValue' undeclared (first use this function)
scriptingpart.cpp:156: `actions' undeclared (first use this function)
scriptingpart.cpp:156: `PyEval_CallObject' undeclared (first use this function)
scriptingpart.cpp: At global scope:
scriptingpart.cpp:162: syntax error before `*' token
scriptingpart.cpp:166: syntax error before `*' token
scriptingpart.cpp:172: `kdevelopc_appId' was not declared in this scope
scriptingpart.cpp:172: `METH_VARARGS' was not declared in this scope
scriptingpart.cpp:173: `kdevelopc_addMenuItem' was not declared in this scope
scriptingpart.cpp:173: `METH_VARARGS' was not declared in this scope
scriptingpart.cpp:175: array size missing in `kdevelopc_methods'
scriptingpart.cpp:175: storage size of `kdevelopc_methods' isn't known
scriptingpart.cpp:171: storage size of `kdevelopc_methods' isn't known
scriptingpart.cpp: In function `void initkdevelopc()':
scriptingpart.cpp:179: `Py_InitModule' undeclared (first use this function)
scriptingpart.cpp: At global scope:
scriptingpart.cpp:181: parse error before `}' token
make[3]: *** [scriptingpart.lo] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
### execution of /var/tmp/tmp.0.e4OCVQ failed, exit code 2
Failed: compiling kdevelop-3.0a3-2 failed

/***************************************************************************
 *   Copyright (C) 2001 by Bernd Gehrmann                                  *
 *   [EMAIL PROTECTED]                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "scriptingpart.h"
#include <Python.h>
#include <stdlib.h>
#include <dcopclient.h>
#include <dcopobject.h>
#include <kaction.h>
#include <kdebug.h>
#include <kgenericfactory.h>
#include <kstandarddirs.h>

#include "kdevcore.h"


static ScriptingPart *scripting_part;
extern "C" {
    void initkdevelopc();
    void initpydcopc();
    int __kde_do_not_unload;
}

typedef KGenericFactory<ScriptingPart> ScriptingFactory;
K_EXPORT_COMPONENT_FACTORY( libkdevscripting, ScriptingFactory( "kdevscripting" ) );

ScriptingPart::ScriptingPart(QObject *parent, const char *name, const QStringList &)
    : KDevPlugin(parent, name ? name : "ScriptingPart")
{
    setInstance(ScriptingFactory::instance());
    
    QString xml = QString::fromLatin1("<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n"
                                      "<kpartgui version=\"1\" name=\"editorpart\">\n"
                                      "<MenuBar>\n"
                                      "</MenuBar>\n"
                                      "</kpartgui>");
    guiDocument.setContent(xml);
    setDOMDocument(guiDocument);

    scripting_part = this;

    QString moddir = KGlobal::dirs()->findResourceDir("data", 
"kdevscripting/kdevelop.py") + "kdevscripting";
    char *env = strdup(QString::fromLatin1("PYTHONPATH=%1").arg(moddir).latin1());
    putenv(env);
    Py_Initialize();
    free(env);
    
    kdDebug(9011) << "Init kdevelopc" << endl;
    initkdevelopc();
    
    kdDebug(9011) << "Init pydcopc" << endl;
    initpydcopc();

    kdDebug(9011) << "import kdevelop" << endl;
    PyRun_SimpleString((char*)"import kdevelop");

    kdDebug(9011) << "from init import *" << endl;
    PyRun_SimpleString((char*)"from init import *");

#if 0
    QString initfile = locate("data", "kdevpython/init.py");
    FILE *f1 = fopen(initfile.latin1(), "r");
    kdDebug(9011) << "evaluate init.py" << endl;
    PyRun_SimpleFile(f1, (char*)initfile.latin1());
    fclose(f1);
#endif
}


extern DCOPObject *pydcopc_dispatcher;


ScriptingPart::~ScriptingPart()
{
    delete pydcopc_dispatcher;
    pydcopc_dispatcher = 0;
}


PyObject *ScriptingPart::addMenuItem(PyObject *args)
{
    char *menu, *submenu;
    PyObject *func;
    
    if (!PyArg_ParseTuple(args, (char*)"ssO", &menu, &submenu, &func))
        return 0;

    if (!PyCallable_Check(func)) {
        kdDebug(9011) << "Scripting function not callable" << endl;
        return 0;
    }
    
    QString menustr = QString::fromLatin1(menu);
    QString submenustr = QString::fromLatin1(submenu);
    QString ident = menustr + submenustr;

    Py_XINCREF(func);
    
    actions.insert(ident, func);
    
    (void) new KAction(submenustr, 0, this, SLOT(slotScriptAction()),
                       actionCollection(), ident.latin1());
    
    QDomElement el = guiDocument.documentElement();
    el = el.namedItem("MenuBar").toElement();
    QDomElement child = el.firstChild().toElement();
    while (!child.isNull()) {
        if (child.tagName() == "Menu" && child.attribute("name") == menustr)
            break;
        child = child.nextSibling().toElement();
    }
    if (child.isNull()) {
        child = guiDocument.createElement(QString::fromLatin1("Menu"));
        child.setAttribute(QString::fromLatin1("name"), menustr);
        el.appendChild(child);
    }
    el = child;
    
    child = guiDocument.createElement(QString::fromLatin1("Action"));
    child.setAttribute(QString::fromLatin1("name"), ident);
    el.appendChild(child);

    kdDebug(9011) << "New dom document: " << guiDocument.toString() << endl;
    
    setDOMDocument(guiDocument);

    Py_INCREF(Py_None);
    return Py_None;
}



PyObject *ScriptingPart::appId(PyObject *args)
{
    if (!PyArg_ParseTuple(args, (char*)""))
        return NULL;

    return Py_BuildValue((char*)"s", DCOPClient::mainClient()->appId().data());
}


void ScriptingPart::slotScriptAction()
{
    QString ident = QString::fromLatin1(sender()->name());
    kdDebug(9011) << "Action " << ident << " activated" << endl;

    PyObject *arglist = Py_BuildValue((char*)"()");
    PyEval_CallObject(actions[ident], arglist);
}


extern "C" {

    static PyObject *kdevelopc_addMenuItem(PyObject */*self*/, PyObject *args)
    {
        return scripting_part->addMenuItem(args);
    }
    static PyObject *kdevelopc_appId(PyObject */*self*/, PyObject *args)
    {
        return scripting_part->appId(args);
    }

    static struct PyMethodDef kdevelopc_methods[] = {
        { (char*)"appId",       kdevelopc_appId,       METH_VARARGS, NULL },
        { (char*)"addMenuItem", kdevelopc_addMenuItem, METH_VARARGS, NULL },
        { NULL,                 NULL,                0,            NULL }
    };

    void initkdevelopc()
    {
        (void) Py_InitModule((char*)"kdevelopc", kdevelopc_methods);
    }
}

#include "scriptingpart.moc"


/***************************************************************************
 *   Copyright (C) 2001 by Bernd Gehrmann                                  *
 *   [EMAIL PROTECTED]                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef _SCRIPTINGPART_H_
#define _SCRIPTINGPART_H_

#include <Python.h>
#include <qdom.h>
#include <qguardedptr.h>
#include "kdevplugin.h"


class ScriptingPart : public KDevPlugin
{
    Q_OBJECT

public:
    ScriptingPart( QObject *parent, const char *name, const QStringList & );
    ~ScriptingPart();

    PyObject *addMenuItem(PyObject *args);
    PyObject *appId(PyObject *args);

private slots:
    void slotScriptAction();

private:
    QDomDocument guiDocument;
    QMap<QString, PyObject*> actions;
};

#endif


These files are syntactically correct, and the first ten errors at least, I didn't see the point in checking more than ten, are erroneous, all variables <<are>> within scope, all functions <<are>> declared, the supposedly invalid declarations are <<not>> actually declarations etc. Thus if the error does not lie in the source file then, we must start to look elsewhere. For example, are the environment variables for KDEDIR, QTDIR and QMAKESPEC correctly set for the shell in which you are compiling kdevelop? The variables should have the following values:

KDEDIR {prefix}
QTDIR {prefix}
QMAKESPEC {prefix}/share/qt/mkspecs/darwin-g++

Where {prefix} is the root of your fink installation, which by default is /sw. Though I am not hopeful that the solution is as simple as this, as this would most likely generate more, and more pointed errors, it is certainly worth checking.

The fact that the errors you list above start at line 131 is the most confusing aspect to this. That line reads :

kdDebug(9011) << "New dom document: " << guiDocument.toString() << endl;

There are six previous invocations of the function kdDebug( int ), defined in kdebug.h, all with the same argument, none of which give rise to an error. kdDebug( int ) returns a kdbgstream object for which stream insertion ( << ) is a defined operation, i.e. it should not be an error. The lines immediately preceding it are likewise straight forward, and syntactically correct, without invocation of macros or templates or any other code generation mechanism, which might hide the error. So the question of why the errors start here, is probably significant, but also beyond me.

I have reposted this to the list in the hopes that someone of more knowledge than I, might see something that I have missed, or at least be able to suggest a new angle of attack. At present all that I can recommend is to check that you're using the latest version. If you are not, then update and recompile. If this is the latest version, your shell environment is correctly set and no dependencies have been removed outside of fink, then all we can do is hope that the maintainer, or someone of equal knowledge, can work out why seemingly correct code, in a correct environment will not compile.

Good luck,

Daniel.

P.S. Sorry that I couldn't offer anything more than confirming what was already known.

Reply via email to