MSVC do not generate lib via cmake - visual-c++

CMakeLists:
if (MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
add_library(${PROJECT_NAME} SHARED ${SOURCES})
CMake 2.8.12 + MSVC 2015
config outputs:
-- The C compiler identification is MSVC 19.0.24210.0
-- The CXX compiler identification is MSVC 19.0.24210.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMAKE_C_FLAGS_DEBUG is /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1
CMAKE_C_FLAGS_RELEASE is /MD /O2 /Ob2 /D NDEBUG
CMAKE_C_FLAGS_RELWITHDEBINFO is /MD /Zi /O2 /Ob1 /D NDEBUG
CMAKE_C_FLAGS_MINSIZEREL is /MD /O1 /Ob1 /D NDEBUG
-- Configuring done
-- Generating done
Referred https://cmake.org/pipermail/cmake/2009-March/027990.html.
You most likely have not setup your classes and/or function calls to be
exported. If you have no exported classes/functions Visual Studio will not
generate an import library for you.
But adding CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON got the same result.
How to make MSVC generate lib & dll like mingw?

Update cmake 2.8 to 3.4 solves the problem.
https://cmake.org/cmake/help/v3.4/release/3.4.html?highlight=windows_export_all_symbols

Related

Pico examples C/C++ build issues with cmake - Detecting C compiler ABI info - failed

I'm trying to build the examples for RP pico using Visual Studio Code 2022 on windows 11.
I have been following the "Getting started with raspberry pi pico" document and have succeeded up to the point where the nmake command is used to build the examples using developer command prompt.
It seems the first hurdle is "Detecting C compiler ABI info - failed" please see below for full output. I have searched all over the internet and stack overflow and tried various peoples fixes but nothing seems to help.
I have tried:
Setting cl.exe as administrator
Running developer command prompt as admin
Reinstalling VS code and cmake
Manually installed windows sdk (as it's not an option on the MSVC installer)
Running VsDevCmd.bat which fails with "Encountered errors" but nothing more useful. I have run the debug and output to txt file but I don't know what I'm looking at.
Thanks in advance.
Microsoft (R) Program Maintenance Utility Version 14.32.31329.0
Copyright (C) Microsoft Corporation. All rights reserved.
[ 0%] Built target bs2_default
[ 0%] Built target bs2_default_padded_checksummed_asm
[ 0%] Performing configure step for 'ELF2UF2Build'
-- The C compiler identification is MSVC 19.32.31329.0
-- The CXX compiler identification is MSVC 19.32.31329.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/pico/Downloads/pico-examples/build/elf2uf2/CMakeFiles/CMakeTmp
Run Build Command(s):nmake -f Makefile /nologo cmTC_add02\fast && "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.32.31326\bin\Hostx64\x64\nmake.exe" -f CMakeFiles\cmTC_add02.dir\build.make /nologo -L CMakeFiles\cmTC_add02.dir\build
Building C object CMakeFiles/cmTC_add02.dir/testCCompiler.c.obj
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_cl_compile_depends --dep-file=CMakeFiles\cmTC_add02.dir\testCCompiler.c.obj.d --working-dir=C:\pico\Downloads\pico-examples\build\elf2uf2\CMakeFiles\CMakeTmp --filter-prefix="Note: including file: " -- C:\PROGRA~2\MICROS~4\2022\BUILDT~1\VC\Tools\MSVC\1432~1.313\bin\Hostx64\x64\cl.exe #C:\Users\Dan\AppData\Local\Temp\nmE440.tmp
testCCompiler.c
Linking C executable cmTC_add02.exe
"C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_add02.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x86\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x86\mt.exe --manifests -- C:\PROGRA~2\MICROS~4\2022\BUILDT~1\VC\Tools\MSVC\1432~1.313\bin\Hostx64\x64\link.exe /nologo #CMakeFiles\cmTC_add02.dir\objects1.rsp #C:\Users\Dan\AppData\Local\Temp\nmE49F.tmp
LINK Pass 1: command "C:\PROGRA~2\MICROS~4\2022\BUILDT~1\VC\Tools\MSVC\1432~1.313\bin\Hostx64\x64\link.exe /nologo #CMakeFiles\cmTC_add02.dir\objects1.rsp /out:cmTC_add02.exe /implib:cmTC_add02.lib /pdb:C:\pico\Downloads\pico-examples\build\elf2uf2\CMakeFiles\CMakeTmp\cmTC_add02.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_add02.dir/intermediate.manifest CMakeFiles\cmTC_add02.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'MSVCRTD.lib'
NMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.32.31326\bin\Hostx64\x64\nmake.exe"' : return code '0x2'
Stop.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "C:/pico/Downloads/pico-examples/build/elf2uf2/CMakeFiles/CMakeOutput.log".
See also "C:/pico/Downloads/pico-examples/build/elf2uf2/CMakeFiles/CMakeError.log".
NMAKE : fatal error U1077: 'echo' : return code '0x1'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.32.31326\bin\Hostx64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.32.31326\bin\Hostx64\x64\nmake.exe"' : return code '0x2'
Stop.
I had a pretty similar issue in my project with Ninja.
The compilation is triggered with the next bat file (it's not full, just a part to generate CMake cache):
#echo off
SETLOCAL
set BUILD_TYPE=%~1
IF NOT "%BUILD_TYPE%"=="" GOTO BUILD_TYPE_OK
set BUILD_TYPE=Debug
:BUILD_TYPE_OK
set CMAKE_MAKE_PROGRAM=C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe
set C_COMPILER=C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe
set CXX_COMPILER=C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe
echo Build type: %BUILD_TYPE%
echo SBP_SBP_MSVC_QT64_DIR = %SBP_SBP_MSVC_QT64_DIR%
set PATH_X64=%PATH%;%SBP_SBP_MSVC_QT64_DIR%
set PATH=%PATH_X64%
cmake -DCMAKE_BUILD_TYPE=%BUILD_TYPE% "-DCMAKE_MAKE_PROGRAM=%CMAKE_MAKE_PROGRAM%" "-DCMAKE_C_COMPILER=%C_COMPILER%" "-DCMAKE_CXX_COMPILER=%CXX_COMPILER%" -DPDB_DIR=../deploy-pdb/x64 -DCMAKE_INSTALL_PREFIX=../deploy/bin-x64 -G Ninja -S . -B ../build/x64
if %errorlevel% neq 0 exit /b %errorlevel%
echo Done.
ENDLOCAL
The original output looked like this:
Build type: Debug
SBP_SBP_MSVC_QT64_DIR = c:\Qt\5.15.2\msvc2019_64
-- The C compiler identification is MSVC 19.32.31332.0
-- The CXX compiler identification is MSVC 19.32.31332.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.24/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: D:/Job/Code/Subpac/x1c1-multitool/build/x64/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_3975f && [1/2] Building C object CMakeFiles\cmTC_3975f.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTC_3975f.exe
FAILED: cmTC_3975f.exe
cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_3975f.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\MSVC\1432~1.313\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_3975f.dir\testCCompiler.c.obj /out:cmTC_3975f.exe /implib:cmTC_3975f.lib /pdb:cmTC_3975f.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
RC Pass 1: command "rc /fo CMakeFiles\cmTC_3975f.dir/manifest.res CMakeFiles\cmTC_3975f.dir/manifest.rc" failed (exit code 0) with the following output:
The system cannot find the file specified
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "D:/Test/build/x64/CMakeFiles/CMakeOutput.log".
See also "D:/Test/build/x64/CMakeFiles/CMakeError.log".
[process exited with code 1 (0x00000001)]
The issue was fixed when I added the next line to the build script:
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64. Below the part of the bat file with this line added:
#echo off
SETLOCAL
set BUILD_TYPE=%~1
IF NOT "%BUILD_TYPE%"=="" GOTO BUILD_TYPE_OK
set BUILD_TYPE=Debug
:BUILD_TYPE_OK
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
set CMAKE_MAKE_PROGRAM=C:/Program Files/Microsoft Visual Studio/2022....
Now the output looks like this, and when I add commands to deploy, all works fine:
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.2.6
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
Build type: Debug
SBP_SBP_MSVC_QT64_DIR = c:\Qt\5.15.2\msvc2019_64
-- The C compiler identification is MSVC 19.32.31332.0
-- The CXX compiler identification is MSVC 19.32.31332.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Test/build/x64
Done.
Hope it will help to solve your problem with nmake.

Setting cmake's msvc compilers flags on command line using git bash

Can someone help with the following issue. I'm using Cmake + git bash and on the windows machine with msvc compiler. If I configure project in the following way cmake .. everything works fine and I can see the following output:
-- Building for: Visual Studio 16 2019
-- The C compiler identification is MSVC 19.24.28319.0
-- The CXX compiler identification is MSVC 19.24.28319.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/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/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - works
However, when I try to set compiler flags cmake -DCMAKE_CXX_FLAGS="/MD" .. I get the following error:
-- Building for: Visual Studio 16 2019
-- The C compiler identification is MSVC 19.24.28319.0
-- The CXX compiler identification is MSVC 19.24.28319.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/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/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.17/Modules/CMakeTestCXXCompiler.cmake:53 (message):
The C++ compiler
"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/dev/projects/camshare/microservices/templates/microservice_cpp/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe cmTC_ce8fa.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=16.0 /v:m && Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Microsoft (R) C/C++ Optimizing Compiler Version 19.24.28319 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
Program
cl /c /Zi /W1 /WX- /diagnostics:column /Od /Ob0 /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_ce8fa.dir\Debug\\" /Fd"cmTC_ce8fa.dir\Debug\vc142.pdb" /Gd /TP /errorReport:queue C:/Program Files/Git/MD C:\dev\projects\camshare\microservices\templates\microservice_cpp\build\CMakeFiles\CMakeTmp\testCXXCompiler.cxx
c1xx : fatal error C1083: Cannot open source file: 'C:/Program': No such file or directory [C:\dev\projects\camshare\microservices\templates\microservice_cpp\build\CMakeFiles\CMakeTmp\cmTC_ce8fa.vcxproj]
MD
c1xx : fatal error C1083: Cannot open source file: 'Files/Git/MD': No such file or directory [C:\dev\projects\camshare\microservices\templates\microservice_cpp\build\CMakeFiles\CMakeTmp\cmTC_ce8fa.vcxproj]
testCXXCompiler.cxx
Generating Code...
CMake will not be able to correctly generate this project.
If I try to do the same with windows cmd everything works fine. Can you explain where is the problem and how I can fix it? Looks like compiler flags were incorrectly appended (strange Files/Git/MD on the command line). I've also tried `CXXFLAGS="/MD" cmake .." and got the same result.
The problem is in git bash mangling of forward slashes, solution can be easily found. Closing the question.

Why can't QuantLib compile on its last release?

After following the QuantLib 1.9 installation tutorial, I can't compile the library on my computer.
my setup
tutorial : https://www.quantlib.org/install/windows-python.shtml
python 3.6.3
Quantlib 1.9
Quantlib-SWIG 1.9
boost boost_1_66_0
visual studio 2017
windows 10
My error is the following :
"running build
running build_py
running build_ext
building 'QuantLib._QuantLib' extension
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -D__WIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNOMINMAX (.....) IC:\Users\AppData\Local\Continuum\anaconda3\Lib\site-packages\boost_1_66_0 /EHsc /TpQuantLib/quantlib_wrap.cpp /Fobuild\temp.win-amd64-3.6\Release\QuantLib/quantlib_wrap.obj /GR /FD /Zm250 /EHsc /bigobj /MD
quantlib_wrap.cpp
Info: Boost.Config is older than your compiler version - probably nothing bad will happen - but you may wish to look for an update Boost version. Define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE to suppress this message.
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO (....)/OUT:build\lib.win-amd64-3.6\QuantLib_QuantLib.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6\Release\QuantLib_QuantLib.cp36-win_amd64.lib /subsystem:windows /machine:x64
LINK : fatal error LNK1104: impossible d'ouvrir le fichier 'QuantLib-vc141-x64-mt.lib'
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe' failed with exit status 1104"
Wish someone could help with this one.

MSVC 2017 missing libboost_filesystem-vc141-mt-gd-x32-1_66.lib error

I'm trying to create a dynamic library on Windows but I have a problem with Boost, I keep getting this error
1>LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc141-mt-gd-x32-1_66.lib'
The thing is, according to this http://www.boost.org/doc/libs/1_66_0/more/getting_started/windows.html#header-only-libraries the two librairies are supposed to be header only header only
the cmake i'm using
cmake_minimum_required(VERSION 3.8)
project(mod_autoindex)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
SET (BOOST_ROOT "C:/Program Files (x86)/boost/boost_1_66_0")
SET (BOOST_INCLUDEDIR "${BOOST_ROOT}/boost")
if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
include_directories(${Boost_INCLUDE_DIR})
include_directories("../../include")
include_directories("../../include/sza")
include_directories("./include")
file(GLOB_RECURSE CPP_SRCS ${CMAKE_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE HEADERS ${CMAKE_SOURCE_DIR}/include/*.hpp)
set(SOURCE_FILES ${CPP_SRCS} ${HEADERS})
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME})
Any idea of wrang am i doing wrong ?
cmake output for cmake . -G "Visual Studio 15 2017 Win64"
-- The C compiler identification is MSVC 19.11.25547.0
-- The CXX compiler identification is MSVC 19.11.25547.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- filesystem
-- system
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/theo/Desktop/cpp_zia/modules/mod_autoindex
So the solution generation seems to work fine, but after that, when I try to build MSBuild mod_autoindex.sln i get the following error
LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc141-mt-gd-1_65_1.lib' [C:\Users\theo\
Desktop\cpp_zia\modules\mod_autoindex\mod_autoindex.vcxproj]
#update here is my current cmake
cmake_minimum_required(VERSION 3.8)
project(mod_autoindex)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
set(BOOST_ROOT "C:/Program Files (x86)/boost/boost_1_65_1")
set(Boost_ADDITIONAL_VERSIONS 1.65.1)
set(BOOST_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS filesystem REQUIRED)
if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
include_directories(${Boost_INCLUDE_DIR})
include_directories("../../include")
include_directories("../../include/sza")
include_directories("./include")
file(GLOB_RECURSE CPP_SRCS ${CMAKE_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE HEADERS ${CMAKE_SOURCE_DIR}/include/*.hpp)
MESSAGE( STATUS "BOOST libraries: " ${Boost_LIBRARIES} )
add_library(${PROJECT_NAME} SHARED ${CPP_SRCS} ${HEADERS})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
Many Boost libraries indeed are header only, but filesystem is not.
Instead of doing things manually I would use the CMake way of adding library dependencies by using the appropriate find_package module:
set(BOOST_ROOT "C:/Program Files (x86)/boost/boost_1_65_1")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
...
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
Boost binaries for your compiler can be downloaded at https://sourceforge.net/projects/boost/files/boost-binaries/
If CMake does not find your Boost installation (CMake 3.10.2 versions FindBoost.cmake module does know about versions up to Boost 1.65.1) you can try to add before the find_package call
set(Boost_ADDITIONAL_VERSIONS 1.66.0)
but
Boost changed its naming scheme starting from version 1.66.0. CMake up to version 3.10.2 does not know this scheme and therefore cannot handle it. You need to use Boost 1.65.1 instead.
Edit according to the comment by #ComicSansMS:
Do not hardcode the Boost path to your CMakeLists.txt instead set it per environment variable BOOST_ROOT or provide it as argument to your CMake call.
So go to your project path (the path where your CMakeLists.txt is stored)
mkdir build
cd build
and either do
set BOOST_ROOT=C:\Program Files (x86)\boost\boost_1_65_1
cmake .. -G "Visual Studio 15 2017"
or call
cmake .. -G "Visual Studio 15 2017" -DBOOST_ROOT="C:\Program Files (x86)\boost\boost_1_65_1"
Later you can use the buildmode of CMake to build your entire project
cmake --build . --target ALL_BUILD --config Release -- /nologo /verbosity:minimal /maxcpucount

Compiling Visual c++ programs from the command line and msvcr90.dll

When I compile my Visual c++ 2008 express program from inside the IDE and redistribute it on another computer, It starts up fine without any dll dependencies that I haven't accounted for. When I compile the same program from the visual c++ 2008 command line under the start menu and redistribute it to the other computer, it looks for msvcr90.dll at start-up.
Here is how it is compiled from the command line
cl /Fomain.obj /c main.cpp /nologo -O2 -DNDEBUG /MD /ID:(list of include directories)
link /nologo /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup /OUT:Build\myprogram.ex
e /LIBPATH:D:\libs (list of libraries)
and here is how the IDE builds it based on the relevant parts of the build log.
/O2 /Oi /GL /I clude" /I (list of includes) /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /FD /EHsc /MD /Gy /Yu"stdafx.h" /Fp"Release\myprogram" /Fo"Release\\" /Fd"Release\vc90.pdb" /W3 /c /Zi /TP /wd4250 /vd2
Creating command line "cl.exe #d:\myprogram\Release\RSP00000118003188.rsp /nologo /errorReport:prompt"
/OUT:"D:\myprgram\Release\myprgram.exe" /INCREMENTAL:NO /LIBPATH:"d:\gtkmm\lib" /MANIFEST /MANIFESTFILE:"Release\myprogam.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"d:\myprogram\Release\myprogram.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /ENTRY:"mainCRTStartup" /DYNAMICBASE /NXCOMPAT /MACHINE:X86 (list of libraries)
Creating command line "link.exe #d:\myprogram\Release\RSP00000218003188.rsp /NOLOGO /ERRORREPORT:PROMPT"
/outputresource:"..\Release\myprogram.exe;#1" /manifest
.\Release\myprogram.exe.intermediate.manifest
Creating command line "mt.exe #d:\myprogram\Release\RSP00000318003188.rsp /nologo"
I would like to be able to compile it from the command line and not have it look for such a late version of the runtime dll, like the version compiled from the IDE seems not to do. Both versions pass /MD to the compiler, so i am not sure what to do.
I know it is not exactly what you are looking for but you can invoke the ide build form the command line and it should give you the same output:
devenv solution.sln /build Release
This will build the Release configuration for solution.sln. (devenv /? on the command line for more info).

Resources