在VS Code上使用Boost

时间:2017-07-20 16:50:51

标签: c++ boost visual-studio-code

g ++使用此任务无法找到boost / regex.hpp:

{
            "taskName": "C4B", // Compile for debug with boost
            "command": "g++",
            "args": [
                "-g","${fileBasename}""-o","${fileBasenameNoExtension}"
            ],
            "type": "shell"
        },

我也试过使用这个arg:"-IC:\\boost\\include\\boost-1_64\\boost"

通过MinGW安装g ++,我将bin添加到PATH环境变量

我总是使用Visual Studio IDE ...我是命令行的新手

这就是我在VS Code上包含路径的方式:

    "includePath": [
                    "C:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include\\c++",
                    "C:\\boost\\include\\boost-1_64\\boost"

                ],
    "browse": {
                "path": [
                    "C:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include\\c++",
                    "C:\\boost\\include\\boost-1_64\\boost"

                ],

在此之前,我只包括C:\\boost\\include

这就是错误:

test1.cpp:1:27: fatal error: boost/regex.hpp: No such file or directory

编译终止。 我怎么解决这个问题?

更新1:

所以我包括include和lib文件夹:

"includePath": [
                "C:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include\\c++",
                "C:\\boost\\include",
                "C:\\boost\\lib"

            ],

我的编译任务是:

{
            "taskName": "C4B", // Compile for debug with boost
            "command": "g++",
            "args": [
                "-g","${fileBasename}","-IC:\\boost\\include\\boost-1_64","-o","${fileBasenameNoExtension}"
            ],
            "type": "shell"
        }

现在我有了这个输出:

C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640027cpp_regex_traits_char_layerIcEC2
ERKNS0_21cpp_regex_traits_baseIcEE':
C:/boost/include/boost-1_64/boost/regex/v4/cpp_regex_traits.hpp:370: undefined reference to `boost::re_detail_106400::c
pp_regex_traits_char_layer<char>::init()'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640011raw_storage6extendEj':
C:/boost/include/boost-1_64/boost/regex/v4/regex_raw_buffer.hpp:131: undefined reference to `boost::re_detail_106400::r
aw_storage::resize(unsigned int)'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640015save_state_initC1EPPNS0_11saved_
stateES4_':
C:/boost/include/boost-1_64/boost/regex/v4/perl_matcher_non_recursive.hpp:107: undefined reference to `boost::re_detail
_106400::get_mem_block()'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640015save_state_initD1Ev':
C:/boost/include/boost-1_64/boost/regex/v4/perl_matcher_non_recursive.hpp:115: undefined reference to `boost::re_detail
_106400::put_mem_block(void*)'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640012perl_matcherIN9__gnu_cxx17__norm
al_iteratorIPKcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEESaINS_9sub_matchISC_EEENS_12regex_traitsIcNS_16cpp
_regex_traitsIcEEEEE9match_impEv':
C:/boost/include/boost-1_64/boost/regex/v4/perl_matcher_common.hpp:214: undefined reference to `boost::re_detail_106400
::verify_options(unsigned int, boost::regex_constants::_match_flags)'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640012perl_matcherIN9__gnu_cxx17__norm
al_iteratorIPKcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEESaINS_9sub_matchISC_EEENS_12regex_traitsIcNS_16cpp
_regex_traitsIcEEEEE18unwind_extra_blockEb':
C:/boost/include/boost-1_64/boost/regex/v4/perl_matcher_non_recursive.hpp:1352: undefined reference to `boost::re_detai
l_106400::put_mem_block(void*)'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640011raise_errorINS_20regex_traits_wr
apperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE':
C:/boost/include/boost-1_64/boost/regex/pattern_except.hpp:75: undefined reference to `boost::re_detail_106400::raise_r
untime_error(std::runtime_error const&)'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640012perl_matcherIN9__gnu_cxx17__norm
al_iteratorIPKcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEESaINS_9sub_matchISC_EEENS_12regex_traitsIcNS_16cpp
_regex_traitsIcEEEEE12extend_stackEv':
C:/boost/include/boost-1_64/boost/regex/v4/perl_matcher_non_recursive.hpp:222: undefined reference to `boost::re_detail
_106400::get_mem_block()'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640018basic_regex_parserIcNS_12regex_t
raitsIcNS_16cpp_regex_traitsIcEEEEE4failENS_15regex_constants10error_typeEiNSt7__cxx1112basic_stringIcSt11char_traitsIc
ESaIcEEEi':
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_parser.hpp:237: undefined reference to `boost::regex_error::rege
x_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::regex_constants:
:error_type, int)'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_parser.hpp:238: undefined reference to `boost::regex_error::rais
e() const'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_parser.hpp:237: undefined reference to `boost::regex_error::~reg
ex_error()'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_parser.hpp:237: undefined reference to `boost::regex_error::~reg
ex_error()'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640019basic_regex_creatorIcNS_12regex_
traitsIcNS_16cpp_regex_traitsIcEEEEE16fixup_recursionsEPNS0_14re_syntax_baseE':
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:783: undefined reference to `boost::regex_error::reg
ex_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::regex_constants
::error_type, int)'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:784: undefined reference to `boost::regex_error::rai
se() const'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:783: undefined reference to `boost::regex_error::~re
gex_error()'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:872: undefined reference to `boost::regex_error::reg
ex_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::regex_constants
::error_type, int)'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:873: undefined reference to `boost::regex_error::rai
se() const'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:872: undefined reference to `boost::regex_error::~re
gex_error()'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:783: undefined reference to `boost::regex_error::~re
gex_error()'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:872: undefined reference to `boost::regex_error::~re
gex_error()'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640019basic_regex_creatorIcNS_12regex_
traitsIcNS_16cpp_regex_traitsIcEEEEE16create_startmapsEPNS0_14re_syntax_baseE':
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:938: undefined reference to `boost::regex_error::reg
ex_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::regex_constants
::error_type, int)'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:939: undefined reference to `boost::regex_error::rai
se() const'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:938: undefined reference to `boost::regex_error::~re
gex_error()'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:938: undefined reference to `boost::regex_error::~re
gex_error()'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640019basic_regex_creatorIcNS_12regex_
traitsIcNS_16cpp_regex_traitsIcEEEEE15create_startmapEPNS0_14re_syntax_baseEPhPjh':
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:1139: undefined reference to `boost::regex_error::re
gex_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::regex_constant
s::error_type, int)'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:1140: undefined reference to `boost::regex_error::ra
ise() const'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:1139: undefined reference to `boost::regex_error::~r
egex_error()'
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:1139: undefined reference to `boost::regex_error::~r
egex_error()'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZNK5boost16re_detail_10640031cpp_regex_traits_implementation
IcE12error_stringENS_15regex_constants10error_typeE':
C:/boost/include/boost-1_64/boost/regex/v4/cpp_regex_traits.hpp:447: undefined reference to `boost::re_detail_106400::g
et_default_error_string(boost::regex_constants::error_type)'
C:/boost/include/boost-1_64/boost/regex/v4/cpp_regex_traits.hpp:449: undefined reference to `boost::re_detail_106400::g
et_default_error_string(boost::regex_constants::error_type)'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640019basic_regex_creatorIcNS_12regex_
traitsIcNS_16cpp_regex_traitsIcEEEEE12insert_stateEiNS0_19syntax_element_typeEj':
C:/boost/include/boost-1_64/boost/regex/v4/basic_regex_creator.hpp:320: undefined reference to `boost::re_detail_106400
::raw_storage::insert(unsigned int, unsigned int)'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost12object_cacheINS_16re_detail_10640021cpp_regex_trai
ts_baseIcEENS1_31cpp_regex_traits_implementationIcEEE3getERKS3_j':
C:/boost/include/boost-1_64/boost/regex/pending/object_cache.hpp:66: undefined reference to `boost::scoped_static_mutex
_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
C:/boost/include/boost-1_64/boost/regex/pending/object_cache.hpp:66: undefined reference to `boost::scoped_static_mutex
_lock::~scoped_static_mutex_lock()'
C:/boost/include/boost-1_64/boost/regex/pending/object_cache.hpp:66: undefined reference to `boost::scoped_static_mutex
_lock::~scoped_static_mutex_lock()'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZNK5boost16re_detail_10640031cpp_regex_traits_implementation
IcE18lookup_collatenameEPKcS4_':
C:/boost/include/boost-1_64/boost/regex/v4/cpp_regex_traits.hpp:680: undefined reference to `boost::re_detail_106400::l
ookup_default_collate_name(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16re_detail_10640031cpp_regex_traits_implementationI
cE4initEv':
C:/boost/include/boost-1_64/boost/regex/v4/cpp_regex_traits.hpp:721: undefined reference to `boost::re_detail_106400::r
aise_runtime_error(std::runtime_error const&)'
C:/boost/include/boost-1_64/boost/regex/v4/cpp_regex_traits.hpp:736: undefined reference to `boost::re_detail_106400::g
et_default_error_string(boost::regex_constants::error_type)'
C:\Users\dj_al\AppData\Local\Temp\cctBnhDJ.o: In function `ZN5boost16cpp_regex_traitsIcE16get_catalog_nameEv':
C:/boost/include/boost-1_64/boost/regex/v4/cpp_regex_traits.hpp:1117: undefined reference to `boost::scoped_static_mute
x_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
C:/boost/include/boost-1_64/boost/regex/v4/cpp_regex_traits.hpp:1117: undefined reference to `boost::scoped_static_mute
x_lock::~scoped_static_mutex_lock()'
C:/boost/include/boost-1_64/boost/regex/v4/cpp_regex_traits.hpp:1117: undefined reference to `boost::scoped_static_mute
x_lock::~scoped_static_mutex_lock()'
collect2.exe: error: ld returned 1 exit status

2 个答案:

答案 0 :(得分:0)

如果def forwards(apps, schema_editor): if not schema_editor.connection.vendor.startswith('postgres'): logger.info('Database vendor: {}'.format(schema_editor.connection.vendor)) logger.info('Skipping migration without attempting to ADD CONSTRAINT') return schema_editor.execute('ALTER TABLE my_table ADD CONSTRAINT my_constraint (my_field != \'NaN\';)') def backwards(apps, schema_editor): if not schema_editor.connection.vendor.startswith('postgres'): logger.info('Database vendor: {}'.format(schema_editor.connection.vendor)) logger.info('Skipping migration without attempting to DROP CONSTRAINT') return schema_editor.execute('ALTER TABLE my_table DROP CONSTRAINT my_constraint;') class Migration(migrations.Migration): dependencies = [ ... ] operations = [ migrations.RunPython(forwards, backwards, atomic=True) ] 是您安装Boost的地方(即解压缩源包),那么您应该添加到包含目录的路径,而不是C:\boost\include\boost-1_64。尾随C:\boost\include\boost-1_64\boost目录存在于代码中的boost指令中。

如果您正在使用图形IDE,我希望它在保存项目时根据需要自动执行转义反斜杠(&#39; \#39;)字符。否则你可能不得不手动转义它们。

答案 1 :(得分:0)

Andrey Semashev所述,请确保使用Boost的安装位置,而不要使用解压缩的源位置。如果您在安装Boost时没有选择安装前缀,则为标准设置,在Windows上为C:\ Boost。

对我来说,在Visual Studio Code中,我唯一需要做的就是打开项目的task.json并在以下几行中进行如下操作:

“参数”:[
“ -I”,
“ C:/ Boost / include / boost-1_73” ]

这将创建一个包含boost目录的编译器参数。然后,在文件中,您应该可以包含Boost,例如以下示例:#include

在整个task.json文件下面:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
            "args": [
                "-g",
                "${workspaceFolder}\\*.cpp",
                "-o",
                "${fileDirname}\\myProgram.exe",
                "-I",
                "C:/Boost/include/boost-1_73"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}