2021年2月4日星期四

How to include other c++ header file in vscode?

My workspace is :

.  ├── include  │   ├── simdjson.cpp  │   └── simdjson.h  ├── src  │   ├── parse_json.cpp  │   └── twitter.json  └── third_party  

My parse_json.cpp is

#include "simdjson.h"  int main(void)  {      simdjson::dom::parser parser;      simdjson::dom::element tweets = parser.load("twitter.json");      std::cout << tweets << std::endl;  }  

My c_cpp_properties.json is

{      "configurations": [          {              "name": "Linux",              "includePath": [                  "${workspaceFolder}",                  "${workspaceFolder}/include"              ],              "defines": [],              "compilerPath": "/usr/bin/gcc",              "cStandard": "gnu17",              "cppStandard": "gnu++14",              "intelliSenseMode": "linux-gcc-x64"          }      ],      "version": 4  }  

It raises error when I press F5 in parse_json.cpp :

Starting build...  /usr/bin/g++ -g /mnt/c/Users/hnjyz/OneDrive/test/src/parse_json.cpp -o /mnt/c/Users/hnjyz/OneDrive/test/src/parse_json  /mnt/c/Users/hnjyz/OneDrive/test/src/parse_json.cpp:1:10: fatal error: simdjson.h: No such file or directory      1 | #include "simdjson.h"        |          ^~~~~~~~~~~~  compilation terminated.  

My tasks.json is:

{      "tasks": [          {              "type": "cppbuild",              "label": "C/C++: g++ build active file",              "command": "/usr/bin/g++",              "args": [                  "-g",                  "${file}",                  "-o",                  "${fileDirname}/${fileBasenameNoExtension}"              ],              "options": {                  "cwd": "${workspaceFolder}"              },              "problemMatcher": [                  "$gcc"              ],              "group": {                  "kind": "build",                  "isDefault": true              },              "detail": "Task generated by Debugger."          }      ],      "version": "2.0.0"  }  

My launch.json is:

{      // Use IntelliSense to learn about possible attributes.      // Hover to view descriptions of existing attributes.      // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387      "version": "0.2.0",      "configurations": [          {              "name": "g++ - Build and debug active file",              "type": "cppdbg",              "request": "launch",              "program": "${fileDirname}/${fileBasenameNoExtension}",              "args": [],              "stopAtEntry": false,              "cwd": "${workspaceFolder}",              "environment": [],              "console": "externalTerminal",              "MIMode": "gdb",              "setupCommands": [                  {                      "description": "Enable pretty-printing for gdb",                      "text": "-enable-pretty-printing",                      "ignoreFailures": true                  }              ],              "preLaunchTask": "C/C++: g++ build active file",              "miDebuggerPath": "/usr/bin/gdb"          }      ]  }  

What should I do ?

Update one: When I change tasks.json to

{      "tasks": [          {              "type": "cppbuild",              "label": "C/C++: g++ build active file",              "command": "/usr/bin/g++",              "args": [                  "-g",                  "${file}",                  "-o",                  "${fileDirname}/${fileBasenameNoExtension}",                  "-I${workspaceFolder}/include"              ],              "options": {                  "cwd": "${workspaceFolder}"              },              "problemMatcher": [                  "$gcc"              ],              "group": {                  "kind": "build",                  "isDefault": true              },              "detail": "Task generated by Debugger."          }      ],      "version": "2.0.0"  }  

It raise a different error :

/usr/bin/g++ -g /mnt/c/Users/hnjyz/OneDrive/test/src/parse_json.cpp -o /mnt/c/Users/hnjyz/OneDrive/test/src/parse_json -I/mnt/c/Users/hnjyz/OneDrive/test/include  /usr/bin/ld: /tmp/ccMAhnvY.o: in function `simdjson::haswell::(anonymous namespace)::numberparsing::parse_float_fallback(unsigned char const*, double*)':  /mnt/c/Users/hnjyz/OneDrive/test/include/simdjson.h:16770: undefined reference to `simdjson::internal::from_chars(char const*)'  /usr/bin/ld: /tmp/ccMAhnvY.o: in function `simdjson::westmere::(anonymous namespace)::numberparsing::parse_float_fallback(unsigned char const*, double*)':  /mnt/c/Users/hnjyz/OneDrive/test/include/simdjson.h:23215: undefined reference to `simdjson::internal::from_chars(char const*)'  /usr/bin/ld: /tmp/ccMAhnvY.o: in function `simdjson::fallback::(anonymous namespace)::numberparsing::parse_float_fallback(unsigned char const*, double*)':  /mnt/c/Users/hnjyz/OneDrive/test/include/simdjson.h:35813: undefined reference to `simdjson::internal::from_chars(char const*)'  /usr/bin/ld: /tmp/ccMAhnvY.o: in function `simdjson::error_message(simdjson::error_code)':  /mnt/c/Users/hnjyz/OneDrive/test/include/simdjson.h:6927: undefined reference to `simdjson::internal::error_codes'  /usr/bin/ld: /tmp/ccMAhnvY.o: in function `simdjson::dom::parser::allocate(unsigned long, unsigned long)':  /mnt/c/Users/hnjyz/OneDrive/test/include/simdjson.h:8140: undefined reference to `simdjson::active_implementation'  /usr/bin/ld: /tmp/ccMAhnvY.o: in function `simdjson::internal::mini_formatter::number(double)':  /mnt/c/Users/hnjyz/OneDrive/test/include/simdjson.h:8416: undefined reference to `simdjson::internal::to_chars(char*, char const*, double)'  collect2: error: ld returned 1 exit status  

......

https://stackoverflow.com/questions/66041888/how-to-include-other-c-header-file-in-vscode February 04, 2021 at 04:28PM

没有评论:

发表评论