is there a way to get c++ include directories path in python

asked 2020-06-17 15:29:03 -0500

azerila gravatar image

updated 2020-06-17 15:32:51 -0500

For a package in my workspace, I have to invoke setup.py manually instead of through catkin_python_setup(). Inside setup.py I need to specify the include directories which the c++ code of this package uses. Is there a way to get the path of these include directories in the same python script of setup.py?

a side question: In CMakeLists.txt, is it the include_directories() and target_link_libraries() that specify where the location of the header files are?

The reason I want to do this is that I am trying to wrap a c++ code of my package with Cython and it needs the include directories, otherwise when it reads the header file, it would raise no such file or directory.

edit retag flag offensive close merge delete

Comments

1

Hi @azerila

the include_directories() directive is used to specify additional locations of header files and the target_link_libraries() is used to specify libraries or flags to use when linking a given target and/or its dependents.

As for the other question, have you considered using the rospack class? To be more specific the get_path method that return the filysystem package path.

Weasfas gravatar image Weasfas  ( 2020-06-18 09:18:03 -0500 )edit

Hi @Weasfas , I imagine something like "rospack.get_path('pkg1')+'/include/'" might help, if we do it on the same packages that we have put in find_package(). although I'm not sure if it will find all header files needed similar to if we had used cmake include directories and catkin_python_setup()

azerila gravatar image azerila  ( 2020-06-18 09:55:19 -0500 )edit

The thing is why not doing the things catkin expects. This repo constains an example of using cython with catkin, hope than can help.

Weasfas gravatar image Weasfas  ( 2020-06-18 11:52:44 -0500 )edit

@Weasfas I had also tried that repo, but strangely when I build it in an isolated work space it is python3 compatible wheras when Build it in the original workspace of my application with the same cmake args it is not anymore...

azerila gravatar image azerila  ( 2020-06-19 03:23:57 -0500 )edit

Maybe because of this?

Weasfas gravatar image Weasfas  ( 2020-06-19 03:38:58 -0500 )edit

@Weasfas , so I have used catkin build so far and with the same cmake argument (DPYTHO_EXECUTABLE..) which works in my work space now but the moment I add name of another package from my workspace in find_package(), although it compiles I get this import error:ImportError: ....: undefined symbol: _Py_ZeroStruct. It's quite strange how this effects catkin_python_setup...

azerila gravatar image azerila  ( 2020-06-19 04:40:33 -0500 )edit

So because of all these, I wanted to see if I can directly do it without catkin_python_setup() while giving the include directories explicitly in setup.py

azerila gravatar image azerila  ( 2020-06-19 05:48:59 -0500 )edit

Well, at this point I do not know what could be possible happening, maybe you missed a setup.py in your other packages. As far as I know, you do not need to say explicitly in the find_package directive since you are adding that in the setup.py. Maybe someone that is more into this kind of things can help you more.

Weasfas gravatar image Weasfas  ( 2020-06-19 06:25:48 -0500 )edit