You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@arrow.apache.org by auderson <au...@qq.com> on 2021/05/18 08:09:05 UTC

why I can't use `arrow::py::import_pyarrow()' in c++

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&gt;

int main() {
    arrow::py::import_pyarrow();
}

&nbsp;#mini_example.h


#include <arrow/python/pyarrow.h&gt;
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 statusBut 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

Re: why I can't use `arrow::py::import_pyarrow()' in c++

Posted by Wes McKinney <we...@gmail.com>.
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 <au...@qq.com> 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" <we...@gmail.com>;
> *Date:* Tue, May 18, 2021 09:15 PM
> *To:* "user"<us...@arrow.apache.org>;
> *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 <au...@qq.com> 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
>>
>>
>>

Re: why I can't use `arrow::py::import_pyarrow()' in c++

Posted by auderson <au...@qq.com>.
Thanks for your reply!


After I linked arrow_python_shared, calling import_pyarrow now caused a SEGFAULT.


I've posted my code on stackoverflow&nbsp;c++ - arrow::py::import_pyarrow() cause a SEGMENTATION FAULT - Stack Overflow


I'm pretty new to C++, and maybe there are protocols I did't follow?
------------------&nbsp;Original&nbsp;------------------
From:                                                                                                                        "user"                                                                                    <wesmckinn@gmail.com&gt;;
Date:&nbsp;Tue, May 18, 2021 09:15 PM
To:&nbsp;"user"<user@arrow.apache.org&gt;;

Subject:&nbsp;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.&nbsp;

On Tue, May 18, 2021 at 3:09 AM auderson <auderson@qq.com&gt; 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&gt;

int main() {
    arrow::py::import_pyarrow();
}

&nbsp;#mini_example.h


#include <arrow/python/pyarrow.h&gt;
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 statusBut 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

Re: why I can't use `arrow::py::import_pyarrow()' in c++

Posted by Wes McKinney <we...@gmail.com>.
You have to link libarrow_python (arrow_python_shared) where this symbol is
found.

On Tue, May 18, 2021 at 3:09 AM auderson <au...@qq.com> 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
>
>
>