google / glog

C++ implementation of the Google logging module
http://google.github.io/glog/
BSD 3-Clause "New" or "Revised" License
6.93k stars 2.05k forks source link

why compile can not pass.it ocurrs the errors as follow。 #1091

Closed linshigang closed 3 months ago

linshigang commented 3 months ago
In file included from /home/lsg/gsoap-onvif/factory/3rdparty/ssigonvif/ssig/src/OnvifClientDevice.cpp:4:0:
/usr/local/include/glog/logging.h:60:4: error: #error <glog/logging.h> was not included correctly. See the documention for how to consume the library.

mycode:

#include "OnvifClientDevice.hpp"
#include <iostream> 
#include <sstream> 
#include "glog/logging.h"
#include "DeviceBinding.nsmap"

OnvifClientDevice::OnvifClientDevice(std::string url,
                                     std::string user,
                                     std::string password,
                                     bool showCapabilities) {
  device_url_ = "http://" + url + "/onvif/device_service";
  user_ = user;
  passwd_ = password;

  has_media_ = false;
  has_ptz_ = false;

  proxy_device_.soap_endpoint = device_url_.c_str();

  soap_register_plugin(proxy_device_.soap, soap_wsse);
  soap_ = soap_new();

  if (SOAP_OK != soap_wsse_add_UsernameTokenDigest(proxy_device_.soap,
                                                   NULL, 
                                                   user.c_str(),
                                                   password.c_str())) {
    LOG(INFO) << "Device binding 1 Error";
  }

  if (SOAP_OK != soap_wsse_add_Timestamp(proxy_device_.soap, "Time", 10))
  {
    LOG(INFO) << "Device binding 2 Error";
  }

  auto *get_cap = soap_new__tds__GetCapabilities(soap_, -1);
  get_cap->Category.push_back(tt__CapabilityCategory__All);
  auto *response = soap_new__tds__GetCapabilitiesResponse(soap_, -1);

  if (SOAP_OK == proxy_device_.GetCapabilities(get_cap, response)) {

    if (response->Capabilities->Media != NULL) {
      has_media_ = true;

      if(showCapabilities) {
        LOG(INFO) << "--------------------------Media-----------------------";
        LOG(INFO) << "XAddr : " << response->Capabilities->Media->XAddr;
      }
      media_url_ = response->Capabilities->Media->XAddr;
    }

    if (response->Capabilities->PTZ != NULL) {
      has_ptz_ = true;
      if(showCapabilities) {
        LOG(INFO) << "--------------------------PTZ-------------------------";
        LOG(INFO) << "XAddr : " << response->Capabilities->PTZ->XAddr;
      }
      ptz_url_ = response->Capabilities->PTZ->XAddr;
    }
  }
  else {
    LOG(FATAL) << "Error : " << ErrorString();
  }
  soap_destroy(soap_); 
  soap_end(soap_);
}

OnvifClientDevice::~OnvifClientDevice(){

}

std::string OnvifClientDevice::ErrorString() {
  std::string result = "";
  result += std::to_string(proxy_device_.soap->error);
  result += " FaultString : ";
  if (*soap_faultstring(proxy_device_.soap)) {
    std::string faultstring(*soap_faultstring(proxy_device_.soap));
    result += faultstring;
  } else {
    result += "null";
  }
  result += " FaultCode : ";
  if (*soap_faultcode(proxy_device_.soap)) {
    std::string faultcode(*soap_faultcode(proxy_device_.soap));
    result += faultcode;
  } else {
    result += "null";
  }
  result += " FaultSubcode : ";
  if (*soap_faultsubcode(proxy_device_.soap)) {
    std::string faultsubcode(*soap_faultsubcode(proxy_device_.soap));
    result += faultsubcode;
  } else {
    result += "null";
  }
  result += " FaultDetail : ";
  if (*soap_faultdetail(proxy_device_.soap)) {
    std::string faultdetail(*soap_faultdetail(proxy_device_.soap));
    result += faultdetail;
  } else {
    result += "null";
  }
  return result;
}
sergiud commented 3 months ago

As the error message indicates, you did not integrate glog properly. Take a look at the documentation for how this needs to be done.

linshigang commented 3 months ago

but ,in the cmake command ,it can pass. like this: cmake_minimum_required (VERSION 3.16) project (myproj VERSION 1.0)

find_package (glog 0.7.0 REQUIRED)

add_executable (myapp free_function.cpp) target_link_libraries (myapp glog::glog) ,but when i use g++ free_function.cpp -o myapp -lglog,it will occur these errors.

sergiud commented 3 months ago

This is expected. You need either Bazel or CMake to consume glog. Anything else is not supported.