#๐Ÿ”’ Help needed with pybind11 and error undefined symbol for import of class that uses other classes

4 messages ยท Page 1 of 1 (latest)

royal junco
#

Hello everything worked for me when I had one class Client in client.hpp and exposed it using binding.cpp to python. But now I have the client use abstract class Board from board.cpp and it's concreat class from standard_board.cpp. The problem is that I get some funny error, which tells me almost nothing. During Cmake and make everything builds, but when I run python I get

$ python3 gui/main.py 
Traceback (most recent call last):
  File "/client/gui/main.py", line 10, in <module>
    import client_module
ImportError: /client/gui/client_module.cpython-312-x86_64-linux-gnu.so: undefined symbol: _ZN5Board4moveEiiii
cmake_minimum_required(VERSION 3.10)
project(Client CXX)

set(CMAKE_CXX_COMPILER g++)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(POLICY CMP0148)
    cmake_policy(SET CMP0148 NEW)
endif()

# For lsp support
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(pybind11 REQUIRED)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
set(PYBIND11_FINDPYTHON ON)
find_package(pybind11 REQUIRED)

set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic")
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")

include_directories(include)

pybind11_add_module(client_module src/binding.cpp src/client.cpp src/board.cpp src/standard_board.cpp)

And

//imports

namespace py = pybind11;

PYBIND11_MODULE(client_module, m) {
    py::class_<Client>(m, "Client")
        .def(py::init<const std::string&, int>())
        .def("connect", &Client::connect_to_server)
        .def("send_message", &Client::send_message)
        .def("disconnect", &Client::disconnect)
        .def("start_receiving", &Client::start_receiving)
        .def("board_state", &Client::board_state)
        .def("possible_moves", &Client::possible_moves)
        .def("set_message_callback", &Client::set_message_callback);
}
slow blazeBOT
#

@royal junco

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

slow blazeBOT
#

@royal junco

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.