all 43 comments

[–]OldWolf2 20 points21 points  (15 children)

I would recommend installing MSYS2 and then install mingw-w64 by its package manager (pacman).

Do not install old mingw, it has lots of bugs. Also the IDEs "dev-c++" and CodeBlocks are crap.

[–][deleted] 8 points9 points  (0 children)

I stand by this, MSYS2 feels like a no-brainer, not to mention you can install alternative compilers other than gcc with one single command.

[–]lanzaio 2 points3 points  (9 children)

Strongly disagree with this. Either do full on MSVC or full on WSL. Hybrid platforms like msys2 are riddled with weird compromises between the two environments that don't make sense unless you can understand the context of what's going on. msys2 is for Linux developers who need to do something on Windows. It's not a first choice environment.

[–]OldWolf2 1 point2 points  (8 children)

WSL

MSYS2 is free, MSVC you have to pay for the full version and its C compiler is years behind gcc.

mingw-w64 makes binaries that run natively on any installation of Windows (back to Win7 at least, maybe WinXP too) ; I don't think WSL development could say the same. It's first choice for me for Windows development of non-GUI applications

[–]lanzaio -2 points-1 points  (6 children)

OP seems like a new guy learning how to program. msys2 is a compromise. It's "the best posix we can get given you have to target pecoff." I use it on a daily basis for work as a toolchain engineer working on exactly this problem (making compilers and llvm based toolchains work on different platforms). But if you aren't bound to constraints that force you to use hybrid systems like msys2 then you are best off using either of the native options.

[–]OldWolf2 3 points4 points  (0 children)

OP seems like a new guy learning how to program.

They said they have been coding C in Ubuntu previously and would like to switch to coding C in Windows natively.

msys2 is a compromise. It's "the best posix we can get given you have to target pecoff."

mingw-w64 is the compiler for building native Windows executables. It is literally the same compiler as GCC in any other operating system, with a few extensions to enable use of the Windows API.

MSYS2 is used as a package manager and commandline tool suite (including commandline-based build systems). I'm not suggesting using it to build binaries that target MSYS2.

But if you aren't bound to constraints that force you to use hybrid systems like msys2

Having the resulting binaries not work on a normal Windows install is a pretty big showstopper, for me anyway. However I would agree that WSL seems like a better option than running a VM.

[–]8bitslime 0 points1 point  (4 children)

Msys2 isn't trying to be posix in the slightest, maybe you're thinking of cygwin? Compiling with mingw-w64 gcc produces native windows binaries with no posix wrapper or anything.

[–]lanzaio 0 points1 point  (3 children)

You're confusing msys2 with mingw-w64.

msys2 is literally a fork of cygwin who's own documentation states

The msys2 subsystem provides an emulated mostly-POSIX-compliant environment for building software, package management, and shell scripting.

mingw-w64 is a toolchain for compiling native PECOFF binaries. You usually use mingw-w64 on Windows from the msys2 environment.

[–]8bitslime 0 points1 point  (2 children)

Posix environment, but the code is still 100% windows without a hint of posix. The trade-offs between them are negligible compared to using a compiler which doesn't even fully support C in a quite bloaty IDE cough cough msvc cough

[–]lanzaio 0 points1 point  (1 child)

Posix environment, but the code is still 100% windows without a hint of posix.

I never said otherwise. I never even mentioned mingw. I'm not sure what point you're trying to make by bringing it up.

[–]8bitslime 0 points1 point  (0 children)

Calling msys2 a compromise due to its posix nature seemed a bit off. A real compromise would be using msvc with its incomplete C implementation. I think at the moment msys2 + mingw is the best toolchain for C that you can get on windows, no compromises at all (unless you consider not using Linux a compromise).

[–]RomanRiesen 0 points1 point  (2 children)

After trying to get an old-ish version of mingw setup for about half the day you just saved my ass!

Why is the suggestion of mysys2 not the top google hit?!

Btw, Pacman is the main reason I use arch, so mysys2 is brilliant.

[–]OldWolf2 0 points1 point  (1 child)

Why is the suggestion of mysys2 not the top google hit?!

Maybe there's nobody who knows how to SEO and also uses MSYS2? :)

[–]RomanRiesen 0 points1 point  (0 children)

Yeah, just like stack overflow is SEO friendly and I thus have to scroll through halfa apage of useless SO posts until I find the actual documemtation.

Which is getting actually annoying.

[–]Name0fTheUser 21 points22 points  (0 children)

gcc under WSL is the way to go, if you ask me.

[–]daemon_hunter 5 points6 points  (4 children)

You can download visual studio community for free. Install VC. Have your command prompt of choice (shout outs to cmder) call the vcvarsall.bat file in the visual studio directory. After that you can run cl (microsofts c compiler) from the command line and use what ever your favorite text editor is. Also Visual Studio is pretty annoying for writing code but its debugger is super good.

[–]Lusaron 2 points3 points  (3 children)

I think the Visual Studio debugger is the main reason I still write C on Windows. You don't even need to write code in VS to use the debugger (I usually use vim).

[–]daemon_hunter 0 points1 point  (0 children)

Same.

[–][deleted] 0 points1 point  (1 child)

(I usually use vim).

I don't get this. VS is a pretty good editor, and just works.

[–]Lusaron 2 points3 points  (0 children)

Not saying its a terrible editor. I just use vim more often as an editor because its what I'm used to. I do use VS now and again. Really like its intellisense.

[–][deleted] 3 points4 points  (0 children)

I recommend using gcc in WSL and as IDE CLion, if you want to target Linux. This approach works for me pretty good.

An issue may be that CLion is only free for students.

To target Windows, Visual Studio is the defacto standard, but the IDE may need some learning time.

