GCC exiting with an error 1 even with -Wall. No explanation why?

366 Views Asked by At

So I tried to recompile one of my projects from a few weeks ago and to my surprise I keep receiving an error one on it. I used MinGW to compile it originally and Eclipse CDT. I have -Wall flag enabled on GCC so I assumed if it was a problem with the code I would have a more useful information than a make error 1 being thrown. As such, I suspect that the issue could lie in how I formatted the make file. Luckily, I did compile the project when I push the commits last time and the binaries are still in the repo. Nevertheless, I would appreciate some help so that I can continue to improve the project.

Edit: when I do -all, it just refuses to compile.

Here is the makefile. I hope it is a simple as me following some incorrect syntax:

CC=gcc -I../Include -L..\Lib 
override CFLAGS+=-Wall -O3 #$(shell pkg-config --cflags fftw3)
#override LDFLAGS+=#$(shell pkg-config --libs fftw3 glib-2.0) -lm 


.PHONY: all clean

all: lvdoenc lvdodec

lvdoenc: lvdoenc.o lvdomain.o
   $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -I../Include -L../Lib -lfftw3
lvdodec: lvdodec.o lvdomain.o
   $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -I../Include -L../Lib -lfftw3
%.o: %.c
   $(CC) -c $(CFLAGS) -o $@ $^  
lvdoenc.c: lvdocommon.h
lvdodec.c: lvdocommon.h


clean:
   rm -f lvdoenc lvdodec lvdomain.o lvdoenc.o lvdodec.o

Here is a link to my repo: https://github.com/Skylion007/LVDOWin

Update: Using some of the answers I have confirmed that it is GCC that is exiting with an error 1 and I cannot figure out why.

Update2: It's not printing anything to syserr.

4

There are 4 best solutions below

0
On BEST ANSWER

Without a transcript of make's output, when you run it, I can't see why GCC should fail silently, but I can see at least two problems with your makefile:

  • Since you state that you are using MinGW, your target platform must be MS-Windows, on which executable files should be qualified by a .exe extension; thus, your all: lvdoenc lvdodec rule is malformed; it should, at the very least be all: lvdoenc.exe lvdodec.exe[1], (or better, for portability all: lvdoenc$(EXEEXT) lvdodec$(EXEEXT), where you define EXEEXT = .exe for Windows, and leave EXEEXT undefined, or defined to be nothing, for platforms which don't require the extension).

  • Your two rules lvdoenc.c: lvdocommon.h and lvdodec.c: lvdocommon.h are obviously incorrect; the .c files don't depend on the .h, but their respective .o files do. Thus, these two rules should be lvdoenc.o: lvdocommon.h and lvdodec.o: lvdocommon.h respectively.

[1] Of course, you then also need to correctly refer to these two "goals" respectively, as lvdoenc.exe and lvdodec.exe, (or lvdoenc$(EXEEXT) and lvdodec$(EXEEXT)), consistently, throughout the makefile.

There are a few other constructs, within your makefile, which I consider questionable: CC shouldn't really be defined, with the -I../Include or -L..\Lib, (and why inconsistently / in the former, but \ in the latter? Both should be /). Conventionally, -I ... belongs in CPPFLAGS, and -L ... in LDFLAGS, with both CFLAGS and CPPFLAGS passed to the compiler, and normally all of CFLAGS, CPPFLAGS, and LDFLAGS passed to the compiler driver, when invoking the linker, (although, as others have noted in comments, the -I ... settings are strictly necessary when compiling .c to .o, while the -L ... settings are required only in the linking phase).

1
On

the following makefile is more in line with what you need for your project.

However, it does not use:

#$(shell pkg-config --libs fftw3 glib-2.0)

which you will need to re-add.

notice the usage of ':=' when defining macros, so the macro only needs to be evaluated once, rather than every time it is referenced.

the paths for the SHELL macro and the CC macro may need to be modified for your system.

SHELL := /usr/bin/sh

CC := /usr/bin/gcc

#CFLAGS  := -c -Wall -Wextra -pedantic -std=c99 -O3 #$(shell pkg-config --cflags fftw3)
CFLAGS  := -c -Wall -Wextra -pedantic -std=c99 -O3

# override LDFLAGS+=#$(shell pkg-config --libs fftw3 glib-2.0) -lm
LDFLAGS :=


SRCS := $(wildcard *.c)


ENCOBJS := lvdoenc.o lvdomain.o
DECOBJS := lvdodec.o lvdomain.o

.PHONY: all clean

all: lvdoenc lvdodec

lvdoenc: $(ENCOBJS)
    $(CC) $(LDFLAGS) -o $@  $(ENCOBJS) -L../Lib -lfftw3 -lm

lvdodec: $(DECOBJS)
    $(CC) $(LDFLAGS) -o $@ $(DECOBJS)  -L../Lib -lfftw3 -lm

%.o:%.c  lvdocommon.h
    $(CC) -c $(CFLAGS) -c $< -o $@  -I../Include



clean:
    rm -f lvdoenc lvdodec lvdomain.o lvdoenc.o lvdodec.o
0
On

Apparently, all that was the cause was that I had uninstalled the 64bit version of MinGW and tried to switch to the 32bit version of MinGW. Unfortunately, some of the libraries would not compile in the 32bit version so I just used MinGW-w instead to solve this problem. It turns out GCC was not starting due to a linker error, but this error was not proportionating and could not be discovered until I tried to run it from the Windows terminal. I am still in the process of solving it and will update this answer when I have fully solved the issue.

0
On

Had the same problem while tried to compile my project with make from MSys. Accidentally problem had been solved, after I added a quotes to gcc input and output files in the makefile. I don't know how it works, but hope that it will help someone else. So in the TS example code should look like this

    %.o: %.c
   $(CC) -c $(CFLAGS) -o "$@" "$^" 

PS: had no problems with building project from ubuntu terminal though, so maybe it's just a msys problem.