eidheim / Simple-Web-Server

A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.
MIT License
2.61k stars 751 forks source link

Cannot compile using using Visual Studio 2015 (MSVC 14.0) #188

Closed zethon closed 6 years ago

zethon commented 6 years ago

This has been baffling me for a couple days now. I am only seeing this problem on Windows 10, as everything seems to work fine on macOS and Linux.

My CMake project looks great, when I configure everything seems to be found:

Selecting Windows SDK version  to target Windows 10.0.16299.
Boost version: 1.65.1
Found the following Boost libraries:
  system
  thread
  chrono
  date_time
  atomic
CMake Warning (dev) at CMakeLists.txt:34 (if):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted variables like "MSVC" will no longer be dereferenced when the policy
  is set to NEW.  Since the policy is not set the OLD behavior will be used.
This warning is for project developers.  Use -Wno-dev to suppress it.

Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR) 
Boost version: 1.65.1
Found the following Boost libraries:
  system
  thread
  filesystem
  chrono
  date_time
  atomic
Configuring done
Generating done

But then when I go to compile I get the following:

"C:\Users\zethon\src\Simple-Web-Server\build\http_examples.vcxproj" (default target) (3) ->
(Link target) ->
  LINK : fatal error LNK1104: cannot open file 'libboost_system-vc140-mt-gd-1_65_1.lib' [C:\Users\zethon\src\Simple-Web-Server\build\http_examples.vcxproj]

    1 Warning(s)
    1 Error(s)

Now here's what's confusing me. Take a look at the linker command:

> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\link.exe /ERRORREPORT:QUEUE /OUT:"C:\Users\aclau\src\Simple-Web-Server\build\Debug\http_examples.exe" /INCREMENTAL /NOLOGO "C:\local\boost_1_65_1\lib64-msvc-14.0\boost_system-vc140-mt-gd-1_65_1.lib" "C:\local\boost_1_65_1\lib64-msvc-14.0\boost_thread-vc140-mt-gd-1_65_1.lib" "C:\local\boost_1_65_1\lib64-msvc-14.0\boost_filesystem-vc140-mt-gd-1_65_1.lib" "C:\local\boost_1_65_1\lib64-msvc-14.0\boost_chrono-vc140-mt-gd-1_65_1.lib" "C:\local\boost_1_65_1\lib64-msvc-14.0\boost_date_time-vc140-mt-gd-1_65_1.lib" "C:\local\boost_1_65_1\lib64-msvc-14.0\boost_atomic-vc140-mt-gd-1_65_1.lib" ws2_32.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:/Users/aclau/src/Simple-Web-Server/build/Debug/http_examples.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/Users/aclau/src/Simple-Web-Server/build/Debug/http_examples.lib" /MACHINE:X64  /machine:x64 http_examples.dir\Debug\http_examples.obj
> LINK : fatal error LNK1104: cannot open file 'libboost_system-vc140-mt-gd-1_65_1.lib' [C:\Users\aclau\src\Simple-Web-Server\build\http_examples.vcxproj]
> 

The error is telling me it's missing libboost_system-vc140-mt-gd-1_65_1.lib which isn't even listed! And then if I look at CMake, it confirms the linker:

image

And if I look at the dependencies in Visual Studio I see:

C:\local\boost_1_65_1\lib64-msvc-14.0\boost_system-vc140-mt-gd-1_65_1.lib
C:\local\boost_1_65_1\lib64-msvc-14.0\boost_thread-vc140-mt-gd-1_65_1.lib
C:\local\boost_1_65_1\lib64-msvc-14.0\boost_filesystem-vc140-mt-gd-1_65_1.lib
C:\local\boost_1_65_1\lib64-msvc-14.0\boost_chrono-vc140-mt-gd-1_65_1.lib
C:\local\boost_1_65_1\lib64-msvc-14.0\boost_date_time-vc140-mt-gd-1_65_1.lib
C:\local\boost_1_65_1\lib64-msvc-14.0\boost_atomic-vc140-mt-gd-1_65_1.lib

I'm also seeing the same problem in a project where I'm attempting to use SWS. You can see the appveyor of a build that illustrates this problem here: https://ci.appveyor.com/project/zethon/arcc/build/0.1.91

Does anyone have any suggestions?

zethon commented 6 years ago

My problem was related to Boost's auto-linking. I'm not entirely sure how it's supposed to work but once I disabled the feature I was able to get the sample projects to compile just fine.

For reference, to disable auto-linking, I added the BOOST_ALL_NO_LIB definition to my build. In CMake I simply added:

add_definitions(-DBOOST_ALL_NO_LIB)

I will submit a PR for this, but I'm not sure if auto-linking is purposely not disabled (ie. enabled) or not in this project.

chenzx commented 6 years ago

I use static link to Boost-1.56 on VS2013, & there is no problem, you need to config in CMake:

set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTI_THREADED ON) set(Boost_USE_STATIC_RUNTIME ON)