为什么生成汇编文件时编译器检查会跳过,为什么项目无法构建?

问题描述 投票:0回答:1

我使用 fmt 库编写了一个 hello world 程序,尝试使用 cmake 将库包含在我的项目中,而无需提前安装库来将项目转移给其他人。但它无法构建。

我的CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)

project(HelloWorld)

include(FetchContent)

FetchContent_Declare(
  fmt
  GIT_REPOSITORY https://github.com/fmtlib/fmt.git
  GIT_TAG master
)

FetchContent_MakeAvailable(fmt)

add_executable(HelloWorld helloworld.cpp)

target_link_libraries(HelloWorld PRIVATE fmt::fmt)

set(CMAKE_GENERATOR "MinGW Makefiles" CACHE STRING "CMake generator" FORCE)
set(CMAKE_CXX_COMPILER "C:/msys64/mingw64/bin/g++")
set(CMAKE_C_COMPILER "C:/msys64/mingw64/bin/gcc")

我的helloworld.cpp:

#include <fmt/core.h>

int main()
{
    fmt::print("Hello World!\n");
    return 0;
}

在终端我写:

cmake -G "MinGW Makefiles" D:\Users\aLL_in\projects\helloworld_2

生成结果: enter image description here

然后我写道:

cmake --build D:\Users\aLL_in\projects\helloworld_2\build

结果: enter image description here

我该怎么办? PS 我使用 VS Code

c++ visual-studio-code cmake g++
1个回答
0
投票

您还可以使用ExternalProject_Add 函数来代替获取。无论哪种方式,您都需要安装 fmt 项目,但您没有这样做。另一种选择可能是这样的:

ExternalProject_Add(
    fmt
  GIT_REPOSITORY https://github.com/fmtlib/fmt.git
  GIT_TAG master
    PREFIX ${CMAKE_BINARY_DIR}/fmt
    CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=/usr/local/)
set(FMT_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include/)
set(FMT_LIBRARY_DIR ${CMAKE_INSTALL_PREFIX}/lib/)
set(FMT_LIBRARIES libfmt.a)

我还没有测试过。

© www.soinside.com 2019 - 2024. All rights reserved.