2

g++ can't find boost/regex.hpp using this task:

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

I tried also using this arg: "-IC:\\boost\\include\\boost-1_64\\boost"

g++ is installed throug MinGW and i added the bin to PATH enviroment variable

I always used Visual Studio IDE...i'm new to command line stuff

This is how I include path on 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"

                ],

Before this I included only C:\\boost\\include

And this is the error:

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

compilation terminated. How i can resolve this?


UPDATE 1:

So i included both include and lib folder:

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

            ],

and my compilation task is:

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

now i have this output:

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
tuttomax
  • 59
  • 1
  • 1
  • 5
  • Are you sure about `-I\\C:`? Shouldn't that be just `-IC:\boost\\include\\boost-1_64\\boost`? – user0042 Jul 20 '17 at 16:53
  • i correct the path with -IC:\\boost\\include\\boost-1_64\\boost but the result is the same – tuttomax Jul 21 '17 at 07:54
  • `C:\boost\lib` should be in library paths, not include paths. You should also add the libraries to link with. From the compiler output it looks like the library for Boost.Regex is missing. – Andrey Semashev Jul 21 '17 at 16:24
  • VS Code has only includePath and browse.path i don't know if there is something for linking – tuttomax Jul 22 '17 at 07:55

2 Answers2

3

If C:\boost\include\boost-1_64 is where you installed Boost (i.e. unpacked the source package) then that is the path you should add to your include directories, not C:\boost\include\boost-1_64\boost. The trailing boost directory is present in #include directives in the code.

If you're using a graphical IDE I would expect it to automatically perform escaping the backslash ('\') characters as necessary when it saves the project. Otherwise you might have to escape them manually.

Andrey Semashev
  • 10,046
  • 1
  • 17
  • 27
  • I'm not confident with this command line stuff. I installed boost in this way: unpacked on Downloads folder and then run bootstrap gcc and b2 --prefix=C:\boost --toolset=gcc install so i have include and libs folder in C:\boost – tuttomax Jul 21 '17 at 08:32
  • `b2 --prefix=C:\boost install` puts headers into `C:\boost\include` and built libraries into `C:\boost\lib`, so those are the paths you should add to your include and library paths. – Andrey Semashev Jul 21 '17 at 08:40
  • Also, you can surely see where files are installed in the filesystem explorer. – Andrey Semashev Jul 21 '17 at 08:45
3

As Andrey Semashev said be sure to use the install location of Boost and not the unpacked source location. Standard if you haven't chosen a install prefix while installing Boost this would be C:\Boost on Windows.

For me in Visual Studio Code the only thing i needed to do is open the task.json of my project and at the following lines as followed:

"args":[
"-I",
"C:/Boost/include/boost-1_73" ]

This creates an compiler argument which includes the directory of boost. Then inside the file you should be able to include Boost as following example: #include <boost/lexical_cast.hpp>.

Below the whole tasks.json file:

{
    "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
            }
        }
    ]
}
Ruben Helsloot
  • 12,582
  • 6
  • 26
  • 49
  • 1
    The `"-I", "C:/Boost/include/boost-1_73"` args in `taks.json` solves my question. – Peng Oct 06 '22 at 16:26