Vscode-cpptools: Conflict occurs when using unordered_map and cout/cin

Created on 28 Mar 2019  ·  6Comments  ·  Source: microsoft/vscode-cpptools

Type: Debugger
Input information below
Conflict occurs when using unordered_map and cout/cin:
Mingw-w64 runtime failure:
Unknown pseudo relocation protocol version 16777216.

Describe the bug

  • OS and Version: windows10
  • VS Code Version: 1.32.3
  • C/C++ Extension Version:
  • Other extensions you installed (and if the issue persists after disabling them):
  • A clear and concise description of what the bug is.

To Reproduce
Please include a code sample and launch.json configuration.

src:

include

using namespace std;

include

include

include

int main()
{
std::unordered_map mymap;
mymap["Bakery"]="Barbara"; // new element inserted
mymap["Seafood"]="Lisa"; // new element inserted
mymap["Produce"]="John"; // new element inserted
// printf("hello"); //work!!!
//Error occurs such as that:
// Mingw-w64 runtime failure:
// Unknown pseudo relocation protocol version 16777216.
std::cout<<"hello";
return 0;
}

launch.json:
// https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md
{
"version": "0.2.0",
"configurations": [
{

        "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示 
        "type": "cppdbg", // 配置类型,这里只能为cppdbg 
        "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
        "program": "${fileDirname}/${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径 
        "args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可 
        "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,我一般设置为true 
        "cwd": "${workspaceRoot}", // 调试程序时的工作目录
        "environment": [], // (环境变量?)
        "externalConsole": false, // 调试时是否显示控制台窗口,一般设置为true显示控制台
        "MIMode": "gdb", // 指定连接的调试器,可以为gdb或lldb。但目前lldb在windows下没有预编译好的版本。
        "miDebuggerPath": "C:\\Program Files\\LLVM\\bin\\gdb.exe", // 调试器路径。 
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": false
            }
        ],
        "preLaunchTask": "Compile"// 调试会话开始前执行的任务,一般为编译程序。与tasks.json的taskName相对应 ,

        // "preLaunchTask": "Compile" ,// 调试会话开始前执行的任务,一般为编译程序。与tasks.json的taskName相对应 ,
        // "logging": { "engineLogging": true, "trace": true, "traceResponse": true } 
    }
]

}
Additional context
If applicable, please include logging by adding "logging": { "engineLogging": true, "trace": true, "traceResponse": true } in your launch.json
Add any other context about the problem here including log or error messages in your Debug Console or Output windows.

Nothing!

more info needed

Most helpful comment

I seem to find the way to solve the problem,and the debugger and runner work:
Modify the settings.json(by remove --target=x86_64-w64-mingw )
// "code-runner.executorMap": {
// "c": "cd $dir && clang $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics --target=x86_64-w64-mingw -std=c11 && $dir$fileNameWithoutExt",
// "cpp": "cd $dir && clang++ $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics --target=x86_64-w64-mingw -std=c++1z && $dir$fileNameWithoutExt"
// },
"code-runner.executorMap": {
"c": "cd $dir && clang $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics -std=c11 && $dir$fileNameWithoutExt",
"cpp": "cd $dir && clang++ $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics -std=c++1z && $dir$fileNameWithoutExt"
},
Modify the task.json(by remove --target=x86_64-w64-mingw ):
"command": "clang++", // 如果用MinGW,编译C用gcc,编译c++用g++
"args": [
"${file}",
"-o", // 指定输出文件名,不加该参数则默认输出a.exe
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-g", // 生成和调试有关的信息
"-Wall", // 开启额外警告
"-static-libgcc", // 静态链接
"-fcolor-diagnostics",
// "--target=x86_64-w64-mingw", // 默认target为msvc,不加这一条就会找不到头文件
"-std=c++1z" // c++1z即c++17,C语言最新标准为c11,或根据自己的需要进行修改
], // 编译命令参数

All 6 comments

Is this a bug with MinGW or do you think our extension has a bug?

Thanks for your reply!
I try to compile the same code with CMD(windows):
clang++ test.cpp -o test.exe
And I run the exe. It worked !
So. I think there has a bug in VSCODE or extension.

