sr99622 / libonvif

Onvif library with GUI implementation and built in YOLOX
GNU Lesser General Public License v2.1
149 stars 39 forks source link

Error on Ubuntu 20.04.6 LTS (Both installation and build from source) #90

Closed kanishkasw closed 2 months ago

kanishkasw commented 2 months ago

Hi, Im getting the following error when trying to run on Ubuntu 20 while following the instructions in the Readme

$ onvif-gui Traceback (most recent call last): File "/home/user/Personal/Tryout/libonvif/onvif-gui/myvenv/bin/onvif-gui", line 5, in from gui.main import run File "/home/user/Personal/Tryout/libonvif/onvif-gui/myvenv/lib/python3.10/site-packages/gui/init.py", line 1, in from .main import MainWindow File "/home/user/Personal/Tryout/libonvif/onvif-gui/myvenv/lib/python3.10/site-packages/gui/main.py", line 42, in from gui.panels import CameraPanel, FilePanel, SettingsPanel, VideoPanel, AudioPanel File "/home/user/Personal/Tryout/libonvif/onvif-gui/myvenv/lib/python3.10/site-packages/gui/panels/init.py", line 1, in from .camerapanel import CameraPanel File "/home/user/Personal/Tryout/libonvif/onvif-gui/myvenv/lib/python3.10/site-packages/gui/panels/camerapanel.py", line 26, in from gui.onvif import NetworkTab, ImageTab, VideoTab, PTZTab, SystemTab, LoginDialog, \ File "/home/user/Personal/Tryout/libonvif/onvif-gui/myvenv/lib/python3.10/site-packages/gui/onvif/init.py", line 7, in from .datastructures import Session, StreamState, MediaSource, Camera File "/home/user/Personal/Tryout/libonvif/onvif-gui/myvenv/lib/python3.10/site-packages/gui/onvif/datastructures.py", line 41, in class Session(onvif.Session): AttributeError: module 'libonvif' has no attribute 'Session'

sr99622 commented 2 months ago

Hello, thank you so much for reaching out. It would appear from the error message that libonvif has failed to compile. In most cases, this is due to a dependency problem, either not installed or some kind of version mismatch. The dependency in this case would be libxml2. You can verify installation using the command

apt list --installed | grep libxml2

You should get a response showing the version installed. If there is a good libxml2 installed, navigate to the libonvif root directory and use the command

assets/scripts/compile

There will be a long output that shows the internal messages generated by the compiler. Near the top should be a section showing the output of the libonvif compile. If there has been a failure, the error message will show specifics.

Please let me know what those messages are, and I can have a better idea of what to do to fix the install.

kanishkasw commented 2 months ago

Hi Thanks for the quick response @sr99622!. libxml2 version

$ apt list --installed | grep libxml2

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libxml2-dev/focal,now 2.9.14+dfsg-0.1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed] libxml2/focal,now 2.9.14+dfsg-0.1+ubuntu20.04.1+deb.sury.org+1 amd64 [installed,automatic]

I was able to fix some issues by looking at assets/scripts/compile output. Still unable to fix the following though

CMake Generate step failed. Build files cannot be regenerated correctly. Scanning dependencies of target avio [ 7%] Building CXX object CMakeFiles/avio.dir/src/avio.cpp.o In file included from /home/user/Personal/Tryout/libonvif/libavio/include/Player.h:29, from /home/user/Personal/Tryout/libonvif/libavio/include/avio.h:31, from /home/user/Personal/Tryout/libonvif/libavio/src/avio.cpp:23: /home/user/Personal/Tryout/libonvif/libavio/include/Display.h:25:10: fatal error: SDL.h: No such file or directory 25 | #include | ^~~ compilation terminated. make[2]: [CMakeFiles/avio.dir/build.make:83: CMakeFiles/avio.dir/src/avio.cpp.o] Error 1 make[1]: [CMakeFiles/Makefile2:116: CMakeFiles/avio.dir/all] Error 2 make: *** [Makefile:104: all] Error 2

