gpt4 book ai didi

c++ - NMAKE : fatal error U1077: cl. exe 和 nmake.exe 返回代码 '0x2'

转载 作者:行者123 更新时间:2023-11-28 04:02:24 26 4
gpt4 key购买 nike

我正在尝试使用 cmake 和 CLion 构建一个 C++ 项目,但我遇到了一些我无法理解的错误:

"C:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" --build C:\Users\username\project-name\cmake-build-debug --target all_tests
Scanning dependencies of target all_tests
[ 0%] Building CXX object CMakeFiles/all_tests.dir/tests/all_tests.cpp.obj
all_tests.cpp
C:\PROGRA~2\Boost\include\BOOST-~1\boost/test/impl/compiler_log_formatter.ipp(64): warning C4273: 'boost::unit_test::output::compiler_log_formatter::log_start': inconsistent dll link
C:\PROGRA~2\Boost\include\BOOST-~1\boost/test/output/compiler_log_formatter.hpp(37): note: see previous definition of 'log_start'
C:\PROGRA~2\Boost\include\BOOST-~1\boost/test/impl/compiler_log_formatter.ipp(76): warning C4273: 'boost::unit_test::output::compiler_log_formatter::log_finish': inconsistent dll link
C:\PROGRA~2\Boost\include\BOOST-~1\boost/test/output/compiler_log_formatter.hpp(38): note: see previous definition of 'log_finish'
// ...
// ... many more warnings like these
// ...
C:\PROGRA~2\Boost\include\BOOST-~1\boost/test/impl/unit_test_parameters.ipp(759): warning C4273: 'boost::unit_test::runtime_config::save_pattern': inconsistent dll link
C:\PROGRA~2\Boost\include\BOOST-~1\boost/test/unit_test_parameters.hpp(93): note: see previous definition of 'save_pattern'
NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~3\2017\BUILDT~1\VC\Tools\MSVC\1416~1.270\bin\Hostx86\x86\cl.exe' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.

我使用的cmake文件如下:

cmake_minimum_required(VERSION 3.9)
project(project_name)

set(CMAKE_CXX_STANDARD 11)

# private lib
add_library(lib INTERFACE)
target_include_directories(lib INTERFACE src/utilities)

# boost
set(BOOST_ROOT "C:\\Program Files\\Boost")
find_package(Boost CONFIG 1.71.0)
if(Boost_FOUND)
message("FOUND")
include_directories(${Boost_INCLUDE_DIR})
endif()

SET(MAIN "...")
SET(TESTS "...")

add_executable(all_tests tests/all_tests.cpp ${MAIN} ${TESTS})
target_link_libraries(all_tests lib)

请注意,同一个项目可以在我的 Mac 上运行,但是当我尝试在 Windows 10 中构建它时出现此错误,请问这是什么问题?

编辑:

all_tests.cpp:

#define BOOST_TEST_DYN_LINK

#include <boost/test/unit_test.hpp>
#include <boost/test/included/unit_test.hpp>

// initialization function:
bool init_unit_test() {
return true;
}

// entry point:
int main(int argc, char* argv[], char* envp[]) {
return boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
}

示例测试套件:

#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../../src/path/to/header.hpp"

BOOST_AUTO_TEST_SUITE( Suite1 )

BOOST_AUTO_TEST_CASE( Test1 ) {
auto res = header_class::function1();
BOOST_CHECK_EQUAL(res, expected_result);
}

BOOST_AUTO_TEST_CASE( Test2 ) {
auto res = header_class::function2();
BOOST_CHECK_EQUAL(res, expected_result);
}

BOOST_AUTO_TEST_SUITE_END()

我非常确定测试用例中的代码是正确的,并且不会导致问题。

最佳答案

header boost/test/unit_test.hppboost/test/included/unit_test.hpp 包含相同的功能但用途不同:

  • boost/test/unit_test.hpp声明库文件中定义的函数,
  • boost/test/included/unit_test.hpp 定义函数,因此不需要包含库文件。

绝对没有必要同时使用这两个 header 。

关于c++ - NMAKE : fatal error U1077: cl. exe 和 nmake.exe 返回代码 '0x2',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59283381/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com