C make file is really confusing me - command-line

I'm working on learning C from a family member who's very adept as far as I know.
I'm using MingW on windows 7 with a fresh install of windows and having some difficulties getting things to work properly. I've made a make file and am using Deitel C for programmers with an introduction to C11, and have typed up the examples from the book in chapter three. I'm fairly certain I've managed to get that portion correct, and the makefile I'm using seems to be correct but it gives me a strange error that I don't understand.
C -o ex01 -O3 -Wall -Werrors -static -pedantic-errors -g main.o
make: C: Command not found
make: * [ex01] Error 127
this is the exact error I keep getting, I'm not sure if there's something wrong with the makefile or if it's something wrong with settings...
RM=rm
CC=gcc
LINK=$CC
CFLAGS = -O3 -Wall -Werrors -static -pedantic-errors -g
all: main.o ex01
clean:
(Tab)$(RM) -f main.o ex01.exe
main.o: main.c
(Tab)$(CC) -o main.o $(CFLAGS) -c main.c
ex01: main.o
(Tab)$(LINK) -o ex01 $(CFLAGS) main.o
this is almost exactly the makefile I'm using, asside from the (Tab) in place of actual tabs. I hope this is enough information to get some help, I suspect it's something wrong with my settings, I've had to set up paths to my library and gcc location. I'm just not sure where else to set up a path that could rectify this error.

#Keltar's comment nailed it exactly: LINK=$CC should be LINK=$(CC).
In make's syntax, $() is the proper way to deference a variable. The line LINK=$(CC) means set the variable LINK to whatever the CC variable is set to. After that instruction, their values will be the same.

Related

How to get a clean CDT Build Console Output?

I'm working with STM32CubeIDE using gcc compiler. In the build output I have to search for warnings and errors in a hundred lines of compiler-output infos. I'm explicitly interested in all warnings and errors! But I do not need something like this as there isn't any warning or error:
(Useful information)
arm-none-eabi-gcc "../gmem/wdog.c"
(followed by 912 useless bytes)
-mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DNUCLEO -DUSE_HAL_DRIVER -DSTM32F446xx -DUSE_FULL_LL_DRIVER -c -I"E:/STM32CubeIDE_11/fatl22_lcd/Ampel" -I../Core/Inc -I"E:/STM32CubeIDE_11/fatl22_lcd/lcd" -I"E:/STM32CubeIDE_11/fatl22_lcd/rtc" -I"E:/STM32CubeIDE_11/fatl22_lcd/so" -I"E:/STM32CubeIDE_11/fatl22_lcd/uart" -I"E:/STM32CubeIDE_11/fatl22_lcd/interrupts" -I"E:/STM32CubeIDE_11/fatl22_lcd/gmem" -I../Drivers/STM32F4xx_HAL_Driver/Inc -I"E:/STM32CubeIDE_11/fatl22_lcd/debugpins" -I"E:/STM32CubeIDE_11/fatl22_lcd/funk" -I"E:/STM32CubeIDE_11/fatl22_lcd/kabel" -I"E:/STM32CubeIDE_11/fatl22_lcd/scheduler" -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -Wconversion -fstack-usage -MMD -MP -MF"gmem/wdog.d" -MT"gmem/wdog.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "gmem/wdog.o"
How can I get rid of this crap ?
I searched for gcc option help files and some "how to increase verbosity" hoping to find the contrary ;-) .
I found explicit help for reducing warnings, which is not my intention.

How to make a Linux Makefile work on Windows?

