Advertisement

Trouble building using msvc in Visual Studio Code

Started by September 15, 2019 11:37 AM
3 comments, last by Plush 5 years ago

tasks.json


{
  "version": "2.0.0",
  "echoCommand": true,
  "tasks": [
    {
      "label": "build",
      "type": "process",
      "command": "cmd",
      "args": [
        "/C %vcvarsall% && cl /Od /Zi /EHsc /Fd:%out%/vc141.pdb /Fo:%out%/%name%.obj ./%src%/*.cpp /link /OUT:%out%/%name%.%ext% /PDB:%out%/%name%.pdb",
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ],
  "options": {
    "env": {
      "src": "src",
      "out": "bin",
      "name": "test",
      "ext": "exe",
      "vcvarsall": "D:/MSVS/BuildTools/VC/Auxiliary/Build/vcvarsall.bat x64",
    }
  }
}

The terminal process terminated with exit code: 2

Windows Error Code 2 means "file not found", make sure you've got the correct paths.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Advertisement

Fixed

tasks.json


{
  "version": "2.0.0",
  "echoCommand": true,
  "tasks": [
    {
      "label": "build",
      "type": "process",
      "command": "cmd",
      "args": ["/C %vcvarsall% && cl /Od /EHsc /Zi /Fd:%buildPath%/vc141.pdb /Fo:%buildPath%/test.obj ./%sourcePath%/main.cpp /link /OUT:%buildPath%/test.exe /PDB:%buildPath%/test.pdb"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": "$msCompile"
    }
  ],
  "options": {
    "env": {
      "sourcePath": "source",
      "buildPath": "build",
      "vcvarsall": "D:/MSVS/BuildTools/VC/Auxiliary/Build/vcvarsall.bat x64"
    }
  }
}

output:


test.obj : error LNK2019: unresolved external symbol "public: void __cdecl test::a(void)" (?a@test@@QEAAXXZ) referenced in function main
test.obj : error LNK2001: unresolved external symbol "class test t" (?t@@3Vtest@@A)
build\test.exe : fatal error LNK1120: 2 unresolved externals
The terminal process terminated with exit code: 2

main.cpp


#include "test.h"

int main()
{
	t.a();

	return 0;
}

test.cpp


#include "test.h"

test t;

void test::a()
{

}

test.h


#ifndef TEST_H
#define TEST_H

class test
{
	public:
		void a();
};

extern test t;

#endif

 

Do I have to add each .cpp file to the args? Wouldn't that be impossible to manage in a big project?

This topic is closed to new replies.

Advertisement