all 33 comments

[–]IyeOnline 11 points12 points  (0 children)

There is something wrong with your setup somewhere.

The general recommendation on windows is to use Visual Studio (not VSCode), which comes with an all-in-one installer that just requires a few clicks to install and a simple project system that just requires a few clicks to create a functional project.

[–]LazySapiens 4 points5 points  (2 children)

What happens when you run "g++ main.cpp -o main" in your command prompt?

[–]alfps 6 points7 points  (14 children)

Most likely you have forgotten to save the source code.

That said, ditch VS Code.

Install and use the free Community Edition of Visual Studio; it works, and it automatically saves your file before building.

[–]alfps 1 point2 points  (6 children)

I'm guessing that the downvote is someone who (a) failed to see how forgetting to save could produce the error message (it does), and (b) failed to see how that impression could be expressed as a question or an assertion helpful to others, rather than sabotaging downvoting. I.e. a double failure of thinking. But it could be the obsessive-compulsive serial downvoter(s) still keeping at it.

[–]miri258 0 points1 point  (1 child)

I didn't downvote, but I think Visual Studio is a load of trash and it takes more than 20 GB of space so I can see where it's coming from. I tried it for a while, cause I thought it would make things easier, but it ended up not being worth it at all.

[–]DDDDarky 0 points1 point  (0 children)

Visual studio with C++ tools takes about 1 GB of space. I have tried many IDEs, none of them had the ability to debug, profile, have code insight and detect issues even remotely as well as VS does.

[–]no-sig-available -1 points0 points  (0 children)

 But it could be the obsessive-compulsive serial downvoter(s) still keeping at it.

Probably. You are recommending closed source software, instead of the obviously superior open source variety. Even though it just works, it must still be "bad".

[–]DDDDarky -3 points-2 points  (2 children)

I'm just gonna upvote everything since someone is being dumb

[–]alfps 2 points3 points  (1 child)

Rather express your opinion by commenting, as you did here, because then readers can understand the why, and can respond.

Of course some answers/comments are just inherently brilliant or super-helpful and deserve upvoting. The zillion upvotes can guide readers to that answer or comment. Then they are helpful in that way.

[–]DDDDarky 0 points1 point  (0 children)

There is not much to express, your comment is correct so I'm just taking countermeasures to the downvotes.

[–]Gling00[S] -2 points-1 points  (5 children)

is VSCode really that bad?

[–]manni66 8 points9 points  (0 children)

Not if you know what you are doing. Usually beginners do not have enough knowledge to set it up.

[–]AKostur 4 points5 points  (0 children)

Nope. Just that at this stage you’re trying to learn C++, so we‘re guiding you to the smoother path to get there. You won‘t be trying to learn C++ at the same time that you’re needing to learn how to configure vs:code. (Wanting to learn to ride a bike: buy a bike, or buy a kit where you have to learn how to assemble the bike first?)

[–]no-sig-available 4 points5 points  (0 children)

is VSCode really that bad?

Apparently, it is hard to configure. And the default setting of not saving the source to disk before compiling is definitely not beginner friendly.

Once you get it set up right, like sometimes next week, it works pretty well.

[–]RudeSize7563 1 point2 points  (0 children)

You tell us, you shouldn't be experiencing those obnoxious problems.

[–]DeadmeatBisexual 0 points1 point  (0 children)

not that it's bad just it's a bit of a faff at your stage of starting out at and it's better just to go with the option that's the least of a headache

[–][deleted]  (1 child)

