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 4606482
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:34:16+00:00 2026-05-22T00:34:16+00:00

I have a main.cpp like so: #include <boost/python.hpp> const char* greeting() { return Hello

  • 0

I have a main.cpp like so:

#include <boost/python.hpp>

const char* greeting()
{
    return "Hello world?";
}

BOOST_PYTHON_MODULE(test)
{
    using namespace boost::python;

    def("greeting", greeting);
}

And a CMakeLists.txt file:

project(test)
cmake_minimum_required(VERSION 2.8)

# get boost
set(Boost_USE_STATIC_LIBS   ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS
                system
                thread
                python
             REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})

# get python
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
link_directories(${PYTHON_LIBRARIES})

add_library(test SHARED
        main.cpp
    )

I can run cmake and make just fine. It outputs a nice little libtest.so file for me. To test it out, I have a Python script like so:

import libtest

print(libtest.greeting())

Running this in the same directory as libtest.so gives the following error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import libtest
ImportError: /home/travis/projects/boost-python-test/build/libtest.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv

Yikes! The problem is pretty clear with make VERBOSE=1…the line creating my libtest.so looks like this:

/usr/bin/c++  -fPIC   -shared -Wl,-soname,libtest.so -o libtest.so CMakeFiles/test.dir/main.cpp.o -L/usr/lib/libpython2.7.so

I’m having a mental block as to why I do not see an -L/usr/lib/libboost_python-mt-py27.a on that line. It clearly worked for find_package(PythonLibs ...). I’m falling short due to some CMake newbishness.

  • 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-22T00:34:17+00:00Added an answer on May 22, 2026 at 12:34 am

    The solution to this is quite simple. One has to explicitly link the libraries with target_link_libraries after the add_library statement.

    target_link_libraries(test
            ${Boost_LIBRARIES}
            ${PYTHON_LIBRARIES}
        )
    

    I’m still not sure why it worked for Python without that. Magic?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple C++ with Boost like this: #include <boost/algorithm/string.hpp> int main() {
I have an application where I have a main.m that returns NSApplicationMain(argc, (const char
Is it possible to have a c++ program like this... #include <iostream> using namespace
Take the following simple source (name it test.cpp): #include <windows.h> void main() { DebugBreak();
I have an error that goes like this In file included from Level.hpp:12, from
Updated below . The following is the entire code I have in my main.cpp:
I have Data.cpp Data.h User.cpp User.h main.cpp Main.cpp need data.cpp and user.cpp. How do
i have a table called category in which i have main category ids and
I have a main asp.net app, which is written in asp.net 1.1. Runnning underneath
I have a main window (#1) on my webpage from which I open a

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.