When you run it via VS Code, it goes through the debugger (and doesn't just run the executable(. You may need to add "-g" to your args setting in order for the debugger to work. Or it could be some other debugger issue @WardenGnaw .

I try to run the gdb debugger . And I cat logs such as that(It run normally):
PS K:\01-Projects\01-C++\01-Codes\Algo\src> clang++ -g .\huya.cpp -o .\huya.exe
huya-6ca7d9.o : warning LNK4217: 本地定义的符号 __std_terminate 在函数 "int public: __cdecl std::vector<int,class std::allocator<int> >::vector<int,class std::allocator<int> >(void)'::1'::dtor$2" (?dtor$2@?0???0?$vector@HV?$allocator@H@std@@@std@@QEAA@XZ@4HA) 中导入
huya-6ca7d9.o : warning LNK4217: 本地定义的符号 _CxxThrowException 在函数 "int private: void __cdecl std::vector<class std::_List_unchecked_iterator<class std::_List_val<struct std::_List_simple_types<struct std::pair<int const ,class std::vector<int,class std::allocator<int> > > > > >,class std::allocator<class std::_List_unchecked_iterator<class std::_List_val<struct std::_List_simple_types<struct std::pair<int const ,class std::vector<int,class std::allocator<int> > > > > > > >::_Reallocate_exactly(unsigned __int64)'::1'::catch$1" (?catch$1@?0??_Reallocate_exactly@?$vector@V?$_List_unchecked_iterator@V?$_List_val@U?$_List_simple_types@U?$pair@$$CBHV?$vector@HV?$allocator@H@std@@@std@@@std@@@std@@@std@@@std@@V?$allocator@V?$_List_unchecked_iterator@V?$_List_val@U?$_List_simple_types@U?$pair@$$CBHV?$vector@HV?$allocator@H@std@@@std@@@std@@@std@@@std@@@std@@@2@@std@@AEAAX_K@Z@4HA) 中导入
PS K:\01-Projects\01-C++\01-Codes\Algo\src> gdb huya.exe
GNU gdb (GDB) 8.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from huya.exe...(no debugging symbols found)...done.
(gdb) run
Starting program: K:\01-Projects\01-C++\01-Codes\Algo\src\huya.exe
[New Thread 4632.0x414c]
[New Thread 4632.0x3514]
[New Thread 4632.0x39f8]
[New Thread 4632.0x41d4]
[New Thread 4632.0x2f04]
hello
1
[Thread 4632.0x3514 exited with code 0]
[Thread 4632.0x41d4 exited with code 0]
[Thread 4632.0x39f8 exited with code 0]
[Thread 4632.0x2f04 exited with code 0]
[Inferior 1 (process 4632) exited normally]
(gdb)

I seem to find the way to solve the problem,and the debugger and runner work:
Modify the settings.json(by remove --target=x86_64-w64-mingw )
// "code-runner.executorMap": {
// "c": "cd $dir && clang $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics --target=x86_64-w64-mingw -std=c11 && $dir$fileNameWithoutExt",
// "cpp": "cd $dir && clang++ $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics --target=x86_64-w64-mingw -std=c++1z && $dir$fileNameWithoutExt"
// },
"code-runner.executorMap": {
"c": "cd $dir && clang $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics -std=c11 && $dir$fileNameWithoutExt",
"cpp": "cd $dir && clang++ $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics -std=c++1z && $dir$fileNameWithoutExt"
},
Modify the task.json(by remove --target=x86_64-w64-mingw ):
"command": "clang++", // 如果用MinGW,编译C用gcc,编译c++用g++
"args": [
"${file}",
"-o", // 指定输出文件名,不加该参数则默认输出a.exe
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-g", // 生成和调试有关的信息
"-Wall", // 开启额外警告
"-static-libgcc", // 静态链接
"-fcolor-diagnostics",
// "--target=x86_64-w64-mingw", // 默认target为msvc,不加这一条就会找不到头文件
"-std=c++1z" // c++1z即c++17,C语言最新标准为c11,或根据自己的需要进行修改
], // 编译命令参数

Thank you, I solve my problem following your instructions, although I don't why it works.

Was this page helpful?
0 / 5 - 0 ratings