I recently discovered the Tiny C Compiler. For the project that I'm currently working on, performance is not a real issue, but file size is, making TCC ideal. I'm using Autotools as a build manager, and I figured that using TCC would be as simple as ./configure CC=tcc.
However, this returns checking whether the C compiler works... no. In config.log, it says configure: exit 77.
Despite all of this, setting CC=clang works fine. Is there any way to get Autotools to use TCC?
The issue appears to have been the fault of my CFLAGS. While TCC was normally able to compile programs with them, Autotools seems to have thought otherwise. Setting CFLAGS="" resolved the issue.
For future reference, my CFLAGS are -march=native -mtune=native -O2 -pipe -fstack-protector --param=ssp-buffer-size=4.
iirc tcc does not produce tiny executables - it is tcc itself that is tiny. Perhaps you're looking for gcc -Os?
Related
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.
I'm exploring using clang as the compiler for ARM embedded development. As clang doesn't have an equivalent of .spec files, I'm having trouble convincing clang to link against libc_nano. How could I either tell clang to not link against any libraries by default so I can specify the correct library, or rewrite the -lc command to -lc_nano?
The command I'm trying to run is:
clang -target arm-none-eabi -mcpu=cortex-a5 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a main.c
Currently I get this error message:
/usr/lib/llvm-6.0/bin/ld.lld: error: unable to find library -lc
EDIT: I've noticed that clang has a -fno-autolink which according to the help text: Disable generation of linker directives for automatic library linking. However it doesn't seem to do anything?
EDIT2: I'm aware I could abuse symlinks to achieve this. I would like to avoid symlinks in this case as it can make the build system brittle.
Upon further google-fu and grep-fu, it turns out the answer was staring at me the entire time. Clang has a -nodefaultlibs that does the trick and prevents default linker directives. Although strangely it wasn't documented in --help.
You can build fake libc.a without any functions inside and use it together with libc_nano.
I have a program written on Linux in GNU C. The program compiles with GCC. I have an install shell script,
gcc -o program program.c -Wall -pedantic -std=gnu11 -lm -fopenmp
which works greatly.
The problem is with Mac. For some reason, Mac sees gcc and instead uses clang even though GCC is installed and install.sh explicitly says gcc. clang doesn't work with omp.h The problem is that clang can't use omp.h and solutions offered http://releases.llvm.org/3.7.0/tools/clang/docs/ReleaseNotes.html#openmp-support don't work, and omp.h may not work in mac at all Enable OpenMP support in clang in Mac OS X (sierra)
I never use macs, and because of this nonsense I never plan to. However, some people using my program want to use Mac, so I have to deal with this.
I've tried various shell script modifications, but none of them work, mac insists on using clang and won't use gcc
I need to do one of two things which I don't know how to do:
1) force Mac to use gcc (which it refuses to do now)
2) get clang to use omp.h in mac (which from other answers on Stack Overflow, looks impossible)
Your second option (get clang to use omp.h) is not impossible (any more). From my answer here:
Try using Homebrew's llvm:
brew install llvm
You then have all the llvm binaries in /usr/local/opt/llvm/bin. To compile the OpenMP Hello World program, for example, type
/usr/local/opt/llvm/bin/clang -fopenmp -L/usr/local/opt/llvm/lib omp_hello.c -o hello
You might also have to set the CPPFLAGS with -I/usr/local/opt/llvm/include.
I am now learning c language, and my school put all assignments on myth, every time we have to log in by ssh and execute command remotely.
Thus I want to download the files and execute them on my own macbook. However when I use make command to compile the files, I got errors and warnings such as :
gcc -g -O0 -std=gnu99 -Wall $warnflags -m32 -c -I. vectest.c -o vectest.o
warning: unknown warning option '-Wlogical-op'; did you mean '-Wlong-long'?
vectest.c:10:10: fatal error: 'error.h' file not found
#include <error.h>”
I googled these problems but could not find a satisfactory answer. can anyone help me solve this ? or I have to use a linux machine instead?
Indeed; compilers for various platforms (even if it's the "same" compiler, such as GCC) may have different flags and behaviors. You may be able to get it to work - you could remove the -Wlogical-op flag from $warnflags in your Makefile, but if the error.h file is a system-supplied header file, you're probably in trouble. Therefore, I suggest that you download e.g. VirtualBox and run Linux on it.
See error(3) for what this header provides. It's not specific to linux but to the GNU C library. What you COULD do is provide your own minimal implementation of these functions and write your own error.h.
You could even `#define' them to do nothing at all, but then you will probably lose some error reporting in the existing code. Maybe you could try to find a teacher understanding the problem and discuss the issue ... it's probably better to learn standard C not using any platform-specific extensions.
stackoverflow, et. al.,
I just installed Allegro 5 on my Ubuntu machine and I see some source code for this game development tool, but I do not see specific instructions for how to compile it.
For C programs I use gcc on the terminal.
My questions are:
From what directory do I compile allegro5 programs?
What compiler options are necessary? (the normal gcc someCProgram.c -o MyProgram doesnt work)
Thank-you for reading. I have read two c books so I am not a complete noob, but I have the struggles...
All the best,
user2085446
Okay, let's put this into an answer:
If your program just consists of a single .c file, you can run gcc from the path the file is in. However, in general there's nothing wrong with invoking gcc from anywhere else as long as you get the paths right.
For linking with external libraries, you need -lmylibrary options in the compiler command, e.g. -lfreetype for the freetype library and so on.
Now, this can get a bit complicated when your libraries depend on other libraries etc. That's what the pkg-config tool is for.
When you look at the allegro wiki page, you will see the following sample command:
gcc [source file(s)] -o [output] `pkg-config --libs allegro-5.0`
The pkg-config bit will resolve the relevant -l options for you.