1

I am having some troubles compiling c++ programs in VS code. I followed this answer: How do I set up Visual Studio Code to compile C++ code?

and my Makefile is

CC=g++
CFLAGS=-Wall
.SUFFIXES = .cpp
objs:=$(wildcard *.cpp)
targets:=$(objs:.cpp= )

.PHONY:all
all: $(targets)
.cpp:
    $(CC) $(CFLAGS) -std=c++11 -o $@ $< 

I just want to compile this file which is opened in current window, say 1.cpp and this file does not have any external dependencies

When i try to compile my file (by pressing f8 as given in the answer i linked) i get the following error:

'make' is not recognized as an internal or external command,
operable program or batch file.

I am a beginner, and don't know much about Makefile , any help will be appreciated. Thanks!
Edit: I am using Windows subsystem for linux to compile my programs not mingw or cygwin.

Edit:
Now i can use make but i think something is wrong with my Makefile. enter image description here

kayush
  • 111
  • 7
  • You may have to install make itself –  May 16 '18 at 12:42
  • @JETM I have make installed (please see this: https://stackoverflow.com/questions/11934997/how-to-install-make-in-ubuntu) – kayush May 16 '18 at 12:45
  • I am using windows subsystem for linux(bash) as terminal to compile my programs – kayush May 16 '18 at 12:46
  • Then the issue is that VSCode isn't looking for make in the right place. I don't know more than that, but maybe this clue can help you search. –  May 16 '18 at 12:53
  • @JETM when i type make in my terminal in vscode, it shows make: nothing to be found for 'all' so i think make command not found is not the case here. Can you check if i am not making some other mistake here – kayush May 16 '18 at 15:42
  • @JETM have a look now, it seems to me that tasks.json is not correct but i can't figure out how to correct this – kayush May 16 '18 at 15:58
  • 2
    `make Makefile` is a very bad command, and may overwrite your makefile. What you want is `make -f Makefile` – Ben Voigt May 16 '18 at 15:59
  • Also, your makefile is horribly wrong, and may overwrite source files, because you've designated them as generated files. Make sure not to test this in your only copy of the code. – Ben Voigt May 16 '18 at 16:00
  • Bottom line, you don't have a Visual Studio Code problem. Get things working when you run `make` at a command-line first, and only then worry about integration with Code. – Ben Voigt May 16 '18 at 16:01

1 Answers1

0

I have figured out a simple way:
args doesn't work some reason at least on my system.

So, change command (line 3 of tasks.json)

"command": "g++ -Wall -std=c++14 ${relativeFile};./a.out < input.txt

And now just one button and compile and run!

kayush
  • 111
  • 7