sr99622 commented 2 months ago

Thank you for the feedback, your input is greatly appreciated.

I have installed ubuntu 20.04 and upgraded python to 3.10 using these instructions and upgraded cmake to version 3.20 using these instructions. Note that the cmake instructions are missing a step sudo apt install libssl-dev

I have been able to re-create the error you are seeing regarding SDL.h. It looks like the version installed by ubuntu 20.04 is not compatible with cmake 3.20, which is unfortunate. You can get the thing to compile with a little effort editing the libavio/CMakeLists.txt file to look like this. Basically, what you are doing is commenting out the find_package(SDL2) routine and hard-coding the file locations. You might want to try the command find /usr/lib -name SDL2 to verify the locations just to be sure they are correct.

#*******************************************************************************
# libavio/CMakeLists.txt
#
# Copyright (c) 2022, 2024 Stephen Rhodes 
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#******************************************************************************/

cmake_minimum_required(VERSION 3.17)

project(libavio VERSION 3.1.2)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")

# pass current dir in from host when building in virtual env
set (MY_CURRENT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
if (DEFINED ENV{CMAKE_CURRENT_SOURCE_DIR})
    set(MY_CURRENT_DIR $ENV{CMAKE_CURRENT_SOURCE_DIR})
endif()
file(TO_CMAKE_PATH "${MY_CURRENT_DIR}" MY_DIR_VAR)

list(PREPEND CMAKE_MODULE_PATH ${MY_DIR_VAR}/cmake)

if(WIN32)
    list(PREPEND CMAKE_MODULE_PATH ${MY_DIR_VAR}/cmake-win)
    add_compile_options("/EHsc")
    set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
    set(BUILD_SHARED_LIBS TRUE)
endif()

add_definitions(-w)

find_package(FFmpeg REQUIRED)
#find_package(SDL2 REQUIRED)

if (NOT WITHOUT_LIBS)
    add_library(libavio SHARED
        src/Clock.cpp
        src/Decoder.cpp
        src/Display.cpp
        src/Encoder.cpp
        src/Exception.cpp
        src/Filter.cpp
        src/Frame.cpp
        src/Packet.cpp
        src/Pipe.cpp
        src/Player.cpp
        src/Reader.cpp
        src/Writer.cpp
    )

    if (WIN32)
        target_link_libraries(libavio PUBLIC
            FFmpeg::FFmpeg
            SDL2::SDL2
        )
    else()
        target_link_libraries(libavio PUBLIC
            FFmpeg::FFmpeg
            /usr/lib/x86_64-linux-gnu/libSDL2.so
            pthread
        )
        set_target_properties(libavio PROPERTIES
            OUTPUT_NAME avio
            SOVERSION 1
        )
    endif()

    target_include_directories(libavio PUBLIC
        include
        ${FFMPEG_INCLUDE_DIRS}
        /usr/include/SDL2
    )
endif()

if (NOT WITHOUT_PYTHON)
    add_subdirectory(pybind11)

    pybind11_add_module(avio 
        src/avio.cpp
        src/Clock.cpp
        src/Decoder.cpp
        src/Display.cpp
        src/Encoder.cpp
        src/Exception.cpp
        src/Filter.cpp
        src/Frame.cpp
        src/Packet.cpp
        src/Pipe.cpp
        src/Player.cpp
        src/Reader.cpp
        src/Writer.cpp
    )

    target_link_libraries(avio PRIVATE 
        FFmpeg::FFmpeg
        /usr/lib/x86_64-linux-gnu/libSDL2.so
    )

    target_include_directories(avio SYSTEM PUBLIC
        include
        /usr/include/SDL2
    )
endif()

I think as a general rule, I wouldn't be able to support this Ubuntu version, so I don't think I would be making any changes to the repository other than to say that the minimum supported version for ubuntu is 22.04. Once again, thank you so much for the feedback and please let me know if you need any further help.

Best Regards,

Stephen

kanishkasw commented 2 months ago

Thanks @sr99622! it worked