0

I'm trying to compile a basic example copied and pasted directly from pybind11, with g++-8 on a Mac.

This is the c++ code (example.cpp):

#include <pybind11/pybind11.h>

int add(int i, int j) {
    return i + j;
}

PYBIND11_MODULE(example, m) {
    m.doc() = "pybind11 example plugin"; // optional module docstring

    m.def("add", &add, "A function which adds two numbers");
}

When I use the following command, it works:

/usr/local/bin/g++-8 -O3 -Wall -shared -std=c++11 -fPIC -Wl,-undefined,dynamic_lookup `python3 -m pybind11 --includes` example.cpp -o example`python3-config --extension-suffix`

However, when I add in -mcmodel=large, such as the following

/usr/local/bin/g++-8 -Wall -shared -std=c++11 -mcmodel=large -fPIC -Wl,-undefined,dynamic_lookup `python3 -m pybind11 --includes` example.cpp -o example`python3-config --extension-suffix`

It would give me a bunch of errors that look like:

/var/folders/zk/zxm107qd503bgh5qxvdhv6cr0000gv/T//ccbv0Hje.s:75886:19: error: invalid variant 'PLTOFF' movabsq $__ZdlPv@PLTOFF, %rax

I have Googled this error but I couldn't find a helpful thread. Also, I want to use g++ (not Xcode) since it's lightweight and popular in my community. I've tried different versions of g++ (6, 7, and 8) but I see the same error.

I need to use mcmodel=large because the actual code that I deal with could require large memory allocations.

Any help would be appreciated.

tryingtosolve
  • 763
  • 5
  • 20

0 Answers0