If I run this script: (Note: edited to reflect answer 1)
#!/usr/bin/env zsh
setopt shwordsplit
if [[ -f $1 ]]
then
echo "will compile $1"
else
echo "ERROR: $1 NOT found"
exit 1
fi
gcc_options=" -c -std=c99 -Wall -Wextra "
echo "gcc_options: ${gcc_options}"
gcc " ${=gcc_options} " " ${=1} "
if [[ $? -eq 0 ]]
then
echo "gcc compile worked"
else
echo "error in gcc compile"
fi
gcc "${=gcc_options}" "${=1}"
if [[ $? -eq 0 ]]
then
echo "gcc compile worked"
else
echo "error in gcc compile"
fi
Both compiles fail.
Output is:
will compile my_file.c
gcc_options: -c -std=c99 -Wall -Wextra
gcc: error: : No such file or directory
gcc: error: : No such file or directory
gcc: error: my_file.c : No such file or directory
gcc: fatal error: no input files compilation terminated.
error in gcc compile
gcc: error: : No such file or directory
gcc: error: : No such file or directory
error in gcc compile
First change:
gcc " $gcc_options $1"
To:
gcc "$gcc_options" "$1"
If some of these variables contain multiple words, you may need to turn on shwordsplit (see here), which can also be done on a per variable basis (${=VAR}).
gcc "${=gcc_options}" "${=1}"
Update
I made a mistake, you definitely don't want quotes on $gcc_options, so it should probably be ${=gcc_options}. If you need to quote $1 depends if $1 contains spaces. So this should do:
gcc ${=gcc_options} $1
Related
I am using ninja to build a program for the first time. I run the command ninja from the cmd but get the error:
ninja: error: build.ninja:3: lexing error
What is the issue?
Here is my build.ninja file:
rule compile
command = gcc -Wall -c $in -o $out
rule link
command = gcc $in -o $out
build hello.o: compile main.c
build hello: link hello.o `
and here is main.c:
int main() {
printf("Hello world\n");
return 0;
}
I'am starting using Linux and I have some trouble using some stm32f4 libraries for my project gcc-testing.
All the CMSIS programs needed are inside the STM32F4_Discovery_FW_V1.1.0 and the project is arranged like this:
~
|__
| |
| STM32F4XX
| |
src STM32F4_Discovery_FW_V1.1.0
|
ggc-testing
|
makefile
main.c
stm32f4xx_config.h
stm32_flash.ld
system_stm32f4xx.c
The main.c and the system_stm32f4xx.c use the stm32f4xx.h file that is inside the STM32F4_Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Include
The error I get from the terminal is:
Make file console error
My make file:
PROJ_NAME=main
STM_DIR=~/STM32F4XX/STM32F4-Discovery_FW_V1.1.0
STM_SRC = $(STM_DIR)/Libraries/STM32F4xx_StdPeriph_Driver/src
vpath %.c $(STM_SRC)
SRCS = main.c
SRCS += system_stm32f4xx.c
SRCS += $(STM_DIR)/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/TrueSTUDIO/startup_stm32f4xx.s
INC_DIRS = $(STM_DIR)/Utilities/STM32F4-Discovery
INC_DIRS += $(STM_DIR)/Libraries/CMSIS/Include
INC_DIRS += $(STM_DIR)/Libraries/CMSIS/ST/STM32F4xx/Include
INC_DIRS += $(STM_DIR)/Libraries/STM32F4xx_StdPeriph_Driver/inc
INC_DIRS += .
TOOLS_DIR = /opt/gcc-arm-embedded/gcc-arm-none-eabi-4_7-2013q1/bin
CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
GDB = arm-none-eabi-gdb
INCLUDE = $(addprefix -I,$(INC_DIRS))
DEFS = -DUSE_STDPERIPH_DRIVER
CFLAGS = -ggdb
CFLAGS += -O0
CFLAGS += -Wall -Wextra -Warray-bounds
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
LFLAGS = -Tstm32_flash.ld
.PHONY: $(PROJ_NAME)
$(PROJ_NAME): $(PROJ_NAME).elf
$(PROJ_NAME).elf: $(SRCS)
$(CC) $(INCLUDE) $(DEFS) $(CFLAGS) $(LFLAGS) $^ -o $#
$(OBJCOPY) -O ihex $(PROJ_NAME).elf $(PROJ_NAME).hex
$(OBJCOPY) -O binary $(PROJ_NAME).elf $(PROJ_NAME).bin
clean:
rm -f *.o $(PROJ_NAME).elf $(PROJ_NAME).hex $(PROJ_NAME).bin
# Flash the STM32F4
flash:
st-flash write $(PROJ_NAME).bin 0x8000000
.PHONY: debug
debug:
# before you start gdb, you must start st-util
$(GDB) $(PROJ_NAME).elf
Hope enyne can help with this.
After gnu make generates a cmd-line (eg gcc), use of a ~ would rely on make executing a shell and the shell expanding an arg with a leading unquoted ~. Based on your line with $(addprefix, try adding a space between -I and ,$(INC_DIRS)
However, the overhead from executing a shell can be undesirable and the extra exec is often easy to avoid; for this case, replace ~ with $(HOME)
Example Makefile :
SUBDIR := some/incdir
TILDE_SUBDIR := ~/$(SUBDIR)
NOT_DELIM := $(addprefix -I,$(TILDE_SUBDIR))
DELIM_INC := $(addprefix -I ,$(TILDE_SUBDIR))
HOME_SUBDIR := $(HOME)/$(SUBDIR)
PHONY: all
all:
#echo NOT_DELIM $(NOT_DELIM)
#echo DELIM_INC $(DELIM_INC)
#echo HOME_SUBDIR $(HOME_SUBDIR)
Output :
NOT_DELIM -I~/some/incdir
DELIM_INC -I /home/user1/some/incdir
HOME_SUBDIR /home/user1/some/incdir
I have the following makefile:
#.SUFFIXES:
#.SUFFIXES: .F90 .cuf .o
ROOT = /home/ccevallos/finalMIT
SRCDIR := $(ROOT)/external/lib_eigesolve
#F90SRC = $(notdir $(wildcard $(SRCDIR)/*.F90))
#F90OBJS = $(patsubst %.F90,%.o,$(F90SRC))
F90OBJS = eigsolve_vars.o toolbox.o zhegst_gpu.o zhemv_gpu.o zhetd2_gpu.o zhetrd_gpu.o zheevd_gpu.o zhegvdx_gpu.o \
dsygst_gpu.o dsymv_gpu.o dsytd2_gpu.o dsytrd_gpu.o dsyevd_gpu.o dsygvdx_gpu.o
#CUFSRC = $(notdir $(wildcard $(SRCDIR)/*.cuf))
#CUFOBJS = $(patsubst %.cuf,%.o,$(CUFSRC))
CUFOBJS = cusolverDn_m.o
FLAGS = -O3 -mp -pgf90libs -Mcuda=cc60,cuda9.1,ptxinfo -Mlarge_arrays
FLAGS2 = -O3 -mp -pgf90libs -Mcuda=cc60,cuda9.1,ptxinfo,maxregcount:64 -Mlarge_arrays
FLAGS3 = -O3 -mp -pgf90libs -Mcuda=cc60,cuda9.1,ptxinfo,nordc,maxregcount:255 -Mlarge_arrays
.PHONY: all
all: lib_eigsolve.a
zhetd2_gpu.o : zhetd2_gpu.F90
pgf90 -c ${FLAGS2} ${OPTFLAGS} $*.F90 -o $*.o
zhemv_gpu.o : zhemv_gpu.F90
pgf90 -c ${FLAGS3} ${OPTFLAGS} $*.F90 -o $*.o
dsytd2_gpu.o : dsytd2_gpu.F90
pgf90 -c ${FLAGS2} ${OPTFLAGS} $*.F90 -o $*.o
dsymv_gpu.o : dsymv_gpu.F90
pgf90 -c ${FLAGS3} ${OPTFLAGS} $*.F90 -o $*.o
cusolverDn_m.o: cusolverDn_m.cuf
pgf90 -c ${FLAGS} ${OPTFLAGS} $*.cuf -o $*.o
%.o: %.F90
pgf90 -c ${FLAGS} ${OPTFLAGS} $*.F90 -o $*.o
lib_eigsolve.a: $(F90OBJS) $(CUFOBJS)
ar rcs $# $^
PHONY: clean
clean:
rm -f lib_eigsolve.a *.mod *.o
This makefile compiles perfectly well, however I basically want to uncomment the lines with # to make this simpler, but when I do that only
ar rcs lib_eigsolve.a
appears in the terminal, with no object file created, and thus lib_eigsolve.a is empty...
Why is it not compiling the object files?
P.S. You can find this Makefile with some modifications here https://github.com/NVIDIA/Eigensolver_gpu
You have a simple typo in $(SRCDIR): the source directory inside Eigensolver_gpu is called lib_eigsolve not lib_eigesolve.
$ cd ~workarea/playground
$ git clone https://github.com/NVIDIA/Eigensolver_gpu.git
$ ls Eigensolver_gpu/
lib_eigsolve LICENSE README.md test_driver
I then proceeded to create a dummy makefile by copy & pasting the relevant lines from your question:
ROOT := $(HOME)/workarea/playground/Eigensolver_gpu
ifndef FIXED
SRCDIR := $(ROOT)/lib_eigesolve
else
SRCDIR := $(ROOT)/lib_eigsolve
endif
F90SRC = $(notdir $(wildcard $(SRCDIR)/*.F90))
$(info F90SRC '$(F90SRC)')
F90OBJS = $(patsubst %.F90,%.o,$(F90SRC))
$(info F90OBJS '$(F90OBJS)')
CUFSRC = $(notdir $(wildcard $(SRCDIR)/*.cuf))
$(info CUFSRC '$(CUFSRC)')
CUFOBJS = $(patsubst %.cuf,%.o,$(CUFSRC))
$(info CUFOBJS '$(CUFOBJS)')
lib_eigsolve.a: $(F90OBJS) $(CUFOBJS)
echo ar rcs $# $^
Test runs:
$ make
F90SRC ''
F90OBJS ''
CUFSRC ''
CUFOBJS ''
echo ar rcs lib_eigsolve.a
ar rcs lib_eigsolve.a
$ make FIXED=1
F90SRC 'dsyevd_gpu.F90 ... zhemv_gpu.F90'
F90OBJS 'dsyevd_gpu.o ... zhemv_gpu.o'
CUFSRC 'cusolverDn_m.cuf'
CUFOBJS 'cusolverDn_m.o'
make: *** No rule to make target 'dsyevd_gpu.o', needed by 'lib_eigsolve.a'. Stop.
Ensure that $(SRCDIR) has no spaces:
SRCDIR := $(strip ${SRCDIR})
ifneq (1,$(words ${SRCDIR}))
$(error Not without further fiddling, friend)
endif
Specifying the path in the wildcard expression looks strange. When you are executing make directly in the srcdir (make -C lib_eigsolve), you should write
F90SRC = $(notdir $(wildcard *.F90))
or
srcdir = .
F90SRC = $(notdir $(wildcard ${srcdir}/*.F90))
when you want to keep your option for out-of-tree builds.
For instance, from variable:
files = dirx/a.cc diry/b.cc dirz/b.cc
I want to effectively have these rules: (without resorting to define/eval)
a_a.o: dirx/a.cc
b_b.o: diry/b.cc
c_c.o: dirz/c.cc
The problem seems unlikely, but this makefile does what you want:
Makefile
VPATH := dirx:diry:dirz
SRCS := a.cc b.cc c.cc
OBJS := $(foreach src,$(SRCS),$(basename $(src))_$(basename $(src)).o)
.PHONY: all clean
.SECONDEXPANSION:
%.o: $$(basename $$(subst _,.,$$*)).cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $# $<
all: $(OBJS)
clean:
rm -f $(OBJS)
With directories and files set up as per your example:
$ ls -R
.:
dirx diry dirz Makefile
./dirx:
a.cc
./diry:
b.cc
./dirz:
c.cc
it runs like:
$ make
g++ -c -o a_a.o dirx/a.cc
g++ -c -o b_b.o diry/b.cc
g++ -c -o c_c.o dirz/c.cc
Cribs: -
VPATH
foreach
basename
subst
.SECONDEXPANSION
Error in invoking target 'install' of makefile '/u01/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ins_ctx.mk'. See '/u01/app/oraInventory/logs/installActions2015-02-28_02-22-27AM.log' for details.
I get the above error when I run the installer of Oracle 11g release 2
The log is as follows
INFO: gcc -o ctxhx -m64 -L/u01/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ -L/u01/app/oracle/product/11.2.0/dbhome_1/lib/ -L/u01/app/oracle/product/11.2.0/dbhome_1/lib/stubs/ /u01/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ctxhx.o -L/u01/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ -lm -ldl -lsc_ca -lsc_fa -lsc_ex -lsc_da -lsc_ut -lsc_ch -lsc_fi -lctxhx -lc -Wl,-rpath,/u01/app/oracle/product/11.2.0/dbhome_1/ctx/lib -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lxml11 -lcore11 -lunls11 -ls
INFO: nls11 -lnls11 -lcore11 -lnls11
INFO: /usr/bin/ld: /u01/app/oracle/product/11.2.0/dbhome_1/lib//libcore11.a(sslss.o): undefined reference to symbol 'pthread_sigmask##GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
INFO: collect2: error: ld returned 1 exit status
INFO: make: *** [ctxhx] Error 1
INFO: End output from spawned process.
INFO: ----------------------------------
INFO: Exception thrown from action: make
Exception Name: MakefileException
Exception String: Error in invoking target 'install' of makefile '/u01/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ins_ctx.mk'. See '/u01/app/oraInventory/logs/installActions2015-02-28_02-22-27AM.log' for details.
Please help me fix this... Thanks in advance.
Try to link with g++ instead of gcc.
cd /bin
mv gcc gcc.save
ln -s g++ gcc
and run the installer again.
Create the following script the run it a root during install the click retry
# Fix ctx/lib/ins_ctx.mk
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
cat << __EOF__ > /tmp/memcpy_wrap.c
#include <stddef.h>
#include <string.h>
asm (".symver wrap_memcpy, memcpy#GLIBC_2.14");
void *wrap_memcpy(void *dest, const void *src, size_t n) {
return memcpy(dest, src, n);
}
__EOF__
if [[ -e "${ORACLE_HOME}/ctx/lib/ins_ctx.mk" ]]; then
sed -i -e 's/\$(INSO_LINK)/\$(INSO_LINK) -Wl,--wrap=memcpy_wrap \$(ORACLE_HOME)\/ctx\/lib\/memcpy_wrap.o/g' ${ORACLE_HOME}/ctx/lib/ins_ctx.mk
gcc -c /tmp/memcpy_wrap.c -o ${ORACLE_HOME}/ctx/lib/memcpy_wrap.o && rm /tmp/memcpy_wrap.c
fi