My hardware and software configuration is as follows:
- macOS Ventura version 13.4.1
- M2 Max chip
- python version 3.11.4 (Versions managed by pyenv)
- boost 1.82.0_1 (installed with Brew)
- boost-python 1.82.0 (installed with Brew)
I am trying to extend my C++ code into a python codebase so that I can use my C++ code as modules in python. I am trying to compile a shared .so file so that I can use my python bindings. When I try to compile using this command
g++ -shared -o BinaryWrap.so -I./DES_2/include -I/opt/homebrew/Cellar/boost/1.82.0_1/include -I/usr/local/include -I/Users/username/.pyenv/versions/3.11.4/include/python3.11 -L/usr/local/lib -L/opt/homebrew/Cellar/boost/1.82.0_1/lib -L/opt/homebrew/Cellar/boost-python3/1.82.0/lib -L/Users/username/.pyenv/versions/3.11.4/lib -lboost_python311 -lpython3.11 ./DES_2/src/BinaryWrap.cpp
I know the command is a lot but I will be constructing this into a Cmake file once I solve the problem. The output I get from this command is below.
In file included from ./DES_2/src/BinaryWrap.cpp:1:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python.hpp:11:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python/args.hpp:10:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python/args_fwd.hpp:10:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python/handle.hpp:11:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python/errors.hpp:13:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/function/function0.hpp:11:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/function/detail/maybe_include.hpp:15:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/function/function_template.hpp:13:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/function/detail/prologue.hpp:12:
/opt/homebrew/Cellar/boost/1.82.0_1/include/boost/function/detail/requires_cxx11.hpp:18:1: warning: C++03 support is deprecated in Boost.Function 1.82 and will be removed in Boost.Function 1.84. [-W#pragma-messages]
BOOST_PRAGMA_MESSAGE("C++03 support is deprecated in Boost.Function 1.82 and will be removed in Boost.Function 1.84.")
^
/opt/homebrew/Cellar/boost/1.82.0_1/include/boost/config/pragma_message.hpp:24:34: note: expanded from macro 'BOOST_PRAGMA_MESSAGE'
# define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x)))
^
<scratch space>:103:2: note: expanded from here
message("C++03 support is deprecated in Boost.Function 1.82 and will be removed in Boost.Function 1.84.")
^
In file included from ./DES_2/src/BinaryWrap.cpp:1:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python.hpp:11:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python/args.hpp:10:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python/args_fwd.hpp:10:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python/handle.hpp:11:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python/errors.hpp:13:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/function/function0.hpp:11:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/function/detail/maybe_include.hpp:15:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/function/function_template.hpp:13:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/function/detail/prologue.hpp:19:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/mem_fn.hpp:22:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/bind/mem_fn.hpp:24:
/opt/homebrew/Cellar/boost/1.82.0_1/include/boost/bind/detail/requires_cxx11.hpp:18:1: warning: C++03 support is deprecated in Boost.Bind 1.82 and will be removed in Boost.Bind 1.84. [-W#pragma-messages]
BOOST_PRAGMA_MESSAGE("C++03 support is deprecated in Boost.Bind 1.82 and will be removed in Boost.Bind 1.84.")
^
/opt/homebrew/Cellar/boost/1.82.0_1/include/boost/config/pragma_message.hpp:24:34: note: expanded from macro 'BOOST_PRAGMA_MESSAGE'
# define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x)))
^
<scratch space>:70:2: note: expanded from here
message("C++03 support is deprecated in Boost.Bind 1.82 and will be removed in Boost.Bind 1.84.")
^
In file included from ./DES_2/src/BinaryWrap.cpp:1:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python.hpp:11:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python/args.hpp:22:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python/object_core.hpp:14:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python/call.hpp:15:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python/converter/arg_to_python.hpp:15:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/python/converter/shared_ptr_to_python.hpp:12:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/shared_ptr.hpp:17:
In file included from /opt/homebrew/Cellar/boost/1.82.0_1/include/boost/smart_ptr/shared_ptr.hpp:17:
/opt/homebrew/Cellar/boost/1.82.0_1/include/boost/smart_ptr/detail/requires_cxx11.hpp:19:1: warning: C++03 support is deprecated in Boost.SmartPtr 1.82 and will be removed in Boost.SmartPtr 1.84. [-W#pragma-messages]
BOOST_PRAGMA_MESSAGE("C++03 support is deprecated in Boost.SmartPtr 1.82 and will be removed in Boost.SmartPtr 1.84.")
^
/opt/homebrew/Cellar/boost/1.82.0_1/include/boost/config/pragma_message.hpp:24:34: note: expanded from macro 'BOOST_PRAGMA_MESSAGE'
# define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x)))
^
<scratch space>:388:2: note: expanded from here
message("C++03 support is deprecated in Boost.SmartPtr 1.82 and will be removed in Boost.SmartPtr 1.84.")
^
3 warnings generated.
ld: warning: dylib (/Users/username/.pyenv/versions/3.11.4/lib/libpython3.11.dylib) was built for newer macOS version (13.4) than being linked (13.0)
Undefined symbols for architecture arm64:
"Binary::Dec_to_Bin(int)", referenced from:
init_module_Binary() in BinaryWrap-4292b8.o
"Binary::bit_to_dec(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>)", referenced from:
init_module_Binary() in BinaryWrap-4292b8.o
"Binary::xOr(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>)", referenced from:
init_module_Binary() in BinaryWrap-4292b8.o
"Binary::bin2hex(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>)", referenced from:
init_module_Binary() in BinaryWrap-4292b8.o
"Binary::hex2bin(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>)", referenced from:
init_module_Binary() in BinaryWrap-4292b8.o
"Binary::hex2char(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>)", referenced from:
init_module_Binary() in BinaryWrap-4292b8.o
"Binary::shiftbits(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, int, char)", referenced from:
init_module_Binary() in BinaryWrap-4292b8.o
"Binary::txttoBits(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>)", referenced from:
init_module_Binary() in BinaryWrap-4292b8.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have checked my code to check for any errors in implmentation; however, there was none. I have triple checked my include and lib paths and I have asked chat gpt with little awnser.
here is my wrapper .cpp file
#include <boost/python.hpp>
#include "Binary.hpp"
#include <string>
BOOST_PYTHON_MODULE(Binary){
boost::python::class_<Binary>("Binary", boost::python::init<>())
.def("bit_to_dec", &Binary::bit_to_dec)
.def("shiftbits", &Binary::shiftbits)
.def("xOr", &Binary::xOr)
.def("hex2bin", &Binary::hex2bin)
.def("bin2hex", &Binary::bin2hex)
.def("hex2dec", &Binary::hex2bin)
.def("Dec_to_bin", &Binary::Dec_to_Bin)
.def("txttoBits", &Binary::txttoBits)
.def("hex2char", &Binary::hex2char);
}
here is my header file
#include <iostream>
#include <string>
#ifndef _Binary_
#define _Binary_
class Binary{
public:
static std::string shiftbits(std::string bits, int n /* number of shifts*/, char dir);
static std::string xOr(std::string s1, std::string s2); // does XOR of two std::strings
static int bit_to_dec(std::string num); // converts bits into decimal numbers
static std::string hex2bin(std::string s); // hexadecimal to bin
static std::string bin2hex(std::string s); // binary to hexadecimal
static std::string Dec_to_Bin(int n); // decimal to binary
static std::string txttoBits(std::string str); // text char's to binary
static std::string hex2char(std::string hex); // hexadecimal to strings of characters
static std::string hex2dec(std::string s); // Hexadecimal to decimal number
};
#endif
here and here are the tutorials I am following.
Thank you very much in advance!