You have to initialize the Python interpreter when using it embedded in a C++ application.
On Tue, May 18, 2021 at 8:36 AM auderson <[email protected]> wrote: > Thanks for your reply! > > After I linked arrow_python_shared, calling import_pyarrow now caused a > SEGFAULT. > > I've posted my code on stackoverflow c++ - arrow::py::import_pyarrow() > cause a SEGMENTATION FAULT - Stack Overflow > <https://stackoverflow.com/questions/67584033/arrowpyimport-pyarrow-cause-a-segmentation-fault> > > I'm pretty new to C++, and maybe there are protocols I did't follow? > ------------------ Original ------------------ > *From:* "user" <[email protected]>; > *Date:* Tue, May 18, 2021 09:15 PM > *To:* "user"<[email protected]>; > *Subject:* Re: why I can't use `arrow::py::import_pyarrow()' in c++ > > You have to link libarrow_python (arrow_python_shared) where this symbol > is found. > > On Tue, May 18, 2021 at 3:09 AM auderson <[email protected]> wrote: > >> Hi, >> >> I'm using arrow-cpp 4.0.0 installed from conda. I also have pyarrow 4.0.0 >> installed. >> >> In my test.cpp file, import_pyarrow() will throw an error: undefined >> reference to `arrow::py::import_pyarrow()' >> >> #mini_example.cpp >> >> #include "mini_example.h" >> #include <arrow/python/pyarrow.h> >> >> int main() { >> arrow::py::import_pyarrow(); >> } >> >> #mini_example.h >> >> >> #include <arrow/python/pyarrow.h> >> >> int main() { >> arrow::py::import_pyarrow(); >> } >> >> >> #CMakeLists.txt >> >> cmake_minimum_required(VERSION 3.10.0) >> project(TEST) >> set(CMAKE_CXX_STANDARD 17) >> >> list(APPEND CMAKE_PREFIX_PATH "/home/auderson/miniconda3/lib/cmake/arrow") >> find_package(Arrow REQUIRED) >> >> >> include_directories(. >> /home/auderson/miniconda3/include >> /home/auderson/miniconda3/include/python3.8) >> >> add_executable(TEST >> mini_example.cpp >> ) >> >> target_link_libraries(${PROJECT_NAME} PRIVATE >> /home/auderson/miniconda3/lib/libpython3.8.so) >> target_link_libraries(${PROJECT_NAME} PRIVATE arrow_shared) >> >> The full output: >> >> CMakeFiles/TEST.dir/mini_example.cpp.o: In function `main': >> /tmp/tmp.vmULkzpuYF/mini_example.cpp:9: undefined reference to >> `arrow::py::import_pyarrow()' >> collect2: error: ld returned 1 exit status >> >> But other functionalities works fine, like create an Array then build a >> Table from them. In fact I'm just stuck at the last step where I have to >> wrap the table so that they can be passed to cython. >> >> Can you find where I'm doing wrong? Thanks! >> >> Auderson >> >> >>
