Setting up Exercism, Visual Studio Code, and tests locally

I am trying to relearn and visit many language and started with C but encountered issues with setting it up locally. I wanted to do it locally as I think it would be a good habit. I had already installed Visual Studio Code with the extensions C/C++, C/C++ extension pack, Code Runner, and Exercism Integration. I have installed MinGW and MinSYS for my compiler and had installed GnuWin32 for the make file so I can test.

The issue that I have right now is that I am trying to do a test for the 4th exercise in C which is hamming but exercism test command doesn’t work and just gives back error. Any help would really be appreciated as doing things locally felt much better.

I don’t know much about C, however I did the C++ track couple months ago and I also went over your set up process as well, pretty much the same from what you listed.
I think for local testing and running on vscode, you would need an entry point to start your code which is the main() function.

Can you show your code so that we can see it?

You should use fence code blocks, as that will also show language features.

Something like this:

```c
#include "hamming.h"
#include <stdio.h>

int compute(const char *strandA, const char *strandB) {
}
```

This should allow more people to be able to see your code.

#include "hamming.h"
#include <ctype.h>
#include <string.h>

int compute(const char *lhs, const char *rhs){
    int strand = sizeof(lhs);

    return strand;   
}

I have just a basic line there and wanted to test the exercism test if it works but it does not. I just get the following error:
Running tests via make

Compiling tests.out
process_begin: CreateProcess(NULL, cc -std=c99 -g -Wall -Wextra -pedantic -Werror -Wmissing-declarations -DUNITY_SUPPORT_64 -DUNITY_OUTPUT_COLOR test-framework/unity.c ./*.c -o tests.out -lm, …) failed.
make (e=2): The system cannot find the file specified.
make: *** [tests.out] Error 2

Where should I be inserting the main() function? I had to use the given function from exercism to test and if I insert main() and replace it, it gives out errors.
My current code is

#include "hamming.h"
#include <ctype.h>
#include <string.h>

int compute(const char *lhs, const char *rhs){
    int strand = sizeof(lhs);

    return strand;   
}

Did you follow the track docs to install C locally and running tests locally?

I have checked the docs but I am getting an error when trying either exercism test command or make command, the errors are the same. I have already removed TEST_IGNORE() line.

Please show your errors the same way that you would show your code. “Getting an error” is interesting, but not really helpful.

Edit: Saw this from e-mail, and see that I missed the earlier message. It appears that you are getting something like this:

Compiling tests.out
process_begin: CreateProcess(NULL, cc -std=c99 -g -Wall -Wextra -pedantic -Werror -Wmissing-declarations -DUNITY_SUPPORT_64 -DUNITY_OUTPUT_COLOR test-framework/unity.c ./*.c -o tests.out -lm, …) failed.
make (e=2): The system cannot find the file specified.
make: *** [tests.out] Error 2

This suggests that make is not in your path.

Thank you for that. I checked and I do have make on my path so it’s really confusing on why tests won’t work.

I think (im not 100% sure) this could be a testrunner (vscode extension) problem. I remembering having to tweak the config file inside vscode so test runner can choose the correct version of c++ to execute the file correctly.
My advice is bring the question and the error log to chatgpt for it to troubleshoot this, it is surprisingly quite good at these things, also you can try the official discord channel and see if somebody who has set up vscode with c deal with this.

1 Like

This looks like an error from make complaining that make cannot find a file. I would suggest running make in a terminal without vscode first, following the instructions, and see if that solves anything.

If you get the same error, it would be helpful to share the path from which you are running the command along with the exact command run.

1 Like

I was able to fix the issue. The fix was replacing the line on makefile to be @gcc instead of @$(CC).