Eclipse C Build selected files generates no executable - c

I'd like to build a single C file on Windows using Eclipse Helios and Cygwin. I rightclick on the file, select "Build selected file", the console output returns but I can't find an executable. I can't use the build project function because I have multiple folders with different applications. (for example it complains that I have more than one main function)
Console output:
Rebuilding selected file(s)
**** Internal Builder is used for build **** gcc -O0 -g3 -Wall -c -fmessage-length=0 -ofolder\test.o ..\folder\test.c
Build of selected resources is complete.
Build and Run works when I have just one src folder with a single Hello World file for example.

When you're rebuilding a specific file you're only rebuilding the corresponding object file. There's nothing strange about this.
From gcc manual page:
When you invoke GCC , it normally does preprocessing, compilation, assembly and linking. The "overall options" allow you to stop this process at an intermediate stage. For example, the -c option says not to run the linker. Then the output consists of object files output by the assembler.

the -c in the build statement will only compile, not link so no executable will be generated. However, an object file will be placed in ../folder named test.o

Related

Why gcc under Windows O.S. produces a .o instead of a .lib file when compiling static libraries?

I am using gcc 8.1.0 on Windows. To install it I set up Code::Blocks on my computer and updated the environment variable list by adding the path to the gcc.exe program within the installation folder of CodeBlocks. The file editor I used was the built-in editor in Visual Studio. The terminal to compile was the power shell from Visual Studio as well.
In the library development folder I have the files mul.c and mul.h. Their content is irrelevant.
To compile the library I use the command:
gcc -c mul.c
When I run it, it creates a file object mul.o and not mul.lib. I needed to use the option -o mul.lib to successfully create the desired extension file. After placing the header, the .lib file and the main.c in the same parent folder I am obvioudly able to build the executable by running.
gcc main.c -I./include -L/static -lmul -o my_program.exe
I have two questions:
Why does gcc produces a .o if I am in a Windows environment?
I followed a tutorial that compile the static library under Linux and it names it libmul.o, in this way the -lmul option is able to retrieve the library. But if I call my generated static library libul.lib it generates the error:
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-ingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmul
collect2.exe: error: ld returned 1 exit status
Are these a normal behaviours by gcc, or is it side effect of making gcc available just by updating the Windows environmental variables list?
Thank you to the community in advance.
GCC comes from the *nix world where libraries have the .a extension. When using GCC+MinGW this remains the case.
Shared libraries in MinGW are .dll files but their libraries for linking are .dll.a files.
The advantage of .a files is that a lot of sources build out of the box on Windows with MinGW, especially when using MSYS2 shell.
If you use -l it will look for .a (or .dll.a for shared build) file adding the lib prefix and the extension automatically.
So -lmul will look for libmul.a (static, e.g. when --static linker flag is given) or libmul.dll.a (shared).
By the way, you are using quite an old GCC 8.1.0.
As I write this current version is 12.2.0. Check https://winlibs.com/ for a standalone download (instructions on how to configure in Code::Blocks are on the site) or use MSYS2's package manager pacman.

Build commands needed to run Wine programs from IDE

