VS 2017编译在Linux上运行的CMake项目时出现意外行为

时间:2019-01-31 15:10:36

标签: c++ visual-studio visual-c++ cmake c++17

我有一个CMake项目,可以在带有g ++的Linux上正常工作。

在Windows(第10版,创建者更新)上,CMake可以正常运行并生成相关文件。

因此,我打开了TestProject.sln解决方案文件,并进行了测试运行,我运行了“本地Windows调试器”,并得到了此错误。

Error   LNK1104 cannot open file 'jsoncpp.lib'

这就是我设置此项目的方式。

.
|-root
|  |- src
|  |- lib
|  |- bin
|  |- app
|  |- include
|  |- extras
|        |- jsoncpp
|-build

我不太确定这里可能出什么问题。

我将jsoncpp添加为子模块。

我做到了

git submodule update --init --recursive

中有一个jsoncpp.lib文件
root\lib\Debug

这是我的CMakeLists.txt

cmake_minimum_required (VERSION 3.13)
project (TestProject)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/root/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/root/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/root/bin)

set(SOURCE_DIR ${PROJECT_SOURCE_DIR}/root/src)
set(INCLUDE_DIR ${PROJECT_SOURCE_DIR}/root/include)
set(EXTRAS_DIR ${PROJECT_SOURCE_DIR}/root/extras)
set(PROJECT_MAIN_DIR ${PROJECT_SOURCE_DIR}/root/app)

set(SOURCES
  ${INCLUDE_DIR}/Combinations.hpp  
  ${INCLUDE_DIR}/Lib.hpp  
  ${SOURCE_DIR}/Lib.cpp
  )

add_executable(TestProject ${PROJECT_MAIN_DIR}/Main.cpp ${SOURCES})

add_subdirectory(${EXTRAS_DIR}/jsoncpp jsoncpp)

target_link_libraries(TestProject jsoncpp)

set_target_properties(TestProject PROPERTIES
  CXX_STANDARD_REQUIRED ON
  CXX_STANDARD 17
  CXX_EXTENSIONS OFF
  )

这是CMake的输出

Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.17134.
The C compiler identification is MSVC 19.16.27026.1
The CXX compiler identification is MSVC 19.16.27026.1
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
JsonCpp Version: 1.8.4
Looking for C++ include clocale
Looking for C++ include clocale - found
Looking for localeconv
Looking for localeconv - found
Looking for C++ include sys/types.h
Looking for C++ include sys/types.h - found
Looking for C++ include stdint.h
Looking for C++ include stdint.h - found
Looking for C++ include stddef.h
Looking for C++ include stddef.h - found
Check size of lconv
Check size of lconv - done
Performing Test HAVE_DECIMAL_POINT
Performing Test HAVE_DECIMAL_POINT - Success
Found PythonInterp: C:/Users/USERNAME/emacs-26.1-x86_64/bin/python2.exe (found suitable version "2.7.14", minimum required is "2.6") 
Configuring done
Generating done

我对Visual Studio不太熟悉,但是看着错误,它说“无法打开”和“无法找到”,所以我的第一想到可能是权限问题。

所以我用Admin Privileges启动了VS,但错误仍然存​​在。

我认为可能存在一些编译器问题,因此我将nmake.exe用作编译器(在生成nmake makefile之后),但那里也没有运气。

我不确定这是否是链接器问题,因为CMake能够找到并链接jsoncpp库,因此我怀疑CMake在构建Makefile时出错。

我不确定如何调试该问题。

0 个答案:

没有答案