boostorg / json

A C++11 library for parsing and serializing JSON to and from a DOM container in memory.
https://boost.org/libs/json
Boost Software License 1.0
432 stars 96 forks source link

explain how to disable autolinking better #1036

Closed kjgbrt closed 3 weeks ago

kjgbrt commented 2 months ago

Version of Boost

Version: 1.85.0

Steps necessary to reproduce the problem

Hello,

  1. I download a copy of the entire boost library, 1.85, and unzip it to a folder
  2. I make a new project in Visual Studio, make sure "hello world" compiles, and then add the path to the boost library via Properties >> C/C++ >> General >> Additional Include Directories
  3. I verify that boost can run by running the simple program on the getting started page (https://www.boost.org/doc/libs/1_86_0/more/getting_started/windows.html)
  4. I then run the following code because I want to use json header-only:
    
    #define BOOST_JSON_NO_LIB
    #include <iostream>
    #include <boost/json/src.hpp>

using std::cout;

int main() { cout << "hi\n"; return 0; }


When I try to compile, i get the following error: 
`LNK1104    cannot open file 'libboost_container-vc143-mt-gd-x64-1_85.lib'`

What am I doing wrong here? 

### All relevant compiler information
Windows OS 
VS 2022
C++14
Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33811 for x86

I'd really appreciate any help here, sorry for the confusion, I'm not an advanced C++ user nor Boost user. Thank you in advance
grisumbras commented 2 months ago

Are you sure you don't also link to a pre-built copy of Boost.JSON by accident? Does Visual Studio show you the actual link command?

kjgbrt commented 2 months ago

I'm not sure how I'd check what you mean.

output of hitting "build":

Build started at 15:10...
1>------ Build started: Project: boost_json, Configuration: Debug x64 ------
1>main.cpp
1>LINK : fatal error LNK1104: cannot open file 'libboost_container-vc143-mt-gd-x64-1_85.lib'
1>Done building project "boost_json.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 15:10 and took 01.430 seconds ==========

That's everything.

Also, I've been going through various online searches, and I'd like to note the following is set: Properties >> Configuration Properties >> C/C++ >> Precompiled Headers >> Precompiled Header = "Not Using Precompiled Headers"

grisumbras commented 2 months ago

There's this answer on StackOverflow, that might help you with getting the link command: https://stackoverflow.com/questions/1319972/how-to-show-linker-command-line-in-build-output-in-visual-studio.

Also, is that definitely the entire contents of your project? No other lines in that cpp file, no other cpp files?

kjgbrt commented 2 months ago

See information below. I'm at the very beginning of trying to use Boost.JSON, and I'm testing it out in a clean, empty project. Note, I changed the setting per the question asked in the link, and thus there's now 56 Warnings also popping up. I found* where the build log is exported, it looks like effectively the same output as below.

image

the output expanded slightly:

Build started at 16:15...
1>------ Build started: Project: boost_json, Configuration: Debug x64 ------
1>main.cpp
1>Microsoft (R) Incremental Linker Version 14.40.33811.0
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>"/OUT:C:\XXX\boost_json\x64\Debug\boost_json.exe" /INCREMENTAL "/ILK:boost_json\x64\Debug\boost_json.ilk" kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST "/MANIFESTUAC:level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG "/PDB:C:\XXX\boost_json\x64\Debug\boost_json.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT "/IMPLIB:C:\XXX\cpp\boost_json\x64\Debug\boost_json.lib" /MACHINE:X64 boost_json\x64\Debug\main.obj
1>LINK : fatal error LNK1104: cannot open file 'libboost_container-vc143-mt-gd-x64-1_85.lib'
1>Done building project "boost_json.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 16:15 and took 01.399 seconds ==========
grisumbras commented 2 months ago

As an option, try defining BOOST_ALL_NO_LIB rather than BOOST_JSON_NO_LIB.

kjgbrt commented 2 months ago

ah, that finally worked. thank you very much. could the readme please be updated? additionally, i assume this could potentially interfere with any boost components that do require a library?

grisumbras commented 2 months ago

Yeah, I'll amend the README.