I’ve recently done a git clone of the wine repository at https://github.com/wine-mirror/wine and downloaded the folders to (~/repo/wine/). I'm trying to run Notepad, but don't know how. I am assuming that to build and compile it, I would need to run main.c from the notepad folder. I’m running GCC v 8.3.0 on Raspbian/Linux 10
With the repo downloaded as shown above, what build commands would I need to run notepad’s main.c from Geanie (or any, currently using Geanie) IDE? Can a single compile and/or build command let me run notepad from Geanie, or am I missing something?
Other details (not needed if what I thought I was going to do can't be done):
I wanted to try to run main.c at (~/repo/wine/programs/main.c), but don’t know how to get GCC to view all of the necessary header files. In my execution instructions window in Geanie, I have
gcc -Wall -c “%f” /home/pi/repo/wine/include
and my build instruction (it won't compile, so this isn't anything I've even gotten to work with yet...)
gcc -Wall -o “%e” “%f” /home/pi/repo/wine/include
When I attempt to compile, I get:
Stdio.h:11:10: fatal error: corecrt_wstdui.h: No such file or directory.
#include <corecrt_wstudio.h>
I went over to the stdio.h and attempted to add a build instruction here as well that also targets the include folder (which is the supposedly missing file), but it won’t compile.
Using cpp -v, I can see my include paths for GCC are as follows:
#include”...” paths:
#include<...> paths:
\usr\lib\gcc\arm-linux-gnueabihf\8\include
\usr\local\include
\usr\lib\gcc\arm-linux-gnueabihf\8\include-fixed
\usr\include\arm-linux-gnueabihf
\usr\include

Error when using libraries in C

I'm trying to play an mp3 file in terminal using C and I followed this link to do so.
I've installed the two libraries libmpg123 and libao. Also, I've compiled the play.c program using the command:
gcc -O2 -o play play.c -lmpg123 -lao
But I get the following error when I run it:
./play: error while loading shared libraries: libao.so.4: cannot open shared object file: No such file or directory
Can you figure it out why it happened.
The executable can be linked, but at run-time, it cannot find the shared libraries. Add the libraries to your LD_LIBRARY_PATH so the program can find them at run time.

Correct syntax checkin with external makefile

I've made a Makefile project (New -> C Project -> Makefile project). And it's correctly compiles.
But syntax checker is not working properly because of Eclipse doesn't import some important options from makefiles. -I (header folders) for example.
How to solve this problem?
Eclipse uses build output generated by your makefiles to parse compilation flags, inclusion paths, predefined macros, etc. It expects that your build system echoes each command it executes.
That is, it will not work, if the output of make looks like this:
[CC] foo.o
[CC] bar.o
[LD] baz
Make sure, that it prints raw commands, like:
gcc -Ipath/to/include -DFOO=1 -O2 ... -o foo.o -c foo.c
gcc -Ipath/to/include ... -o bar.o -c bar.c
ld foo.o bar.o -o baz
Some build tools provide an option to enable a verbose mode (like make V=1). However, handwritten makefiles are usually OK, because Make echoes executed commands by default.
In this case Eclipse will be able to recognize build options (like path/to/include or FOO=1) and use them to setup C/C++ indexer.
Related project settings
Configuring the project:
In C/C++ Build -> Discovery Options check these entries:
Automate discovery of paths and symbols
Discovery profile: GCC per file scanner info profile
Enable build output scanner info discovery
After that you need to perform a fresh build from inside Eclipse (Clean Project, then Build Project), so that it will see a complete build log.
This feature is rather fragile, and gets broken sometimes... Usually it helps to flush the index using Project -> Index -> Rebuild.

Eclipse can't run my Makefile

I'm writing a C project in Eclipse and while trying to run it I get the following error message:
(Cannot run program "make": Launching failed)
My Makefile is:
all : GenericHashTable.o TableErrorHandle.o
gcc -Wall GenericHashTable.o TableErrorHandle.o -o all
GenericHashTable.o : GenericHashTable.c GenericHashTable.h TableErrorHandle.h
gcc -Wall -c GenericHashTable.c -o GenericHashTable.o
TableErrorHandle.o : TableErrorHandle.c TableErrorHandle.h
gcc -Wall -c TableErrorHandle.c -o TableErrorHandle.o
clean :
rm all *.
Is the formatting broken in your makefile or in your question? Commands on the line below the target & dependencies. Does this makefile work from the command line?
Assuming the makefile is correct check the obvious things such as ensuring Eclipse can see your toolchain. Perhaps it can't even find the make command or you haven't set it from preferences.
Also the CDT offers a managed makefile and a standard (manual) makefile. The managed means Eclipse will create the makefile for you. The standard makefile is a makefile you are responsible for writing. Perhaps if your project is simple you should use the managed makefile to save yourself the hassle of writing one.
You can try the internal builder from eclipse:
Project->Properties->C/C++ Build
There (in the top level of C/C++ Build) you find Builder Settings->Builder Type which you set to Internal Builder. This way CDT does not require an external make command.
Either use the internal builder as "Turbo J" already suggested or make shure 'make' is in your PATH.
You can set the PATH for the build process in the Project-Properties in 'C/C++ Build -> Environment' - click "Select..", choose PATH and then change it by adding the correct path for the 'make' command.
This way you can also set the PATH of your compiler - that may be necessary if you use the Internal Builder.

Resources