I'm getting the following message trying to compile some simple code: MSB6006 "CL.exe" exited with code 2
.
I'm trying to learn C++. I know some C. I understand the two are completely different languages. I include both tags because I get different results depending on how I try to compile the code.
For my own education, I'm trying to write a lexer. Mainly the problem seems to be with this function:
word scan(char** source)
{
word w;
w.lexeme[0] = '\0';
return w;
}
I get the same problem as this one MSB6006: "CL.exe" exited with code 2 but the answer doesn't apply in my case. I saw this question error MSB6006: "CL.exe" exited with code 2 which pointed to this question on the MSDN site They seem to indicate that small problems can cause this error code.
I have two files. One is a "driver" and the other is the lexer code. But I get the exact same results if I include everything in one file.
Here is the code for the driver:
#include "pch.h"
#include "Cl2aDLL.h"
void Cl2a(char argv1[], char argv2[])
{
char** source = NULL;
scan(source);
}
Here is the code for the header. I got the technique somewhere from a MSFT website:
#pragma once
#ifndef CL2ADLL__H__
#define CL2ADLL__H__
typedef struct {
char* lexeme;
}word;
#ifdef __cplusplus
extern "C" {
#endif
#ifdef CL2ADLL_EXPORTS
#define CL2ADLL_API __declspec(dllexport)
#else
#define CL2ADLL_API __declspec(dllimport)
#endif
CL2ADLL_API void Cl2a(char argv1[], char argv2[]);
word scan(char** source);
#ifdef __cplusplus
}
#endif
#endif // ! CL2ADLL__H__
Here is the code for the lexer:
// Error MSB6006 "CL.exe" exited with code 2.
#include "pch.h"
#include "Cl2aDLL.h"
/*
// when I comment out the following lines, it compiles and runs okay
word scan(char** source)
{
word w;
w.lexeme[0] = '\0';
return w;
}
*/
// if I only have the following, I get compile error if .cpp
word scan(char** source)
{
}
The strange thing is that if I compile as C code it compiles and runs okay. But if I try to compile as C++ I get the error message. If I uncomment out the first version of the scanner, I get the error message compiling as C or C++ either one.
Does anyone know of a change that can remove this error message?
Sorry for the long question, but I'm trying to give as clear a definition of the problem as I can. Because I can't figure out what could be wrong. TIA.
Update: I'm using VS 2019 Community Edition 16.1.1
Update 2: I got the same results with version 16.1.2. But trying the code in VS2017 Community Edition 15.9.12 showed the problem, as shown below.
Also I should have explained that all the above code was in a .dll file. The .dll code was run from a simple console application as follows:
#include "..\CL2aDLL\CL2aDLL.h"
int main(int argc, char* argv[])
{
char parm1[1 + 1] = "";
char parm2[1 + 1] = "";
if (argc == 1) {
Cl2aDLL(parm1, parm2);
}
else {
Cl2aDLL(argv[1], argv[2]);
}
return 0;
}