• GFLAGS中cmakeLists的编写-OsqpEigen中cmakeLists的编写---GLOG移植


    1 glog

    使用 CMakeLists.txt 来组织和构建包含 glog 的项目是一个很好的选择。下面是一个如何使用 CMakeglog 的例子。

    1. 项目结构:

      ├── CMakeLists.txt
      └── main.cpp
      
      • 1
      • 2
    2. CMakeLists.txt:

      cmake_minimum_required(VERSION 3.10)
      project(GlogExample)
      
      # 设置C++标准为C++11
      set(CMAKE_CXX_STANDARD 11)
      
      # 查找glog库
      find_package(glog REQUIRED)
      
      add_executable(GlogExample main.cpp)
      
      # 链接glog库到你的项目
      target_link_libraries(GlogExample glog::glog)
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
    3. main.cpp (和之前的代码一样):

      #include 
      
      int main(int argc, char* argv[]) {
           
          google::InitGoogleLogging(argv[0]);
          google::SetLogDestination(google::INFO, "./myapp_");
      
          LOG(INFO) << "This is an INFO log.";
          LOG(WARNING) << "This is a WARNING log.";
          LOG(ERROR) << "This is an ERROR log.";
          VLOG(1) << "This is a verbose log level 1.";
      
          google::ShutdownGoogleLogging();
          return 0;
      }
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
    4. 构建与运行:
      在项目根目录下:

      mkdir build
      cd build
      cmake ..
      make
      ./GlogExample
      
      • 1
      • 2
      • 3
      • 4
      • 5

    这样,CMake 会帮助你解决库的查找和链接问题,你只需关注代码逻辑。确保在使用 CMakeLists.txt 前,你已经安装了 glogcmake。如果在配置或构建时遇到问题,或者有其他的需求,可以随时询问。

    2 这个错误是因为 CMake 在默认的路径下找不到 glog 的配置文件。在某些系统和安装方法中,glog 可能没有提供 glogConfig.cmake 或 glog-config.cmake 文件,这意味着 CMake find_package 命令不能直接找到它

    CMake Error at CMakeLists.txt:8 (find_package):
      By not providing "Findglog.cmake" in CMAKE_MODULE_PATH this project has
      asked CMake to find a package configuration file provided by "glog", but
      CMake did not find one.
    
      Could not find a package configuration file provided by "glog" with any of
      the following names:
    
        glog
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  • 相关阅读:
    Spring Task(简略笔记)
    码元和码点(字符串截取截取得是码元,汉字有一些偏僻字占据两个码元,字符的函数往往不是我们期待)
    IntelliJ IDEA 2022.2保姆级安装教学
    From High-Level Deep Neural Models to FPGAs
    图像融合--挑战、机遇与对策
    俄罗斯方块
    矩阵转置
    从 0 到 1 ,手把手教你编写《消息队列》项目(Java实现) —— 介绍项目/ 需求分析
    java建造者模式
    枚举类型的使用
  • 原文地址:https://blog.csdn.net/yalipf/article/details/134280911