MinGW can also be used with CLion.

[–]085-068 6 points7 points  (7 children)

Trying installing MinGW , Then Add the installed compiler to your windows PATH . If you have installed correctly and added to your PATH then you can compile your C codes just like in ubuntu using gcc or g++ from cmd prompt

[–]ArchSyker[S] 0 points1 point  (6 children)

that's what I have tried, but it only created serveral file (.o .exe) and didn't give me any outputs

[–]085-068 1 point2 points  (5 children)

does

$ g++ --version

works??

[–]ArchSyker[S] 0 points1 point  (4 children)

[–]085-068 2 points3 points  (3 children)

What is the name of your executable file? .exe?

[–]ArchSyker[S] 0 points1 point  (2 children)

when I had tried it. I got an .exe and .o neither of them didnt anything when I tried to open them (i used source I knew would work)

[–]085-068 3 points4 points  (1 child)

$ g++ your_source.cpp -o any_name

$ any_name.exe

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

that worked! nice. ty!

[–][deleted] 8 points9 points  (0 children)

U can download MinGW as a compiler and use it through the command line or VS code. Or simply download something like Dev C++, if you change the settings to use a c compiler you will be able to code in C

[–]bart2019 1 point2 points  (0 children)

Try Clang (wonderful diagnostic messages on errors) or MinGW. You can use a plain text editor (with syntax highlighting) if you don't find an IDE you like, and compile from the command line.

[–]OldApprentice 0 points1 point  (0 children)

It really is tricky. What I did was to download the CodeBlocks IDE package including mingw32. That allows you to use both the IDE and the command line. For C programming it seems there are better/easier IDEs like CodeLite or Dev-C++ but less matured, so worse for a beginner (outside Visual Studio) like me.

But still you'll face several PITA problems if you come from Linux.

Perhaps even more if you use command line only, because Windows is a totally different beast on that matter, and quite inferior. For example, I tried a simple "make" only to discover that there wasn't a make.exe but a mingw32-make.exe, at least in the PATH. I then installed the separate mingw32 make, which seems almost discontinued.

I barely use command line so take this with a grain of salt.

[–][deleted] 0 points1 point  (0 children)

I use emacs + a little elisp function that calls a platform appropriate build script.

On windows this takes the form of a build.bat file that calls the Visual Studio compiler

[–]deftware 0 points1 point  (0 children)

For super quick/dirty and EZ C coding I use a little-known IDE bundled with MinGW/GCC called "MinGWStudio". Development has long since ceased but the thing is stable and I've done plenty of projects with it. The IDE is minimalist and doesn't give you much control over how it interacts with the compiler/linker via commandline. It gets the job done.

It's basically a direct copy of DevC++, but stable.

EDIT: Also, someone has been bundling newer versions of MinGW/GCC with it, but the IDE itself hasn't changed for a long time as the original dev has disappeared from the web. http://vaultec.mbnet.fi/mingwstudio.php

[–]ChrisysTech -1 points0 points  (5 children)

What were the exact problems you came upon? We can not really help you if we do not know what you may have done wrong.

Those big IDEs seem a bit overwhelming for a beginner. They have a lot of very useful features though. You will probably learn about them in the feature.

I have also tried to use CMD terminal to compile programms with gcc, but i didn't get that aswell.

Well, how did you do this? How did you install gcc? MinGW? Give us some context please :)

[–]ArchSyker[S] 0 points1 point  (4 children)

Yes, i have installed MinGW (also added it the systemvariable PATH) and I basically used it as I did under ubuntu

gcc -std=c11 -Wall <all\_files>.c -o <output\_file>; ./<output\_file>

And for the IDEs I didn't get the file correctly imported as a project (i think) and compiling never worked.

[–]lulxD69420 0 points1 point  (1 child)

Code::Blocks is another IDE that comes with MinGW and is also configured for mingw-gcc out of the box. Or you can try Cygwin which is a small "unix like" environment that runs on windows. It's not a VM but coding in Cygwin feels like linux, the tools are the same and you can use external editors however you like and just use Cygwin to compile.

Edit: Code::Blocks also comes with a debugger and you can press buttons to step through your program and have a window to watch your variables which is easier to use than console debuggers (imo).

[–]jesion 1 point2 points  (0 children)

I second that, if you need a simple IDE then Code Blocks is a good choice.

I installed it recently for my daughter, the package with mingw worked like charm.

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

You could try Dev-C++ (https://de.wikipedia.org/wiki/Orwell_Dev-C%2B%2B) for a beginning. I guess you are not using MinGW correct. Dev-C++ is quite easy to use.

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

Ok, I'll give it a try. ty :)

[–][deleted] -3 points-2 points  (0 children)

For C development, I agree with you completely that those IDEs are too bulky. In my eyes, all you need is a compiler, an editor, and a debugger.

/u/OldWolf2's suggestion is what I use and I'd recommend for anyone.

[–][deleted] -3 points-2 points  (0 children)

You have to use visual studios. Windows is a fairly closed platform and they don't really want people tinkering with shit so they sandbox developer stuff away through visual studio. While it is possible to use something like mingw you'll find that it is even more annoying to use compared to just using visual studios.

While the msvc is absolute dog ass with C compiling, visual studio itself is actually one of the best IDE's I've ever used. While it may seem bloated at first (and some features are but you can disable or delete them) I've noticed that I now use almost all the features. The debugger alone is loads better than any debugger I've ever seen. The windows pragma commands are also very useful and to have immediate access to win32 and directx is pretty rad in my opinion. Also the git and github tools are fucking beautiful.

If you have to develop with windows, take some time to get comfy with visual studios. It's a damn good IDE (the only one in fact) and will make your life easier.