How to compile and run C on a Surface Pro X? - c

I'd like to program some Ansi-C on a Surface Pro X. On my Computer I just set up VS Code as an editor and installed Msys2 which comes with the GCC. But the same won't work on the Surface Pro X, cause if the processor architecture as I understand (correct me if I'm wrong).
So my question is: How can I compile and run C on a Surface Pro X and also check for Ansi C conformity. It also would be nice to be able to work in VS Code.
Also is this a general problem of the Surface Pro X? Would those issues also appear when trying to program java or python?

I don't have a Surface Pro X or any other ARM Windows device, however it should be possible to use VS Code since there has been a Windows on ARM version since May 2020 (download on the usual Visual Studio Code download page).
I am not sure on what development environments are available for Windows on ARM, but you could always install WSL (the Windows subsystem for Linux) where you can then install pretty much anything you want. You can then link your VS Code to your WSL and work there.
To install development tools for any language you would then follow instructions on how to install that environment for Linux (eg. using apt-get for Debian and it's derivatives like Ubuntu).
To install basic development tools for Java and C/C++ in WSL type sudo apt install default-jdk default-jre gcc g++, python is generally already installed in a linux environment.

Related

Compile C code in Visual Studio in Windows for Linux

I'm using Visual Studio in Windows to develop basic C applications. I want to compile my code for Linux, without the need to have Linux installed on my machine. Is that possible ? And how ?
You'll need to have Linux installed somewhere. If you can remote to a linux box, vm, or WSL console, from your Visual Studio machine, you can use VS 2019 to build and debug most applications in any of those environments, via the Cross Platform Connection Manager.
The following blog and document links are a good place to start.
Targeting the Windows Subsystem for Linux from Visual Studio
C++ with Visual Studio 2019 and Windows Subsystem for Linux (WSL)
EA and Visual Studio’s Linux Support
Usability Improvements for CMake in Visual Studio 2019 version 16.4: Launch Target Selection and Overview Pages
Similarly, Visual Studio Code has some support for this as well:
Using C++ and WSL in VS Code
Sincerely,
yes, it is possible.
Have a look at this stackoverflow question.
Install WLS on your Windows machine
Use the standard gcc instruction (or, better, Makefiles and/or CMake)
Example:
Let's say you have your program:
//code within filename.c
#include <stdio.h>
int main(){
printf("Hello Youssef\n");
return 0;
}
Then, within the folder, run:
$ gcc filename.c
and then run it:
$ ./a.out
Hello Youssef
You can install a VM (virtual machine) on your windows computer, then install linux on the virtual machine.
Note: both the VM and linux are free downloads

MinGW-W64: Which Install Options (Archtitecture, Threads, ...) must/should I Use for Native Windows Development

I want to install MinGW-W64 for Windows 10 64 Bit (must run on Version 1607!). First problem is which MinGW should I download, there are 3 versions on download page: 1) "MingW-W64-builds", 2) "Msys2", 3) "Win-Builds". I have choosen 1). If this was wrong for my purpose (see below) please tell me.
When I start the installer I have to choose the following options, which I'm not clear what to choose:
Architetcture: i686 or x86_64
Threads: posix or win32
Exception: dwarf or sjlj
Purpose (What I want to do)
I want (later) to install the CLang C++ 64 bit Compiler, which AFAIK requires the libraries from MinGW-64.
I want to write native Windows 64 bit C++ (at least C++ 14) and C applications (compiled with either GCC or CLang). I don't need a bash (or someone tells me a good reason why I should use it instead of the excellent Windows Powershell).
At a later time I want to be able to install an IDE (like Eclipse) which especially integrates the debugger (the one for GCC and if it is a different one for CLang that for CLang).
The sources should be as compatible as possible to sources which can be compiled with Visual Studio and the produced binaries should also be as compatible as possible with code produced with Visual Studio (unfortunately I cannot use VS Community version because of license reasons).
(Maybe this is usefull for answering: Python 2.7.11 and Python 3.7 are installed on my machine)
MSYS2 is an environment that gives you a UNIX-like shell.
You can use this if you need to use UNIX-like build tools (like autoconf).
If that's not what you need, don't install it.
Certainly don't build for MSYS as it's closer to Cygwin POSIX emulation than native Windows.
You will need a GCC compiler build against MinGW-w64.
For example one of the MinGW-w64-builds from: https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/
However, there don't seem to be any recent builds posted there, while there were newer releases of both GCC and the MinGW-w64 libraries. So I have built more recent versions and published them at: http://winlibs.com/
On http://winlibs.com/ there are also some instructions on how to compile from the command line and how to set up the compiler in the Code::Blocks IDE.
If you need Clang instead of GCC there are Windows binaries available at: http://releases.llvm.org/
However, you will still need the MinGW-w64 libraries to build for Windows using CLang. So if you're new to this, maybe you should just start with GCC before moving on to CLang.
Keeping your code compatible between compilers or even operating systems is up to the programmer.
The key rule there is to avoid anything compiler or operating specific, and if you really must then enclose them in conditional defined (e.g. put the specific code between #ifdef __MINGW32__ or #ifdef _WIN32 and #endif).

Build C executable for Raspberry Pi on Windows or Linux

I have to design a C executable (no GUI) that is supposed to run on Raspberry PI. I'm familiar with design using IDE like Visual Studio or Eclipse (with CDT plugin). If i use Raspberry PI as a design machine, I think I have no chance to use a standard IDE. I should use makefiles and gcc compiler only.
Is there any chance to develop Raspberry PI executable using Visual Studio (for Windows) or Eclipse (for both Windows and Linux).
You can specify to eclipse projects with Makefiles. You can also specify a compilation toolchain.
So yes, you can develop and compile for Raspberry Pi or for other plateforms using Eclipse.
For getting toolchain and other tools for Rasp Pi you can find things here.
In Eclipse, you create a new or import a project choosing Makefile Project with Existing Code then add your toolchain.
If you have a newer Pi like the 4, you should be able to run eclipse directly from the Pi desktop. You can download via:
sudo apt-get install eclipse
This will be a stripped-down version and will likely run quite slow, so I agree compiling on a more powerful remote machine is better...
Is there any chance to develop Raspberry PI executable using Visual Studio (for Windows) or Eclipse (for both Windows and Linux).
Yes, this is called cross-compiling. You can set up a cross-compile toolchain for the raspberry pi on windows or linux and configure your Eclipse CDT project to build with the toolchain. You can even set up remote debugging.
This website has good information and a step-by-step guide for windows using cygwin.
This looks like a good guide for linux.
Edit:
Just realized you asked for Visual Studio on Windows. I don't think there is Visual Studio support for this. The example I pointed to sets up cygwin so you have an emulated linux environment. You could also set up a VM using free VM software and install a linux environment that way, and run eclipse CDT from there. This is what I did when setting up a cross compiling environment for the Raspi.

What does Eclipse CDT come with?

This is what i currently have installed on my home computer:
http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers-includes-incubating-components/indigosr2
Now, that was a pain to setup because you needed to use Cygwin to install a bunch of stuff in order for Eclipse to compile and run a C project. I found this the other day:
http://www.eclipse.org/cdt/
Does Eclipse CDT come with everything it needs to compile and run a C program or does it still depend on external files? Does it come with a standard library?
You do not have to use Cygwin and you can use alternatives such as mingw (it is simpler for most people to install). Checkout this tutorial for detailed description how to setup on Windows:
http://www.banym.de/eclipse/install-eclipse-cdt-on-windows-7
Compiler is responsible for standard library and in the case mentioned above it is mingw.
If you are on other hand interested about MAC OS installation checkout:
http://forge.mysql.com/wiki/Eclipse/CDT_on_Linux_and_Mac_OS_X
http://max.berger.name/howto/cdt/cdt.jsp

How do I compile a .c file on my Mac?

How do I compile a .c file on my Mac?
You'll need to get a compiler. The easiest way is probably to install XCode development environment from the CDs/DVDs you got with your Mac, which will give you gcc.
Then you should be able compile it like
gcc -o mybinaryfile mysourcefile.c
You will need to install the Apple Developer Tools. Once you have done that, the easiest thing is to either use the Xcode IDE or use gcc, or nowadays better cc (the clang LLVM compiler), from the command line.
According to Apple's site, the latest version of Xcode (3.2.1) only runs on Snow Leopard (10.6) so if you have an earlier version of OS X you will need to use an older version of Xcode. Your Mac should have come with a Developer Tools DVD which will contain a version that should run on your system. Also, the Apple Developer Tools site still has older versions available for download. Xcode 3.1.4 should run on Leopard (10.5).
In 2017, this will do it:
cc myfile.c
Just for the record in modern times,
for 2017 !
1 - Just have updated Xcode on your machine as you normally do
2 - Open terminal and
$ xcode-select --install
it will perform a short install of a minute or two.
3 - Launch Xcode. "New" "Project" ... you have to choose "Command line tool"
Note - confusingly this is under the "macOS" tab.
Select "C" language on the next screen...
4- You'll be asked to save the project somewhere on your desktop. The name you give the project here is just the name of the folder that will hold the project. It does not have any importance in the actual software.
5 - You're golden! You can now enjoy c with Mac and Xcode.
You can use gcc, in Terminal, by doing gcc -c tat.c -o tst
however, it doesn't come installed by default. You have to install the XCode package from tour install disc or download from http://developer.apple.com
Here is where to download past developer tools from, which includes XCode 3.1, 3.0, 2.5 ...
http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wo/5.1.17.2.1.3.3.1.0.1.1.0.3.3.3.3.1
Ondrasej is the "most right" here, IMO.
There are also gui-er ways to do it, without resorting to Xcode. I like TryC.
Mac OS X includes Developer Tools, a developing environment for making
Macintosh applications. However, if someone wants to study programming
using C, Xcode is too big and too complicated for beginners, to write
a small sample program. TryC is very suitable for beginners.
You don't need to launch a huge Xcode application, or type unfamiliar
commands in Terminal. Using TryC, you can write, compile and run a C,
C++ and Ruby program just like TextEdit. It's only available to
compile one source code file but it's enough for trying sample
programs.
Use the gcc compiler. This assumes that you have the developer tools installed.
STEP 1
Just check wheater your MacBook has the compiler or not using this command 👉🏻 clang --version in your command line interface. If the tool exists then you will be able to see the version like this
STEP 2
Next, go to the directory where your source code exists using CMD Interface, then run the command make "filename" without the .c extension.
STEP 3
The final command to run your source code after compiling it is ./filename without the .c extension.
This is how you can compile and run your program on the Macintosh system.

Resources