Eclipse can't run my Makefile - c

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.

Related

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

Link a makefile for using SDL librarie

I'm learning using the SDL librarie, with a french site.
This is the tuto :
"There may be some of you who have gotten into the habit of compiling by hand under Linux using a Makefile (file controlling compilation).
If this is your case, I invite you to download a Makefile which you can use to compile SDL projects.
The only thing a little special is the addition of the SDL library for the linker (LDFLAGS). You will have to download the Linux version of the SDL and install it in your compiler folder"
I've found my gcc folder in /usr/bin/gcc , but when I want to move the makefile to this folder, the error is :
mv: cannot move 'makefile_sdl' to '../usr/bin/makefile_sdl': Permission denied
There it is my make file, maybe something's wrong or missing (i'm a beginner ahah)
CPP=gcc #compiler command
CFLAGS=-O3 #Option d'optimisation du programme
LDFLAGS=-lSDL -lSDL_mixer #Linker
EXEC=nomProgramme #Nom du programme à modifier
all: ${EXEC}
${EXEC}: ${EXEC}.o
${CPP} $(CFLAGS) -o ${EXEC} ${EXEC}.o ${LDFLAGS}
${EXEC}.o: ${EXEC}.c
${CPP} $(CFLAGS) -o ${EXEC}.o -c ${EXEC}.c
You don't need to (and shouldn't) move the makefile to /usr/bin.
You can put it anywhere, but things will be easier if it's in the same directory as your source code (nomProgramme.c).
You need to name your Makefile Makefile. Case sensitive, make sure to check for spelling errors, etc. You also need to be in the same directory as Makefile when you run make.
You should also just run make without any specified targets. It will automatically build the all target, which will build your program into an executable called nomProgramme.
You'll also need to install libsdl-mixer1.2-dev (sudo apt-get install libsdl-mixer1.2-dev and change EXEC=main back to EXEC=nomProgramme.
Here's a link to the GNU make documentation. It gives a quick overview and then a very detailed explanation of everything you can do with GNU make: https://www.gnu.org/software/make/manual/make.html
to answer the OPs question:
the directory /usr/bin is not writable via user (like yourself).
However, executing a command line that is prefixed with sudo (giving you 'root' privileges) will enable you to write on that directory.
However, /usr/bin is intended for executable files and Makefile_sdl is NOT an executable file
Suggest saving that file 'somewhere' Then when you want to use that makefile, to copy it to the directory where your current project is located (I.E. the directory in which you want to run make
However, Makefile_sdl is not one of the standard file names recognized by make so must run make via:
make -f Makefile_sdl

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.

How to compile makefile using MinGW?

I'm new to this. Just wanted to ask how to compile a makefile. I am using MinGW compiler in C language. Do I have to save all my files in MinGW\bin? because right now my files are in a different directory.
Appreciate the help.
Excerpt from http://www.mingw.org/wiki/FAQ:
What's the difference between make and mingw32-make?
The "native" (i.e.: MSVCRT dependent) port of make is lacking in some functionality and has modified functionality due to the lack of POSIX on Win32. There also exists a version of make in the MSYS distribution that is dependent on the MSYS runtime. This port operates more as make was intended to operate and gives less headaches during execution. Based on this, the MinGW developers/maintainers/packagers decided it would be best to rename the native version so that both the "native" version and the MSYS version could be present at the same time without file name collision.
So,look into C:\MinGW\bin directory and first make sure what make executable, have you installed.(make.exe or mingw32-make.exe)
Before using MinGW, you should add C:\MinGW\bin; to the PATH environment variable using the instructions mentioned at http://www.mingw.org/wiki/Getting_Started/
Then cd to your directory, where you have the makefile and Try using mingw32-make.exe makefile.in or simply make.exe makefile.in(depending on executables in C:\MinGW\bin).
If you want a GUI based solution, install DevCPP IDE and then re-make.
You have to actively choose to install MSYS to get the make.exe. So you should always have at least (the native) mingw32-make.exe if MinGW was installed properly. And if you installed MSYS you will have make.exe (in the MSYS subfolder probably).
Note that many projects require first creating a makefile (e.g. using a configure script or automake .am file) and it is this step that requires MSYS or cygwin. Makes you wonder why they bothered to distribute the native make at all.
Once you have the makefile, it is unclear if the native executable requires a different path separator than the MSYS make (forward slashes vs backward slashes). Any autogenerated makefile is likely to have unix-style paths, assuming the native make can handle those, the compiled output should be the same.
I have MinGW and also mingw32-make.exe in my bin in the C:\MinGW\bin . same other I add bin path to my windows path. After that I change it's name to make.exe . Now I can Just write command "make" in my Makefile direction and execute my Makefile same as Linux.
First check if mingw32-make is installed on your system.
Use mingw32-make.exe command in windows terminal or cmd to check,
else install the package mingw32-make-bin.
then go to bin directory default ( C:\MinGW\bin) create new file make.bat
#echo off
"%~dp0mingw32-make.exe" %*
add the above content and save it
set the env variable in powershell
$Env:CC="gcc"
then compile the file
make hello
where hello.c is the name of source code
Please learn about automake and autoconf.
Makefile.am is processed by automake to generate a Makefile that is processed by make in order to build your sources.
http://www.gnu.org/software/automake/
I found a very good example here: https://bigcode.wordpress.com/2016/12/20/compiling-a-very-basic-mingw-windows-hello-world-executable-in-c-with-a-makefile/
It is a simple Hello.c (you can use c++ with g++ instead of gcc) using the MinGW on windows.
The Makefile looking like:
EXECUTABLE = src/Main.cpp
CC = "C:\MinGW\bin\g++.exe"
LDFLAGS = -lgdi32
src = $(wildcard *.cpp)
obj = $(src:.cpp=.o)
all: myprog
myprog: $(obj)
$(CC) -o $(EXECUTABLE) $^ $(LDFLAGS)
.PHONY: clean
clean:
del $(obj) $(EXECUTABLE)

First C programm - need help with eclipse

I have install the C/C++ CDT Version of Eclipse. After making a HelloWorld.c file and get the code in there I get an error of "Launch failed. Binary not found".
I found in google that my Eclipse miss the compiler and I install MinGW on my computer and add the path to env variables (tested it with "gcc -v" in cmd and succeded).
1) I can build now, but have no idea how to make a MAKEFILE. - I Read 10 tutorials but don't understand it - ideas?
2) I can build, but not run, I get "Launch failed. Binary not found" - ideas?
Found the error: I never maked a ".c" file -.- after renaming it - works fine.
Revised answer: If you want to avoid writing a real makefile, you can write something like this:
all:
gcc *.c -o runme.exe
You need to specify the binary which gcc outputs (gcc [..] -o <this one>) in the run settings (in the previous example, it should point to runme.exe). Go to Run->Run Configurations, and under C/C++ Application browse and look for runme.exe.
I would, however, strongly advise you to seriously learn about makefile. The beauty of makefiles is that you can use very little features at first and use more and more as you go on (as you saw, writing a "dummy" file was very quick). At first I suggest you write something a bit more "clever" than what I gave you above. Here's a nice tutorial and an example:
all: hello
hello: main.o factorial.o hello.o
g++ main.o factorial.o hello.o -o hello
main.o: main.cpp
g++ -c main.cpp
factorial.o: factorial.cpp
g++ -c factorial.cpp
hello.o: hello.cpp
g++ -c hello.cpp
clean:
rm -rf *o hello
all is what compiles at default. What comes before the : are rule names and after it are the dependencies. i.e, to compile all you need to compile hello (though only if it's been updated), and so forth. the line below the rule is the command to compile. I hope this helps. Please read the tutorial, Makefiles are important.
Add the directory that gcc resides in (C:\MinGW\bin or whatever) to your PATH environment variable and restart Eclipse (important!). This is the process in XP: http://vlaurie.com/computers2/Articles/environment.htm. That should sort it out.
1 I suggest you to take a look at this:
http://www-scf.usc.edu/~csci410/handouts/make.pdf
It's a basic gmake tutorial and should be enough to get you started. But right now, for single file project, I suggest you to just skip creating Makefiles and doing in the command prompt:
gcc -o helloworld.exe helloworld.c
And running your executable in the prompt. You can worry about Makefiles later in your learning curve.
2 How did you setup your project?
Make sure you've got a binary parser selected when you bring up properties for the project. At least in my install, none were checked by default. I needed to check Mach-O 64 parser; you'll need to pick one based on what you're doing. I picked this up from http://www.thexploit.com/tools/os-x-10-6-64-bit-eclipse-cdt-missing-binaries/
I didn't have a binary parser selected, and that seems to mean that CDT can't find anything that it recognizes as a binary. It meant in my case that I just got the "Launch failed. Binary not found" message, even though I specified the exact binary, including a fully-qualified path, in the run/debug configurations.
This has nothing to do with builds, just running/debugging. If you're having a problem building, this probably is irrelevant.

Resources