I have a CMake project that works fine on Linux with g++.
On Windows (10, Creators Update) CMake runs fine and generates relevant files.
So I opened TestProject.sln solution file and for a test run, I ran 'Local Windows Debugger' and got this error.
Error LNK1104 cannot open file 'jsoncpp.lib'
This is how I've setup this project.
.
|-root
| |- src
| |- lib
| |- bin
| |- app
| |- include
| |- extras
| |- jsoncpp
|-build
I'm not really sure what could be wrong here.
I have jsoncpp added as a submodule.
I did
git submodule update --init --recursive
and there is a jsoncpp.lib file in
root\lib\Debug
This is my 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
)
This is CMake's output
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
I'm not very familiar with Visual Studio but looking at the error, it says 'cannot open' and not 'couldn't find' so my first thought was maybe it's a permission issue.
So I booted up VS with Admin Privileges but the error continued.
I thought maybe there's some compiler issue so I used nmake.exe as a compiler (after generating nmake makefiles) but no luck there either.
I'm not sure if it's a linker issue since CMake was able to find and link jsoncpp library so I doubt CMake made a mistake building the Makefile.
I'm not sure how I should go about debugging the issue.