Click here to Skip to main content
15,886,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an application that uses cppyy.
I have a header file containing a wrapper for sfml's RenderWindow so that the python instance can access those graphics.
The C++ header file graphics.hpp with the following contents
C++
#include <SFML/Graphics.hpp>
#include <iostream>

int WINDOW_WIDTH = 300;
int WINDOW_HEIGHT = 200;

using namespace sf;
using namespace std;


class WindowWrapper: protected RenderWindow {
	public:
		WindowWrapper(const char *title) {
			RenderWindow(VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), title);
		}
		WindowWrapper(string title) {
			RenderWindow(VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), title.c_str());
		}
		void eventLoop();
};
void WindowWrapper::eventLoop() {
	cout << "running event loop function" << endl;
}


it is a simple class WindowWrapper the inherits the sfml RenderWindow class.
I can include this in a C++ file.

here is my python script
Python
import cppyy

cppyy.include("graphics.hpp")

from cppyy.gbl import WindowWrapper
print(type(WindowWrapper))
window = WindowWrapper("Test Window")
window.eventLoop()


it runs until the point I try to create a WindowWrappre instance
It returns many very similar errors like
IncrementalExecutor::executeFunction: symbol '_ZN2sf12RenderWindow9setActiveEb' unresolved while linking symbol '__cf_4'!
You are probably missing the definition of sf::RenderWindow::setActive(bool)
Maybe you need to load the corresponding shared library?


I am guessing it somehow needs access to sfml's shared object libraries, but I don't know how to supply them

I am using arch Linux and python3.10

What I have tried:

I have tried searching with duckduckgo, but I don't think that many people have tried this, as there weren't many results. I have also tried researching cppyy missing shared object libraries, but nothing seemed to fit what I was trying to accomplish
Posted
Updated 30-Dec-21 13:11pm

1 solution

I have searched for a while and found that the sfml shared objects had to be loaded into the context of the python script

I made a new file "graphics.cpp" with one line in it which is
C++
#include <SFML/Graphics.hpp>

then compile it with this
Terminal
g++ -fPIC -shared graphics.cpp -lsfml-graphics -lsfml-window -lsfml-system -o graphics.so


the shared object will then automatically have all of the other shared object files that sfml needs

now you import this with cppyy along with you include for graphics.hpp
and the basic python file will look like this
Python
import cppyy

cppyy.include("src/graphics.hpp")
cppyy.load_library('bin/graphics.so')

window = cppyy.gbl.WindowWrapper("Text Window")
window.eventLoop()


it should now execute the event loop code without error
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900