当前位置: 首页 > article >正文

Chromium 如何构建一个单独exe c++

1、在src目录下新建一个jdtest文件夹

     src\jdtest

2、在jdtest文件下添加BUILD.gn jdtest.cc

   build.gn 内容如下:

# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/compiler/compiler.gni")

executable("jdtest") {
    if (is_win && current_cpu == "x64") {
      # The build infrastructure needs courgette to be named jdtest64.
      output_name = "jdtest64"
    }

    sources = [ "jdtest.cc" ]

    if (is_win) {
      ldflags = [ "/LARGEADDRESSAWARE" ]
    }

    deps = [
      "//base",
      "//build/win:default_exe_manifest",
    ]
}

其中可执行文件名是executable("jdtest")

deps 依赖引用了base库。

jdtest.cc内容如下:

#include<iostream>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>

#include <initializer_list>
#include <memory>
#include <string>
#include <tuple>
#include <vector>

#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"

int main(int argc, const char* argv[]) {
  base::AtExitManager at_exit_manager;
  base::CommandLine::Init(argc, argv);
  const base::CommandLine& command_line =
      *base::CommandLine::ForCurrentProcess();

  command_line.GetCommandLineString();
  std::cout<<"hello world\n";


  return 0;
}

3、在\src\BUILD.gn 里面添加生成gn依赖:

    if (is_win) {
      deps += [
        "//jdtest:jdtest",
      ]

4、命令行输入:gn gen out/Debug

注意一定要在在\src\BUILD.gn里面添加//jdtest:jdtest 否则无法生成jdtest.ninja文件,导致无法编译。

 【F:\code\google\src\out\Debug\obj\jdtest\jdtest.ninja】

5、命令行输入:ninja -C out/debug jdtest

6、 最后在debug目录生成jdtest64.exe

 


http://www.kler.cn/news/343032.html

相关文章:

  • Linux 外设驱动 应用 1 IO口输出
  • 设计算法int IsExistEL(MGraph G),判断G是否存在EL路径,若存在,则返回1 ,否则返回0。
  • 【Linux】Windows搭建CentOS7环境
  • 多模态智能
  • 鸿蒙NEXT开发-动画(基于最新api12稳定版)
  • 【C++设计模式】结构型模式:桥接模式
  • Leetcode 第 417 场周赛题解
  • Python - Windows下安装pip
  • 【含开题报告+文档+PPT+源码】基于过滤协同算法的旅游推荐管理系统设计与实现
  • 408算法题leetcode--第30天
  • 97. UE5 GAS RPG 实现闪电链技能(二)
  • 项目常用版本控制管理工具
  • Nacos 2.2.x版本配置详解(鉴权版本)
  • 【VUE】Vue3中的diff流程
  • No.10 笔记 | PHP学习指南:PHP数组掌握
  • Linux的环境与历史
  • Label Studio 半自动化标注
  • 2-119 基于matlab的合成孔径雷达(SAR)RDA(距离多普勒算法)、RMA(距离徙动算法)、CSA(线性调频变标算法)算法点目标成像与分析
  • 搭建一个高效的 TikTok 节点:从零开始的实践指南
  • 10月10日