libuvc icon indicating copy to clipboard operation
libuvc copied to clipboard

Sample code not giving any output neither any error

Open lafith opened this issue 3 years ago • 4 comments
trafficstars

Hi, I built libuvc in windows without any error following your instructions. I wrote few lines just to check if it is working. It is running without any error but it is also not printing out anything.

Screenshot (33)

main.cpp

#include <iostream>
#include <libuvc/libuvc.h>

int main(){
  std::cout<<"UVC Test:"<<std::endl;
  uvc_context_t *ctx = nullptr;
  uvc_error_t res = uvc_init(&ctx, nullptr);
  if (res < 0)
    {
        uvc_perror(res, "uvc_init error");
        std::cout<<"error"<<std::endl;
    }
    uvc_exit(ctx);
    std::cout<<"Done!"<<std::endl;
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.0.0)
project(WebCam_MicrosoftMediaFoundation VERSION 0.1.0)

include_directories(include)
file(GLOB SOURCES "src/*.cpp")

find_package(OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )

set(libuvc_DIR C:/libuvc/build/CMakeFiles)
find_package(libuvc REQUIRED)
include_directories( C:/libuvc/include )

include(CTest)
enable_testing()

add_executable(OpenCV_Test
                ${SOURCES})

target_link_libraries( OpenCV_Test ${OpenCV_LIBS} C:/libuvc/build/Release/uvc.lib)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

lafith avatar Jan 21 '22 08:01 lafith

Hi, Unfortunately, I do not have an idea what could be going wrong in your example. I would recommend starting with the simplest possible example (just printing something) and then adding complexity step by step to find the step causing the program to stop working.

papr avatar Jan 21 '22 08:01 papr

Ok I tried this approach and this is when I am getting no output nor error. Do you have any idea where could be the problem?

#include <iostream>
#include <libuvc/libuvc.h>

int main(){
  std::cout<<"UVC Test:"<<std::endl;
  uvc_context_t *ctx = nullptr;
  uvc_error_t res = uvc_init(&ctx, nullptr);
//  if (res < 0)
//    {
//        uvc_perror(res, "uvc_init error");
//        std::cout<<"error"<<std::endl;
//    }
//    uvc_exit(ctx);
//   std::cout<<"Done!"<<std::endl;
     return 0;
}

lafith avatar Jan 21 '22 11:01 lafith

@lafith uvc_init compares against NULL, not nullptr. I do not know enough about c++ to know if this makes a difference. Please give passing NULL instead a try.

papr avatar Jan 21 '22 11:01 papr

@papr No, same result :(

lafith avatar Jan 21 '22 11:01 lafith