Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6915349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:27:51+00:00 2026-05-27T09:27:51+00:00

I have written a c++ library, and I’m trying to make python bindings to

  • 0

I have written a c++ library, and I’m trying to make python bindings to it with boost::python. This is simplified version of file, where I define them:

#include <boost/python.hpp>
#include <matrix.h>
#include <string>

using namespace boost::python;

class MatrixForPython : public Matrix{
  public:
    MatrixForPython(int size) : Matrix(size) {}

    std::string hello(){
      return "this method works"; 
    }
};

BOOST_PYTHON_MODULE(matrix){
  class_<MatrixForPython>("Matrix", init<int>())
    .def("hello", &MatrixForPython::hello); 
}

Compilation is done by CMake, and here is my CMakeLists.txt:

project(SomeProject)
cmake_minimum_required(VERSION 2.8)

# find and include boost library
find_package(Boost COMPONENTS python REQUIRED)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_PATH})
include_directories(${Boost_INCLUDE_DIR})
include_directories(.)

# compile matrix manipulation library
add_library(matrix SHARED matrix.cpp python_bindings.cpp)
set_target_properties(matrix PROPERTIES PREFIX "")
target_link_libraries(matrix
  ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})

Compilation finishes without errors, but when I try to run simple python script:

import matrix

I get following error

undefined symbol: _ZN6MatrixC2ERKS_

What puzzles me the most is fact, that when I change MatrixForPython not to derive from Matrix everything works as expected. What should I change in order to make it work?

EDIT: matrix.h:

#ifndef MATRIX_H_
#define MATRIX_H_

#include <boost/shared_array.hpp>


class Matrix{
  public:
    // creates size X size matrix
    Matrix(int size);

    // copy constructor
    Matrix(const Matrix& other);

    // standard arithmetic operators
    const Matrix operator * (const Matrix& other) const;
    const Matrix operator + (const Matrix& other) const;
    const Matrix operator - (const Matrix& other) const;

    // element manipulation
    inline void set(int row, int column, double value){
      m_data[row*m_size + column] = value;
    }

    inline double get(int row, int col) const{
      return m_data[row*m_size + col];
    }

    // norms
    double frobeniusNorm() const;
    double scaledFrobeniusNorm() const;
    double firstNorm() const;
    double infNorm() const;

    // entire array manipulation
    void zero();    // sets all elements to be 0
    void one();     // identity matrix
    void hermite(); // hermite matrix


    virtual ~Matrix();


    // less typing
    typedef boost::shared_array<double> MatrixData;

  private:
    int m_size; 
    MatrixData m_data;
};




#endif
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:27:51+00:00Added an answer on May 27, 2026 at 9:27 am

    undefined symbol: _ZN6MatrixC2ERKS_

    This is because you are missing the Matrix::Matrix(const Matrix&) copy constructor in your shared library:

    samm@mac ~> echo _ZN6MatrixC2ERKS_ | c++filt 
    Matrix::Matrix(Matrix const&)
    samm@mac ~> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a simple GUI in Python using the Tkinter library. This GUI
I have written a Flex Library project - a .swc file - which is
I have a dynamic linked library written in C# 3.0. This library has a
i have written a library with some classes that make use of qt object
Have written all the code in a silverlight class library (dll) and linked this
In the past, I have written a script using the Python IMAP library to
if i have written a library in C++, and have bindings for C, Ada,
I have written a Python extension library in C and I am currently using
I have written a Python extension for a C library. I have a data
I have a library written in C that I would like to use in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.