How can I duplicate my Linux C environment in Windows with CLION? - c

I've been coding (C) directly in my production environment for a casual game I'm hacking together. The environment is:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial
The GCC version I've been using is as followed:
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609
My Windows environment that I want to make my development environment is:
Windows 10 Pro 64-bit, Intel
So, I'm not an expert on duplicating this for gcc or with C. I have CLION, which does support both C and C++, but pretty much everything out there is tailored for C++ or Visual C++ or whatever. I feel a bit outdated, but want to get a working environment so I can actually compile outside of directly in the shell.
As it stands, I use CLION to do everything, but upload the source files to the shell and then compile. I have tried to install CMake with MinGW, but have failed. Any help is much appreciated!

How can I duplicate my Linux C environment in Windows with CLION?
Since you are developing a game, which requires much more than what the standard C11 programming language defines (read n1570) you probably cannot.
The simplest approach is to install Linux on your laptop (perhaps in some VM).
Alternatively, perhaps the fellow members of your game project are all using some particular toolkit which happens to be ported to Windows (e.g. SDL, Qt, etc...). Then you might try using it.
Notice that CLION is not a compiler but an IDE (it uses an external compiler, perhaps GCC disguised as MinGW).
BTW, even on Windows (and of course on Linux also) you can (and probably should, at first) compile on the command line. You might want to use some build automation tool.

Related

using Clang in windows 10 for C/C++

