Compiling a c program on linux ubuntu - c

Hey guys please help me out here. I have made a c program. I'm new to it and compiling it and i'm getting an error thats making me pull my hair out.
error
as: unrecognized option "--32"
I've tried using gcc -c, gcc -o to no avail.
however, using gcc -S to get a asm file works.
What am I doing wrong?
EDIT: I've tried
gcc -c verilog.c
gcc -o verilog verilog.c
gcc -o verilog.c
gcc verilog.c -o verilog
I also got a warning on a part of my code but that wouldnt stop the compilation though right?

Related

how to switch from assembly code to c code in gdb

I am trying to debug my c program using
gcc -g -lm -lpthread -std=c99 -w terminalproject.c
and then
gdb a.out
but when I type
layout next, it shows me assembly code not c code.
How to switch to C code in layout?
EDIT: I am using Red Hat Linux 6, I tried to run it in Ubuntu, It is showing C code.
p.s my code has pthreads in it.
This command:
gcc -g -lm -lpthread -std=c99 -w terminalproject.c
is wrong. Use this instead:
gcc -g -std=c99 -pthread terminalproject.c -lm
You should never use -w (suppress all warnings) flag, unless you desire painful debugging sessions.
layout src says No source Available.
This likely means that you are using updated GCC, but ancient GDB. Try building recent GDB release from source -- it's usually not hard.

rl_replace_line of readline library impossible to build on mac os

Recently I built a microshell program on Linux. I wanted to work on my MacBookPro (Big Sur 11.6.2) and found out that I'm having issue to compile my program because of the function rl_replace_line of the readline library.
I compile with :
clang -Wall -Wextra -Werror -I./includes
The error I'm having is :
error: implicit declaration of function 'rl_replace_line' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
I found another question on stackoverflow and the answer was to compile with :
-L .brew/opt/readline/lib and -I .brew/opt/readline/include
It doesn't work for me and I'm still having the same error. I tried what brew suggest which is to do :
export LDFLAGS="-L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/opt/readline/include"
I also tried to compile with -lreadline and it doesn't work.
It still doesn't work for me.
Any idea what I could try to solve this issue ?
Thank you !

Can't name executable with specified optimization

I have to turn off optimizations while compiling c code I wrote while using the gcc compiler on a linux. I have found that I can compile the code but I can only get the code to compile without the executable name specified (default to a.out).
So this works:
gcc -O0 Problem04b.c
But my problem is that I have to submit this assignment and I can't submit an executable called a.out because my instructor needs to know which problem it is. I realize I can probably just run
cp a.out Problem04b
then
rm a.out
but I want to know if there is a way I can just compile the code directly into the executable Problem04b. I've tried to run the command like this:
gcc -O0 Problem04b Problem04b.c
but I'm having no luck.
Thanks for your help.
It's the -o flag:
gcc -O0 -o Problem04b Problem04b.c
To specify the output file, you need to use the -o <filename> option with gcc.
Note : Please mind the lower case here
In your case, it should be
gcc -O0 -o Problem04b Problem04b.c
For reference: From gcc manual
-o file
Place output in file file. This applies to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.
Actually, you also want to get warnings (that won't change the produced executable, but it is very helpful to you), so compile with
gcc -O0 -Wall -Wextra Problem04b.c -o Problem04b
The -Wall option asks for nearly all warnings, the -Wextra option asks for even more of them.
To run your thing (the ./ is useful because of possible PATH issues):
./Problem04b
Notice that -O0 is optional (since it is the default), you could remove it.
gcc -Wall -Wextra Problem04b.c -o Problem04b
If you want real optimization, e.g. for benchmarking, use e.g. -O1 or -O2 or -O3
You probably want to compile with debug information, then
gcc -g -Wall -Wextra Problem04b.c -o Problem04b
and of course you need to learn how to use the GDB debugger. So read some tutorial about that, then type
gdb ./Problem04b
You'll get a (gdb) prompt. Try help at that time.
You probably want to read the chapter about invoking GCC of the GCC documentation.

gcc is working, but not yielding executable

My C compiler was working a second ago and making executables, but I started working on a new .c file and suddenly it won't work anymore. I haven't changed anything and I'm still using the same commands, Gitbash version, etc. The compiler is still able to catch errors, so gcc works, but after calling:
gcc -std=c99 my_file.c
there is no executable called my_file.exe. Help sites online suggest installing additional software to fix the error, but I'm hesitant to do so because everything was working fine earlier and I don't want to aggravate the problem with additional software.
Since you have not specified the name of the file to output, GCC will output a.exe.
If you desire output named something else, you must use the -o flag, for example:
gcc -std=c99 -o my_file.exe my_file.c
On Unix, that compiler command would generate an executable a.out. You may find that there is an executable with a default name — but I don't have Windows to check what that name is. Guesses might include a.exe, a_out.exe, aout.exe, etc.
To get my_file.exe:
gcc -std=c99 -o my_file.exe my_file.c
If you don't specify an output -o flag you will get a.exe by default (a.out on other platforms),
gcc -std=c99 my_file.c
If it is working, produces
a.exe
I think you wanted
gcc -std=c99 -o my_file.exe my_file.c

Alchemy C Code compilation

I am using alchemy to compile the C code.
This is the way I am compiling
gcc oggvorbis.c -O3 -Wall -swc
oggvorbis.swc -lvorbis
I am getting an error
llvm-gcc: oggvorbis.swc: No such file
or directory.
But the command works fine when i don't use any shared library.
Your command line invocation should probably read (untested)
gcc oggvorbis.c -O3 -Wall -swc -o oggvorbis.swc -lvorbis

Resources