I am working at a project that is supposed to run a python script.

Here is my main class:

#include <iostream>
#include "scripting.hpp"


int main(void) {
    cScripter oScripter;

    std::vector <double> vectMy (7, 32);
    oScripter.doRunScript (&vectMy, "test.py", "function");

    return 0;
}

And here are respectively scripter.hpp and scripter.cpp :

#ifndef SCRIPTING_HPP_INCLUDED
#define SCRIPTING_HPP_INCLUDED

#include <boost/python.hpp>
#include <rapidxml-1.13/rapidxml_utils.hpp>
#include <vector>
#include <string>

std::vector <double> *vectPointer; 

int size (void);
void resize (const int& newSize);
void push_back (const double& dbValue);
void pop_back (void);
double& at (const int& intPosition);



class cScripter {
    public:
        cScripter (void);
        void doRunScript (std::vector <double>*,
                          const std::string&,
                          const std::string&);
};

#endif // SCRIPTING_HPP_INCLUDED
#include "scripting.hpp"

int size (void) {
    return vectPointer->size ();
}

void resize (const int& newSize) {
    vectPointer->resize (newSize);
}

void push_back (const double& dbValue) {
    vectPointer->push_back (dbValue);
}

void pop_back (void) {
    vectPointer->pop_back ();
}

double& at (const int& intPosition) {
    return vectPointer->at (intPosition);
}

BOOST_PYTHON_MODULE_INIT (sc) {
    using namespace boost::python;
    def ("size", size);
    def ("resize", resize);
    def ("push_back", push_back);
    def ("at", at, return_value_policy<copy_non_const_reference>() );
}


cScripter::cScripter (void) {}

void cScripter::doRunScript (std::vector <double>* vectPoint,
                             const std::string& strFileName,
                             const std::string& strEntryPoint) {
    vectPointer = vectPoint;
    PyImport_AppendInittab ("sc", init_module_sc);
    Py_Initialize ();

    PyRun_SimpleString ((rapidxml::file <char> (strFileName.c_str ())).data ());
    PyRun_SimpleString ((strEntryPoint + "()").c_str ());

    Py_Finalize ();
}

The problem is I get these two errors:
scripting.cpp line 3 - multiple definition of vectPointer
main.cpp line 18 - first defined here

The compiling command is
g++ -g -pg -W -Wall -pendantic -Wmain -O2 -Wctor-dtor-privacy -Weffc++

Edited 6 Years Ago by n.utiu: n/a

why is your definition of vectPointer in your header file?

yes, dumb me

This question has already been answered. Start a new discussion instead.