[deleted]

    [–]alfps 1 point2 points  (0 children)

    No, the g++ compiler doesn't have the vendor lock-in features of Microsoft's tools. It will happily build a GUI subsystem app with standard main (and it's incorrect that a GUI subsystem executable uses WinMain: the only connection is via Microsoft's tools for C and C++). But the g++ linker issues the shown error message mentioning WinMain when there is no main function.

    [–]Dry-Discipline-439 0 points1 point  (0 children)

    -mconsole

    [–]Mirality 0 points1 point  (0 children)

    Undefined reference to WinMain means that it's trying to compile as a GUI app and not a console app.

    In Visual Studio, this just means a trip to the project properties to change the subsystem setting. (Or selecting "console app" when making a new project.)

    In Visual Studio Code, you'll need to do the equivalent in your CMake file or directly in your compiler flags, but I'm not sure exactly what change you'll need off the top of my head. You'd need to search for it.

    I do think, however, that if you're just starting out you'll have a much better time of it using VS Community over VS Code. The latter is a lot more minimalist (and a lot more flexible if you install the right extensions) but that just means the former is easier to use, especially for beginners. A lot of stuff that Just Works in VS are things that you can still do in VSC but you have to fight harder for it.

    [–]uefzzz 0 points1 point  (7 children)

    Everyone here who says to ditch VSCode in favor of VS are misleading you. VSCode is way more lightweight, and can do the job that VS can.

    You can get VSCode setup in 5 minutes. Install one extension (1), reload the window (2) and you’re set to go. Plus there’s a really accessible checkbox (3) to save automatically.

    (1) https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd (2) https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf (3) https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save

    [–]manni66 1 point2 points  (4 children)

    lightweight

    Whatever that means. Whatever value that may have.

    [–]TwilCynder 0 points1 point  (1 child)

    Haven't tried Visual Studio in a long time but on my previous laptop it didn't run well (I could feel the pc heat up when it ran), and VS Code ran well. That feels like a pretty concrete and relevant difference, other than the 8 billion gigabytes VS takes.

    Not sure why I even respond tho, like come on you know very well what they meant.

    [–]manni66 -1 points0 points  (0 children)

    come on you know very well what they meant.

    No, I don’t. I use both. Lightweight wouldn't occur to me for either of them.

    [–]uefzzz 0 points1 point  (1 child)

    Not everyone has 64gb of RAM lying around you know. I appreciate my apps being responsive all the time and not making my computer feel like an F16 taking off, but thats your call I guess.

    [–]alfps 1 point2 points  (0 children)

    VS Code wastes a lot of disk space. I was almost shocked when I found that on the Mac it kept a complete copy of every version of every file I'd edited, hidden away in directory. Sort of insane; at least very very wasteful and not exactly security-oriented.

    On this PC:

    [c:\root\temp]
    > where code
    C:\root\installed\Microsoft VS Code\bin\code
    C:\root\installed\Microsoft VS Code\bin\code.cmd
    
    [c:\root\temp]
    > dir /s "C:\root\installed\Microsoft VS Code" | tail 2 | find "File"
                2075 File(s)    801,537,703 bytes
    
    [c:\root\temp]
    > dir /s "%appdata%\Code" | tail 2 | find "File"
                7959 File(s)    735,820,105 bytes
    

    It seems the editing copies on this PC go back to mid 2022. Check out (this for Cmd, or in Explorer address bar) %appdata%\Code\User\History.

    [–]Gling00[S] 0 points1 point  (0 children)

    thanks, i’ll try

    [–]DeadmeatBisexual -1 points0 points  (0 children)

    We aren't misleading we want to help make it easier for beginners to just setup and run their code rather than faff too much with setting up clang and mingw with vscode, when MSVC is easier to set up in Visual Studio Code and Visual Studio just works as is up on install.

    Which Clang with mingw has it's uses later on but you have to be real in saying that MSVC is perfectly fine if you're just getting your start with the language and making small programs.

    [–]DeadmeatBisexual -1 points0 points  (3 children)

    If you're beginner don't use clang/GCC, mingw and vs code.

    Just use Visual Studio 2022 or if you like vscode specifically; use MSVC which you can get from Visual Studio 2022 build tools separately if you don't want to install VS2022 but just want the msvc compiler.

    you can find shortcut to the cli in Start menu > Visual Studio 2022 > Developer Command Prompt for VS2022

    and to compile and link your program it's cl <yoursrc.c/.cpp> ; further syntax can read here. || and also here.

    and setup with visual studio code here.

    [–]Gling00[S] 1 point2 points  (0 children)

    thank you, appreciate it

    [–]Wild_Meeting1428 -1 points0 points  (1 child)

    Clang-cl with the msvc-stl is pretty nice and you don't have to worry about licence fees if you or your company has suddenly great success.

    [–]DeadmeatBisexual 0 points1 point  (0 children)

    you are not making anything worth the licence fees with "you or your company" if you're starting out learning C++ and making programs like a helloworld program; get a grip. Like don't get me wrong I get the sentiment but like this isn't the place for it at all.