(Disclaimer: I am not at all a computer science genius, far from that. I may use bad terminology and I appologize.)
I need to run some tests using the google test library and I was provided with a Makefile to handle the execution but it won't run on my Windows machine (I use Visual Studio). It was made for a Linux environment so I'm not sure what i would need to modify in order to run it. I have used MinGW to run Makefiles of my own making in the past.
Here's how the Makefile looks like:
CC=g++
CFLAGS=-c -Wall -ggdb -I.
LDFLAGS=
SOURCES=main.c singlelinklist.c
TESTS=single_test.cpp
#TODO: Need a more elegant way of specifying objects and tests
GTESTDIR=~/environment/googletest
OBJECTS=$(SOURCES:.cpp=.o)
FLAGS = -Iinclude
#all: $(SOURCES) $(EXECUTABLE)
# These next lines do a bit of magic found from http://stackoverflow.com/questions/2394609/makefile-header-dependencies
# Essentially it asks the compiler to read the .cpp files and generate the needed .h dependencies.
# This way if any .h file changes the correct .cpp files will be recompiled
depend: .depend
.depend: $(SOURCES)
rm -f ./.depend
$(CC) $(CFLAGS) -MM $^ >> ./.depend;
include .depend
# End .h file magic
#$(EXECUTABLE): $(OBJECTS)
# $(CC) $(LDFLAGS) $(OBJECTS) -o $#
#.cpp.o:
# $(CC) $(CFLAGS) $< -o $#
clean:
# rm -rf *o $(EXECUTABLE) test_executable
rm -f ./.depend
rm $(GTESTDIR)/libgtest.a
rm $(GTESTDIR)/gtest-all.o
# Google test section
$(GTESTDIR)/libgtest.a:
$(CC) -isystem $(GTESTDIR) -I $(GTESTDIR) -pthread -c $(GTESTDIR)/gtest/gtest-all.cc -o $(GTESTDIR)/gtest-all.o
ar -rv $(GTESTDIR)/libgtest.a $(GTESTDIR)/gtest-all.o
# This will also recompile if any source file is changed.
test_executable: $(GTESTDIR)/libgtest.a $(TESTS) depend
$(CC) -isystem $(GTESTDIR) -pthread -ggdb $(TESTS) $(GTESTDIR)/gtest/gtest_main.cc $(GTESTDIR)/libgtest.a -o test_executable
test: test_executable
./test_executable --gtest_print_time=0
And here's how my workspace is structured.
(Seems like I can't embed pictures).

gcc command line structure arguments

I try to compile a c file with gcc version 6.3.0 20170516 (Raspbian 6.3.0-18+rpi1+deb9u1).
I run the compiler in the source file's folder, but I keep getting the 'file not found' error message for the last argument ('bcm2835').
gcc -o gpio -l rt /home/pi/bcm2835-1.15/src/bcm2835.c -l bcm2835
/usr/bin/ld: cannot find -lbcm2835
collect2: error: ld returned 1 exit status
AFAIK, The gcc does not specify the third argument, I have no idea what this 3rd argument is used for and where to find it.
If I omit that argument, I get several error lines, each for one of the internal commands, like:
undefined reference to bcm2835_init
I also wish to know what the rt stands for. I could not find it in the official gcc docs.
Thanks
After -l, there should be no space. So it should be -lrt (not -l rt) and it should be -lbcm2835 (not -l bcm2835).
You need to add a linker search path with -L (uppercase L) right before calling -lbcm2835.
The input file should usually be last (that's the argument ending with main.c). That would be
gcc -o main -lrt -lbcm2835 /home/pi/bcm2835-1.15/main.c
-l links a library to the program. -L sets the library search path such that -l will find the libraries specified.
See this page for details on -l and -L.

Error in Makefile calling sed with comment character

I'm trying to build lstrip, a Lua utility for compressing Lua source code. I'm trying to build for Lua 5.1.3 on OS X v10.10.3.
I have downloaded and extracted the Lua 5.1.3 source code and modified the Makefile for lstrip to point to this directory. However, when I run make, I get this output:
cc -I/usr/local/src/lua-5.1.3/src -I/usr/local/src/lua-5.1.3/src -O2 -Wall -Wextra -O2 -c -o lstrip.o lstrip.c
lstrip.c:33:14: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char* argv[])
^
1 warning generated.
sed '/void luaX_next/i#include "proxy.c"' /usr/local/src/lua-5.1.3/src/llex.c > llex.c
sed: 1: "/void luaX_next/i#inclu ...": command i expects \ followed by text
make: *** [llex.c] Error 1
This is what the relevant Makefile command looks like:
llex.c:
sed '/void luaX_next/i#include "proxy.c"' $(LUASRC)/$# > $#
I think that this is because the # in the sed command is being treated like an actual comment, but I'm not sure.
How can I fix the Makefile, or manually run the steps, to get lstrip built?
Full copy of the Makefile follows, in case it matters:
# makefile for lstrip
# change these to reflect your Lua installation (Lua 5.1!)
LUA= /usr/local/src/lua-5.1.3
LUAINC= $(LUA)/src
LUALIB= $(LUA)/src
LUASRC= $(LUA)/src
# no need to change anything below here
CFLAGS= $(INCS) $(WARN) -O2 $G
WARN= -O2 -Wall -Wextra
INCS= -I$(LUAINC) -I$(LUASRC)
LIBS= -L$(LUALIB) -llua -lm
MYNAME= lstrip
MYLIB= $(MYNAME)
T= $(MYNAME)
OBJS= $(MYNAME).o llex.o
TEST= test.lua
all: test
test: $T
$T $(TEST)
$T: $(OBJS)
$(CC) -o $# $(OBJS) $(LIBS)
llex.c:
sed '/void luaX_next/i#include "proxy.c"' $(LUASRC)/$# > $#
llex.o: proxy.c
clean:
-rm -f $(OBJS) core core.* a.out $(MYNAME)
# eof
Hand-build solution:
cp /usr/local/src/lua-5.1.3/src/llex.c .
Hand-edit llex.c to add the line #include "proxy.c" before the line starting with void luaX_next (line 446 for me).
Now run make, which will succeed.
You can find the answer in the sed manual, and it is in the Makefile lines
llex.c:
sed '/void luaX_next/i#include "proxy.c"' $(LUASRC)/$# > $#
Some variable expansion takes place here:
$(LUASRC) is expanded to the variable set above -> $(LUA)/src. Recurse as needed.
$# is replaced with the current target (llex.c)
So this recipe says:
In order to obtain the target llex.c (which will be processed later through other recipes), apply a stream editing command to the file $LUASRC/llex.c and write it to llex.c.
The stream editing command is: look for text "void luaX_next", before printing it, insert line "#include "proxy.c"".
Problem is, the command to do this is not "i" but "i\(newline)", which conflicts with a requirement of Makefiles that recipes must be on a single line.
I suspect that in order to fix your Makefile you need to use a different command than sed; awk can fit the bill although it's a bit more complex.
This line works in Mac OS X and in Linux:
sed '/void luaX_next/{h;s/.*/#include "proxy.c"/;p;g;}' $(LUASRC)/$# > $#

Not able to link libsvn_delta-1.a when compiling svn_swig_perl in msys

Trying to compile perl svn binding for msys. But when compiling the swig perl lib_core.dll it complains reference not found for _svn_delta_noop_window_handler and _svn_delta_default_editor in libsvn_swig_perl-1.a. Both function coming from libsvn_delta-1.a.
I should recompile and make sure the libsvn_swig_perl-1.a properly link with libsvn_delta-1.a? Or it doesn't matter as long as during building lib_core.dll it can link the missing static library?
I really have no idea how to solve this issue.
below are the full log when compile the lib_core.dll:
ld2 -s core.o -o blib/arch/auto/SVN/_Core/_Core.dll \
/usr/lib/perl5/5.8.8/msys/CORE/libperl.dll.a -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/bindings/swig/perl/libsvn_swig_perl/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_client/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_delta/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_repos/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_wc/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_diff/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_subr/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_local/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_svn/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_neon/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs_util/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs_fs/.libs -lsvn_client-1 -lsvn_delta-1 -lsvn_fs-1 -lsvn_ra-1 -lsvn_repos-1 -lsvn_wc-1 -lsvn_diff-1 -lsvn_subr-1 -lsvn_fs_util-1 -lsvn_swig_perl-1 -lapr-1 -lintl -lz -laprutil-1 -lexpat -lperl -L/lib/perl5/5.8.8/msys/CORE \
gcc -shared -o _Core.dll -Wl,--out-implib=lib_Core.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--stack,8388608 -Wl,--enable-auto-image-base \
-s core.o /usr/lib/perl5/5.8.8/msys/CORE/libperl.dll.a -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/bindings/swig/perl/libsvn_swig_perl/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_client/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_delta/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_repos/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_wc/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_diff/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_subr/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_local/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_svn/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_neon/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs_util/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs_fs/.libs -lsvn_client-1 -lsvn_delta-1 -lsvn_fs-1 -lsvn_ra-1 -lsvn_repos-1 -lsvn_wc-1 -lsvn_diff-1 -lsvn_subr-1 -lsvn_fs_util-1 -lsvn_swig_perl-1 -lapr-1 -lintl -lz -laprutil-1 -lexpat -lperl -L/lib/perl5/5.8.8/msys/CORE
Creating library file: lib_Core.dll.a
/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/bindings/swig/perl/libsvn_swig_perl/.libs/libsvn_swig_perl-1.a(swigutil_pl.o.b): In function `thunk_apply_textdelta':
/usr/src/subversion16/subversion-1.6.17-3-msys-src/subversion-1.6.17/subversion/bindings/swig/perl/libsvn_swig_perl/swigutil_pl.c:703: undefined reference to `_svn_delta_noop_window_handler'
/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/bindings/swig/perl/libsvn_swig_perl/.libs/libsvn_swig_perl-1.a(swigutil_pl.o.b): In function `svn_delta_make_editor':
/usr/src/subversion16/subversion-1.6.17-3-msys-src/subversion-1.6.17/subversion/bindings/swig/perl/libsvn_swig_perl/swigutil_pl.c:785: undefined reference to `_svn_delta_default_editor'
collect2: ld returned 1 exit status
perlld: *** system() failed to execute
gcc -shared -o _Core.dll -Wl,--out-implib=lib_Core.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--stack,8388608 -Wl,--enable-auto-image-base \
-s core.o /usr/lib/perl5/5.8.8/msys/CORE/libperl.dll.a -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/bindings/swig/perl/libsvn_swig_perl/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_client/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_delta/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_repos/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_wc/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_diff/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_subr/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_local/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_svn/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_ra_neon/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs_util/.libs -L/usr/src/subversion16/subversion-1.6.17-3-msys-src/bld/subversion/libsvn_fs_fs/.libs -lsvn_client-1 -lsvn_delta-1 -lsvn_fs-1 -lsvn_ra-1 -lsvn_repos-1 -lsvn_wc-1 -lsvn_diff-1 -lsvn_subr-1 -lsvn_fs_util-1 -lsvn_swig_perl-1 -lapr-1 -lintl -lz -laprutil-1 -lexpat -lperl -L/lib/perl5/5.8.8/msys/CORE
My question already answer by other post. Its the linker order issue. Check the answer below:
Linker order
I just need to move around the linker for svn_swig_perl to link it before svn_delta to solve the problem.