CMake issues using Python.h inside dissector

asked 2023-05-04 13:31:01 +0000

artectrex gravatar image

updated 2023-05-04 13:32:05 +0000

Hi,

I want to call a function from a Python library inside a dissector (I know, not great but I'm just trying something out). To do this I'm using the Python/C api.

After adding the #include in the dissector I wanted to modify, Python.h was not found. This I solved by adding to the epan/dissectors/CMakeLists.txt file (around line 2194):

 target_include_directories(dissectors
        SYSTEM PRIVATE
+               ${Python3_INCLUDE_DIRS}

Now I get linker errors, so I tried adding a

+target_link_libraries(dissectors ${Python3_LIBRARIES})

right after the target_include_directories (still in epan/dissectors/CMakeLists.txt).

That still didn't work, and I don't know how to get the linker to link the Python libraries correctly? I'm not very experienced with CMake and even less with Wireshark development.

This is the linker error I get:

...
[ 90%] Linking CXX executable run/wireshark
ld: run/libwireshark.so.0.0.0: undefined reference to `PyRun_SimpleStringFlags'
ld: run/libwireshark.so.0.0.0: undefined reference to `Py_FinalizeEx'
ld: run/libwireshark.so.0.0.0: undefined reference to `Py_Initialize'
edit retag flag offensive close merge delete

Comments

Linking CXX executable run/wireshark

If it's linking wireshark should the library be added to wireshark_LIBS in the top level CMakeLists.txt?

Chuckc gravatar imageChuckc ( 2023-05-04 15:53:22 +0000 )edit

I tried that too, it didn't work :(

artectrex gravatar imageartectrex ( 2023-05-04 15:55:40 +0000 )edit