LNK2001: My boost libraries are (probably) built incorrectly

I decided to update my boost libraries from 1.61 to 1.63, and in the project that I updated to use the new files, I'm getting some new error messages I wasn't getting before:

error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAAEBVerror_category@12@XZ)
error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAAEBVerror_category@12@XZ)

Since my 1.63 libraries are being compiled using Visual Studio 2017, my first assumption is that I've made a mistake compiling the boost libraries, so here are the total steps I'm taking from a clean unzip of the boost files:

  • Start Menu→Visual Studio 2017 RC→Developer Command Prompt
  • I change directory until I'm in the high-level boost_1_63_0 folder.
  • I run bootstrap.bat
  • I open project-config.jam for editing
  • I change using msvc ; to using msvc : 14.1 : E:Program FilesMicrosoft Visual StudioVCToolsMSVC14.10.24911binHostX64x64;
  • I open boost/config/auto_link.hpp for editing
  • I make an edit to this file (code listed below after the list)
  • In the open command prompt, I execute the command b2 architecture=x86 address-model=64 link=static threading=multi runtime-link=shared --build-type=complete stage --stagedir=stage/x64 -a
  • It completes with the following message at the end (listed below after the list)
  • I attempt to use these libraries with my code, using #define BOOST_LIB_DIAGNOSTIC to track that the correct files are being used (they are).
  • I attempt to compile my project that uses boost.asio, and get the two unresolved external symbol errors listed above.
  • Does anyone know where my mistake is? These errors do not occur if I use the boost 1.61 libraries compiled using Visual Studio 2015 in Visual Studio 2017 RC.

    auto_link.hpp (old):

    # elif defined (BOOST_MSVC)
    
         // vc14:
    #  define BOOST_LIB_TOOLSET "vc140"
    

    auto_link.hpp (new):

    # elif defined (BOOST_MSVC) && (BOOST_MSVC < 1910)
    
         // vc14:
    #  define BOOST_LIB_TOOLSET "vc140"
    
    # elif defined (BOOST_MSVC)
    
         // vc15:
    #  define BOOST_LIB_TOOLSET "vc141"
    

    Message at the end of the boost compilation process:

    ...failed updating 6 targets...
    ...skipped 4 targets...
    ...updated 904 targets...
    

    Libraries shown by use of #define BOOST_LIB_DIAGNOSTIC :

    1>Linking to lib file: libboost_system-vc141-mt-1_63.lib
    1>Linking to lib file: libboost_date_time-vc141-mt-1_63.lib
    1>Linking to lib file: libboost_regex-vc141-mt-1_63.lib
    

    Let me know if there's any other diagnostic information needed. I tried commenting out various uses of the boost.asio library, but only removing the header entirely eliminated these issues (which, of course, made the boost components unusable).


    This seems to be similar as LNK 2019 error using Boost::asio as you have the same errors.

    I just installed VS2017RC and boost 1.63. Then I used this description: Build boost with msvc 14.1 ( VS2017 RC) . Note: your line

    using msvc : 14.1 : E:Program FilesMicrosoft Visual StudioVCToolsMSVC14.10.24911binHostX64x64;
    

    should probably include the "cl.exe" and quotes.

    using msvc : 14.1 : "E:Program FilesMicrosoft Visual StudioVCToolsMSVC14.10.24911binHostX64x64cl.exe";
    

    ...They should implement a progress bar or such ;) Guess what:

    ...failed updating 6 targets...
    ...skipped 4 targets...
    ...updated 1214 targets...
    

    So look at the error message:

    msvc.compile.asm bin.v2libscontextbuildmsvc-14.1debugaddress-model-64link-staticthreading-multiasmmake_x86_64_ms_pe_masm.obj
    'ml64' is not recognized as an internal or external command, operable program or batch file.
    ml64 -nologo -c -Zp4 -Cp -Cx -DBOOST_ALL_NO_LIB=1 -DBOOST_CONTEXT_EXPORT= -DBOOST_CONTEXT_SOURCE -DBOOST_ALL_NO_LIB=1 -DBOOST_CONTEXT_EXPORT= -DBOOST_CONTEXT_SOURCE /Zi /Zd /W3  -Fo "bin.v2libscontextbuildmsvc-14.1debugaddress-model-64link-staticthreading-multiasmmake_x86_64_ms_pe_masm.obj" "libscontextsrcasmmake_x86_64_ms_pe_masm.asm"
    ...failed msvc.compile.asm bin.v2libscontextbuildmsvc-14.1debugaddress-model-64link-staticthreading-multiasmmake_x86_64_ms_pe_masm.obj...
    

    Missing 64-bit dependencies... So, like KindDragon says in the second link:

    Run "Developer Command Prompt for VS 2017 RC" from Windows Start Menu to boostrap from a shell configured using the x86 vcvars or x64 vcvars .

    It is necessary to configure the shell using the 64-bit compiler variables.

    cd "Program Files (x86)Microsoft Visual Studio 14.0VC"
    vcvarsall amd64
    

    ..alternatively you could start the x64 native environment from the Start menu: -> Visual Studio 201x -> Visual Studio Tools -> Windows Desktop Command Prompts -> VS201x x64 Native Tools Command Prompt

    And then build again.

    ...failed updating 2 targets...
    ...skipped 2 targets...
    ...updated 6 targets...
    

    With error message fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64' . So a rebuild is required.

    b2 --clean-all
    etc...
    

    ...You get the point. But it seems I read now in the comments that Bogdan has also mentioned this. Well, Kinddragon in Build boost with msvc 14.1 ( VS2017 RC) was actually first ;)

    链接地址: http://www.djcxy.com/p/95082.html

    上一篇: 控制。 不缓存任何东西

    下一篇: LNK2001:我的boost库(可能)构建不正确