Set Up Compiler for C for Sublime Text 3 - c

I just started to learn C programming at University. Unfortunately I need a specific compiler in order to meet their requirements.
My C Compiler needs to compile with following settings:
gcc -Wall -o2
Can anyone help me by programming a compiler for me, or tell my what to do?
Thank you for you help
Greetings
Alex

You can install gcc in cygwin:
http://preshing.com/20141108/how-to-install-the-latest-gcc-on-windows/
Edit your code in Sublime Text 3 and compile it with gcc

Well I don't know what OS or hardware you are using but gcc can be installed on all Linux systems, and OSX has clang which is compatible with gcc, and calling gcc on OSX simply invokes clang because it's hard linked. If you are on Windows install cygwin.
Please see this answer on how to compile and link C programs in sublime rather than using a shell.

Related

Run precompiled C program

I am currently working on a program that is encrypting a text file. I made it in Turbo C++, using C language, but my main problem is that:
I need to run turboc++, in order for my .exe program to run. Does anybody here know a way to compile it and run it as stand-alone program?
TurboC++ is an obsolete compiler for an obsolete variant of C++ or of C. Use a recent compiler (such as GCC 8 or Clang 7; both are open source so freely available) for recent C11 or C++14 (or C++11) standards. Get rid of TurboC++ since it is obsolete (and is not a good compiler, compared to other existing ones).
If using GCC, you'll compile your C file foo.c using gcc -Wall -g -O foo.c -o foo. If using Clang, you'll compile with clang -Wall -g -O foo.c -o foo. Don't forget to enable all warnings and debug info. You'll get an executable foo which can be run without having the source code. That executable is specific to your operating system and to your instruction set architecture.
I need to run turboc++, in order for my .exe program to run.
With any good enough C or C++ compiler, you don't need the compiler to run the executable it is producing.
Don't confuse a compiler with the IDE or source code editor you'll use to write C or C++ source code. All C or C++ compilers I heard of are command line programs, that might be run from a terminal, an IDE, a good source code editor (such as emacs or vim).
If your source is in C++, that is bar.cc, use g++ -Wall -g -O bar.cc -o bar or clang++ -Wall -g -O bar.cc -o bar
Adapt these compilation commands (I'm giving those for Linux) to your operating system. On Windows, executables have a file path ending with .exe.
Of course, both GCC and Clang are able to compile and link a program made of several translation units. Learn to use some build automation tool, such as make or ninja. Such tools are driving compilation and linking commands.
If you are learning to program in C++, be aware that it is a very difficult programming language (you'll need years of efforts to master it). And notice that Linux is a very developer-friendly operating system, mostly made of free software whose source code you could study. That is why I recommend Linux for those learning C++ or C.
PS. If your teacher requires TurboC, I do recommend to have a polite discussion with him, suggesting to make your homework with GCC or Clang.

Machine/compiler dependent segfault with c code

I am trying to run a parallel code (numerical simulation) on a Linux machine. I have tested the code configuration on my laptop (OSX) and all works fine. When I ship to the larger (Linux) machine it segfaults on the first timestep.
I didn't write the code and don't want to get into debugging it. I am hoping that it may be possible to solve the problem with a different compiler or flags.
On my laptop (OSX) I have the code running with the default compiler.
cc --version
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.5.0
On the Linux machine that I work on, I am using
cc --version
cc (Ubuntu 4.9.4-2ubuntu1~14.04.1) 4.9.4
I have tried both 4.9.4 and 4.8.4 on the Linux machine, and both give the same segfault.
My Makefile sets the following directives:
CFLAGS = -O3
LDFLAGS = -I`pwd` -I$(SRCDIR) -I/usr/bin/include -I/usr/include/mpi
LIBFLAGS = -lm -lnetcdf -lmpi -L/usr/bin/lib
I know this is a shot in the dark, but if anyone has a suggestion for a change I could try to get this working on the linux machine I would be most grateful. In case it's not obvious to you already, I am a mere regular scientist, not a computer scientist, so most of this is black magic to me.
Thanks.
I didn't write the code and don't want to get into debugging it.
Well, if you refuse to help yourself, you'll have to bribe someone else to do it for you.
I am hoping that it may be possible to solve the problem with a different compiler or flags.
It may well be possible, but finding the right flags requires understanding the problem in the first place.
Otherwise, you are trying to program by coincidence, and that rarely leads to success.

Compile a C program gives "can't find compiler executable in your search path (GNU GCC compiler)" in Codeblocks

I have installed codeblocks in windows 7 first time and try to run a simple C program but I get this error?
can't find compiler executable in your search path (GNU GCC compiler)
I tried many things to solve it but unable to compile.
Have you installed the Mingw compiler or any other simiar compiler? If not install that first. After you have done so, you need to set codeblocks to use that compiler. You can do that by going to the settings>compiler settings and set the necessary options there. You may need to refer the place where you have installed Mingw or other compiler. Note the compiler executable is gcc for C and g++ for C++ and the linker is ld i guess. Debugger is gdb. You need to tell codeblocks where are these located.
I also received that error. I fixed it using Settings -> Compiler -> Global compiler settings -> Toolchain executables -> Auto detect.

after the installation via MacPorts of gcc45, how can I use it to build C language on my Mac?

The following html link contains all the relevant bash command line records of the installation process. Thank you for help!
That was a bad question
I didn't use XCode through I know Xcode will make it easier! I use an Air, memory of 4GB currently.
If this won't work easily I probably will quit learning C or run and compile C on Windows. :(
And XCode stuff, whatever.
You command-line output indicates rather clearly that you aren't telling gcc what to compile, so it's throwing its hands up in exasperation:
$ gcc
i686-apple-darwin10-gcc-4.2.1: no input files
You'll need to specify the file you're compiling. Better yet, use an IDE, like Xcode.
<Shrug> What do you want us to say?
Obviousy Macports is trying to build/install gcc but it can't without a compiler. Yes gcc can be built without a preexisting compiler, but good luck and why? Especially when XCode is a free download, click click let it start and a little while later it's done. At that point as pointed out elsewhere, gcc, g++ will work, but it's not actually gcc but clang in disguise.
If you want, you can use macports or brew or whatever later if you really want to, but again why? For programs that only work using gcc extensions? Doubt it. You just want a c/c++ compiler. If you ever want to do programs for the Mac or IPhone, you need XCode anyway, gcc won't do.

How do I change the compiler in Xcode

I'm compiling a C code in Xcode 4.6.3, however I don't know which compiler I'm using. I need to use gcc 4.2.
Thanks in advance.
If you really need to change to gcc, you can do so in the build settings:

Resources