I am currently learning C, taking a CS50 online class via EDX/Harvard. They have us using Clang inside the CS50 IDE/Sandbox which is cloud-based. They haven't explained how to use Clang outside of that tho. Thus I am wondering; How do I setup clang in windows 10 ? as well as for use with VisualStudio Code?
On Windows, Clang is not self-sufficient, and is supposed to be used in combination with an other compiler: either MinGW (GCC) or MSVC. Clang is going to use the standard library (and other libraries/headers) of that compiler, since it doesn't ship with ones of its own.
If you want to use it with MSVC and have it installed, running clang-cl instead of cl should just work.
But since you mentioned VSC, I assume you don't want MSVC. Then...
If you want to use it with MinGW and have it installed, use clang --target=x86_64-w64-windows-gnu instead of gcc, and it should also just work. (That's assuming your MinGW produces 64-bit apps. Replace x86_64 with i686 if it's 32-bit.)
If you don't have MinGW yet, you can get a fresh version from MSYS2. Then you have an option to install their unofficial build of Clang instead of the regular one, which has an advantage of using --target=x86_64-w64-windows-gnu automatically (so you don't have to write it manually), but also takes up considerably more drive space, and used to be a bit unstable for me in the past.
Expanding on HolyBlackCat's answer. The simplest way to get up and running using clang is to download Visual Studio (not code) and choose the following toolsets during its installation-
Select "Desktop development with C++"
Under "Desktop development with C++" also select "C++ clang tools for windows"
Click install and clang will be usable to you through the commandline, just like the CS50 terminal. You usually won't have to worry too much about playing with extra cmdline options other than the ones cs50 has taught you.
To create a C project in VS with clang-
Create an empty C++ project (don't worry it's just named C++ but will work just fine with C - with the C compiler - not C++ compiler)
Go to project properties by right clicking on the project name and clicking properties
Set the platform toolset to LLVM - Clang in the project general config
Of course, this is not a silver bullet and will not guarantee an identical experience to development on linux. But if you're a beginner, you most likely will not notice any differences and this is a quick and easy way to get started with C dev on windows.
Also remember, once you have VS + Clang installed by following the above steps - you can also write code in VSCode (though it might need some configuration - specifically, you've to point it to the directory where the header files are) and use the terminal with clang to compile.

Will a program written in visual studios 2017 run in a linux or unix environment?

I'm currently very confused about something. I'm currently programming in C, and I'm confused about whether or not that counts as a Unix or Linux environment. Do I actually need to download a port of linux or am I good to use visual studios? The problem is the program I write will be graded via linux/unix.
There isn't a short answer to your question. Consider:
Visual Studio 2017's C++ toolchain, by default, only generates Win32 PE executable files (*.exe, *.dll, etc) which only run on Windows Vista or later (Windows XP support requires an optional VS component).
Linux cannot run these Win32 PE executables by default, though you can install Wine to attempt to run them on Linux installations on the same CPU instruction set. Wine enables Linux to run Win32 PE executables and also provides a Windows-like runtime environment (registry, simulated C:\Windows path, etc) for them to run in: https://www.winehq.org/
Visual Studio 2017 can cross-compile to Linux, macOS, iOS and other operating systems using two different approaches:
Visual Studio 2017's preferred method is to use remote build-servers: you would have a Linux or Macintosh computer on your local network that runs a build agent process which then builds the software on that remote machine, keeping the build toolchain on the Linux/Mac, and even debugging support by running the program on the remote machine with a remote debugger attached.
Microsoft's C++ team wrote a blog post demonstrating how to target Linux using this approach here: https://blogs.msdn.microsoft.com/vcblog/2017/04/11/linux-development-with-c-in-visual-studio/
The other approach is to use a custom makefile using a cross-compilation toolchain running on your local machine. You may need an environment like Cygwin or MINGW installed.
Excepting Wine, all other options assume your C++ code is actually portable: that you don't use any platform-specific APIs (i.e. you stick to the C++ standard library) or that you are using platform-specific APIs with conditional compilation.
Also remember that "Linux" is not a single platform: a binary executable built for Ubuntu 16.0 x64 might not work on RedHat x64, and especially won't work on FreeBSD or OpenBSD (which are not Linux, but a form of Unix).

C Modules On Windows Need Linux System Inclusion

I am new to C programming (proficient in Java) trying to compile some old (~1999) C modules on my windows machine. I'm using Eclipse CDT with Cygwin installed on my computer. I have resolved all of my issues except one: the modules have include statements for things like sys/io.h, sys/stat.h etc. After doing some research I found that these are unix system calls. Is it possible to use Cygwin to get these inclusions resolved on my windows machine through eclipse? Or do I need to run on a unix environment? Please correct me if any of this information is wrong... I'm at my wits end trying to compile these modules. Thank you.
Even if you use Cygwin, Mingw or other GCC-like compilers on Windows (with or without Eclipse) - it still is Windows and does not provide 100% compatible Linux system services. So YMMV.
Windows 10 with WSL provides much more compatible Linux environment and also a real Linux C compiler, with all its include files. If you need to just run some Linux program without spending much effort to Windows adaptation, this is the way.

what software should i use when i want to study c

i want to write code use notepad and compile the c code use cmd on windows (like java),
what software should i use ,
gcc for windows
cygwin
Turbo C
gvim
thanks
An excellent option for Windows is the Visual C++ Express Edition (which is free). This is a full IDE, compiler, and debugger and is a great way to get started.
GCC is also a good option if for some reason you wish to avoid an IDE. I wouldn't recommend this for a beginner, though.
Please don't use Turbo C, it's very old and you will have problems with it.
Cygwin is a popular linux environment for Windows.
Gvim is an editor and (in my opinion) has a very high learning curve. You could use Notepad++ or Code::Blocks to develop your code in.
mingw is also a good option to start with.
IMO you should avoid IDEs: a beginner needs to actually see and feel the whole process of compiling by invoking the compiler from a terminal, not by simply pressing some keys and bang! Also most of the IDEs have code completion facilities which is not good for beginners (especially for C). So I would go with vim (or gvim) and cygwin.
PS: Give Linux a try, you might actually like it; then vim and gcc.
Use cygwin. It's just about the only way to get a C environment on Windows that's both modern (i.e. not 16-bit, DOS-based) and conformant to the standards, and with it you get a fairly-complete POSIX environment, which allows you to actually do interesting things with C.
The classics would be Cygwin and MSYS/MinGW.
Cygwin provides a Linux API compatibility layer and includes a package manager which provides access to many well-known Linux applications (ie batteries included).
MSYS/MinGW only provides a minimal userland to get the GNU build system working.
Both come with their own shell environment, but can be used from Windows' command line as well.
Binaries created with Cygwin-gcc won't work without cygwin1.dll, but you get all the benefits of a mostly-POSIX environment. You can also use Cygwin's MinGW package for cross-compilation and thus create stand-alone binaries.
Other solutions are possible: Currently, I'm using the MinGW compiler together with the Cygwin userland from the Windows command line...
I think cygwin itself named as gcc for windows.
also gvim is not a compiler , It is a very nice and powerful tool for code editing.Also you can try emacs and kwrite
Some suggestions from my side:
In windows, you need to install a third party software to try all programming stuffs(c,c++ etc) ,Most of the times it is having GUI implementations and you didn't get any exact idea behind the code execution flow.also the command prompt of windows not at all efficient as linux shell.
But if you install a good linux distro (ubuntu/fedora/cent os/debian/pardus/suse/arch linux),all default compilers,debuggers and editors are installed within the OS and you can try the basic and all advanced programs by just opening the terminal(shell).Also the shell is a more powerful tool and you can enjoy all kind of automation comamnds(I mean scripting).
Also: for your added information, most of the embedded programmers in the industry prefer command line execution unlike GUI implementation because it is too fast than GUI.

Run C program written in Linux on Windows

I have C program which I wrote in Linux that runs very well. Now I want to run it on Windows.
How do I easily run it on Windows?
Elaborating a bit on the answers from caf and jartieda...
Cygwin is an attempt to emulate a (nearly) complete POSIX execution environment in a native Windows process. It is complete enough that a surprising amount of Unix application code simply compiles and runs using the familiar ./configure && make && make install idiom. This trick was done by supplying a DLL that emulates POSIX system calls using the Windows API. Based on that, you get a complete GCC toolchain, bash, and all the usual command line utilities you are used to. One downside is that the compiled program is dependent on the Cygwin DLL, which makes it tricky to deliver the result to a system that does not already have Cygwin installed and whose user doesn't want to use a Unix shell.
MinGW is a port of the GCC toolchain that generates native Windows applications that depend on the well known (and distributed with Windows itself) MSVCRT.DLL C runtime library. It makes no attempt to emulate a POSIX operating system, but applications that are mostly based on the standard C libraries, will often build essentially unchanged.
MSYS is a compile-time environment that provides enough Unix utilities (including bash) to often allow ./configure to run, and if the project supports the results, finish the build with MinGW's GCC. The result is a native Windows executable that does not depend on any DLLs you don't deliberately use aside from MSVCRT.DLL. Although the MSYS environment itself was a fork of an early version of the Cygwin project, it is primarily intended to be used to provide a unix-like place to compile native Windows applications: one would generally not build new applications based on its runtime environment.
Another approach to compiling for Windows is to use the MinGW cross compiler on linux. A number of MinGW's core developers work that way, testing they product either under Wine, or under Windows running in a VM or a separate PC.
If the program has a GUI component, then you may have additional difficulties. Some GUI frameworks are available for both Linux and Windows. Qt, wxWidgets, and IUP all leap to mind, but there are others out there.
Edit: I've improved the paragraph above about MSYS to emphasize that it is intended to be a compile-time environment for building programs that run as native Windows applications, and not a full POSIX environment like Cygwin.
Note, also, that there is always the option of porting the project to one of the more traditional compilers for Windows development. Open Watcom, the Borland compilers, and Microsoft all have free or inexpensive versions, although often enough not under licenses that make the opens source community entirely happy.
This approach probably requires more effort because the differences between a Linux environment and the Windows environment become more visible when you also switch from one toolchain to another. This is especially true of the Microsoft compilers which are historically not as fully standards compliant as GCC.
The easiest way is to install the Cygwin environment, and compile it under that.
best way recompile it all using mingw compiler.
easy way recompile it under cygwin environment.
The answers you got so far, focus on installing the GNU operating system on the Windows kernel; but you could also use freeware tools from Microsoft. This solution is probably most attractive if you want to continue to develop on Linux, and only do a little work for porting on Windows:
Microsoft offers a simplified version of their development environment as freeware: Visual Studio Express (download). If your program does only file IO it will probably compile unmodified, because Microsoft supplies the C standard library too.
For GUI I also wholeheartedly recommend the Qt framework. It is very well written and documented; it is now licensed under the LGPL, so you can link it to proprietary applications without any cost. However it is written in C++ so you would need to change the programing language. For integration of QT with Visual Studio Express: I believe it works, but you need to try it out. About five years ago I tested the integration of (proprietary) QT and (professional) Visual Studio for my employer, and it worked perfectly.

Resources