I am writing CUDA code and am using the following Makefile to compile and link it together.
DEBUG = TRUE
CUDA_PATH = /usr/local/cuda
INC_DIR = ../include
ICC = -I/usr/include -I$(INC_DIR) -I$(CUDA_PATH)/include
LIB_CUDA = -L$(CUDA_PATH)/lib64
NVCC = $(CUDA_PATH)/bin/nvcc
LINT = cppcheck
LINK = $(NVCC)
CXX = g++
C_SOURCES = main.c
CUDA_SOURCES = cuda_r_lib.cu
EXE = r_lib
OBJS = main.o
CUDA_OBJS = cuda_r_lib.o
HFILES = $(INC_DIR)/r_lib.h
MAKEFILE = Makefile
REBUILDABLES = $(CUDA_OBJS) $(OBJS) r_lib
LFLAGS = -lcuda $(LIB_CUDA)
ifdef DEBUG
CFLAGS = -Wall -ggdb -pthread -fPIC -O3
CDEFINES = $(ICC)
CUDA_FLAGS = -arch=sm_20 $(ICC)
else
CFLAGS = -Wall -pthread -fPIC -O3
CDEFINES = $(ICC) -DNDEBUG=1
CUDA_FLAGS = -arch=sm_20 $(ICC)
endif
$(EXE): $(OBJS) $(CUDA_OBJS)
$(LINK) $(LFLAGS) $(OBJS) $(CUDA_OBJS) -o $(EXE)
$(OBJS): $(C_SOURCES) $(HFILES) $(MAKEFILE)
$(CXX) $(CDEFINES) $(CFLAGS) -c $(C_SOURCES) -o $#
$(CUDA_OBJS): $(CUDA_SOURCES) $(HFILES) $(MAKEFILE)
$(NVCC) $(CUDA_FLAGS) -c $(CUDA_SOURCES) -o $#
clean:
rm -f *~ $(REBUILDABLES) *ii core
lint:
$(LINT) --enable=all --inconclusive --std=posix *.c *.cu
I've got to the point where my code compiles and links cleanly. But the binary ./r_lib doesn't execute. I can't even change its permissions (tried chmod +x ...)
Here's what I get:
rinka#rinka-Desktop:/media/rinka/CUDA/dev/code$ make
g++ -I/usr/include -I../include -I/usr/local/cuda/include -Wall -ggdb -pthread -fPIC -O3 -c main.c -o main.o
/usr/local/cuda/bin/nvcc -arch=sm_20 -I/usr/include -I../include -I/usr/local/cuda/include -c cuda_r_lib.cu -o cuda_r_lib.o
/usr/local/cuda/bin/nvcc -lcuda -L/usr/local/cuda/lib64 main.o cuda_r_lib.o -o r_lib
rinka#rinka-Desktop:/media/rinka/CUDA/dev/code$ ll ./r_lib
-rw------- 1 rinka rinka 552223 Nov 6 19:08 ./r_lib
rinka#rinka-Desktop:/media/rinka/CUDA/dev/code$ file r_lib
r_lib: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=8f2b88bf570a5d74c2c237969a93519f64636b86, not stripped
rinka#rinka-Desktop:/media/rinka/CUDA/dev/code$ ./r_lib
bash: ./r_lib: Permission denied
rinka#rinka-Desktop:/media/rinka/CUDA/dev/code$ chmod +x ./r_lib
rinka#rinka-Desktop:/media/rinka/CUDA/dev/code$ ./r_lib
bash: ./r_lib: Permission denied
rinka#rinka-Desktop:/media/rinka/CUDA/dev/code$ ll ./r_lib
-rw------- 1 rinka rinka 552223 Nov 6 19:08 ./r_lib
I can't for the life of me figure out what I'm doing wrong - maybe I'm just tired. I looked at: gcc compiled binaries give "cannot execute binary file" but I'm not using the -c option while linking...
Also - any feedback on the compiler & linker options for nvcc that will help throw up warnings more rigorously will be very welcome. I'm not really satisfied with the warnings I got so far.
This is not a message from your compiler or build-tool, but from your shell and originates from the OS.
For the path /media/, it seems you have your files on external storage e.g. an USB-stick. That might be mounted with option noexec, so you cannot execute from there. Also, if that is VFAT, there are no permission-flags in the, so you cannot set them. Instead default flags are used by the OS and might also prevent execution a program from that partition. This is a security measure against malware.
Try mount and check options.
If I'm right, you should move the files to a normal filesystem, e.g. your home.
Related
When trying to compile my c code I keep getting basic.c:5:10: fatal error: 'fftw3.h' file not found. I am compiling my c code using MacOS terminal and have Xcode installed.
I'm trying to write some c code which uses the fftw-3 library. fftw-3 has been installed using sudo port install fftw-3 and I have entered port contents fftw-3 which returned:
/opt/local/include/dfftw.h
/opt/local/include/dfftw_threads.h
/opt/local/include/drfftw.h
/opt/local/include/drfftw_threads.h
/opt/local/include/fftw_f77.i
/opt/local/lib/libdfftw.2.dylib
/opt/local/lib/libdfftw.a
/opt/local/lib/libdfftw.dylib
/opt/local/lib/libdfftw_threads.2.dylib
/opt/local/lib/libdfftw_threads.a
/opt/local/lib/libdfftw_threads.dylib
/opt/local/lib/libdrfftw.2.dylib
/opt/local/lib/libdrfftw.a
/opt/local/lib/libdrfftw.dylib
/opt/local/lib/libdrfftw_threads.2.dylib
/opt/local/lib/libdrfftw_threads.a
/opt/local/lib/libdrfftw_threads.dylib
/opt/local/share/info/fftw.info
/opt/local/share/info/fftw.info-1
/opt/local/share/info/fftw.info-2
/opt/local/share/info/fftw.info-3
/opt/local/share/info/fftw.info-4
/opt/local/share/info/fftw.info-5
I have been using a makefile and am trying to work out what needs including in it. At the moment I have:
# define the name of your source file(s)
SRCS = basic.c
# define the name of the object files(s) - we can do this automatically
OBJS = $(SRCS:.c=.o)
# tell MAKE which compiler to use
CCOMP = gcc
# flags for the compiler
# don't forget the -O3
CFLAGS = -Wall -O3 -fstrict-aliasing -Iinclude
#CFLAGS = -c -Wall -Iinclude
# flags for the linker. note -lm for the math library
LDFLAGS = -O3 -lm -L/opt/lib -I/opt/lib -L/opt/local/include -I/opt/lib
# the name of your executable file (the target) - here we put it in the top directory
TARGET = basic
# actions
all: $(OBJS)
$(CCOMP) -o $(TARGET) $(OBJS) $(LDFLAGS)
%.o: %.c
$(CCOMP) -c -o $# $< $(CFLAGS)
# delete all objects and target
clean:
rm -f $(OBJS) $(TARGET)
I'm not sure if the #CFLAGS and #LDFLAGS sections are correct? I would appreciate troubleshooting and any advice on what I need to do to get this working. Thanks!
I am trying to use the Command Transmission Interface from the Trusted Software Stack for the TPM 2.0 and I cannot seem to get this library loaded. Any use gives an "undefined reference" error.
Had the same problem when using the ESAPI from TSS as well and fixed it with the following flag in my Makefile: TPMFLAGS =-L=/usr/local/lib/ -ltss2-esys.
Following is my Makefile in its current implementation:
CC = gcc
CFLAGS = -std=c99 -Wall -I$(IDIR)
TPMFLAGS =-L=/usr/local/lib/ -ltss2-esys -ltss2-tcti-device
IDIR = ./includes/
SRCDIR = ./src/
BINDIR = ./bin/
SOURCES = $(SRCDIR)*.c
all: $(BINDIR)antiEvilMaid
$(BINDIR)antiEvilMaid: $(BINDIR)main.o $(BINDIR)errors.o
$(CC) $(BINDIR)main.o $(BINDIR)errors.o $(TPMFLAGS) -o $#
$(BINDIR)main.o: $(SRCDIR)main.c $(IDIR)main.h
$(CC)$(CFLAGS) -c $(SRCDIR)main.c -o $#
$(BINDIR)errors.o: $(SRCDIR)errors.c $(IDIR)main.h
$(CC)$(CFLAGS) -c $(SRCDIR)errors.c -o $#
run:
$(BINDIR)antiEvilMaid init
clean:
rm $(BINDIR)*.o $(BINDIR)antiEvilMaid
memtest:
valgrind --leak-check=full $(BINDIR)antiEvilMaid init
I'm trying to compile a C program on Windows for use on a linux dev board.
When I try to compile using a makefile I get this output:
$ make
arm-linux-gnueabihf-gcc -g -Wall main.c -o filetest
process_begin: CreateProcess(NULL, arm-linux-gnueabihf-gcc -g -Wall main.c -o filetest, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [filetest] Error 2
This happens whether or not a blank file called filetest is present or not in the same directory. If it is present, I can run make clean and it will remove the file.
Here is the makefile I'm using:
#
TARGET = filetest
ALT_DEVICE_FAMILY ?= soc_cv_av
SOCEDS_ROOT ?= $(SOCEDS_DEST_ROOT)
HWLIBS_ROOT = $(SOCEDS_ROOT)/ip/altera/hps/altera_hps/hwlib
CROSS_COMPILE = arm-linux-gnueabihf-
CFLAGS = -g -Wall -D$(ALT_DEVICE_FAMILY) -I$(HWLIBS_ROOT)/include/$(ALT_DEVICE_FAMILY) -I$(HWLIBS_ROOT)/include/
LDFLAGS = -g -Wall
CC = $(CROSS_COMPILE)gcc
ARCH= arm
build: $(TARGET)
#
$(TARGET):main.c
$(CC) $(LDFLAGS) $^ -o $#
%.o : %.c
$(CC) $(CFLAGS) -c $< -o $#
.PHONY: clean
clean:
rm -f $(TARGET) *.a *.o *~
I used tabs in my actual makefile instead of spaces for the code block above ^^
Also, I'm working within Intel's FPGA SoC EDS for a Cyclone V board.
I have a problem with GDB in Archlinux:
Even I add -g in my Makefile gdb say (no debugging symbols found)...done..
But if I compile manually gcc -g *.c it work...
I don't know what is don't work in my Makefile ?
My Archlinux:
Linux sime_arch 4.13.4-1-ARCH #1 SMP PREEMPT Thu Sep 28 08:39:52 CEST 2017 x86_64 GNU/Linux
My GCC:
gcc version 7.2.0 (GCC)
My Makefile:
SRC = test.c \
test2.c
OBJ = $(SRC:.c=.o)
NAME = test_name
CFLAG = -Wall -Werror -Wextra
all: $(NAME)
$(NAME): $(OBJ)
gcc -g $(OBJ) -o $(NAME) $(CFLAG)
clean:
rm -f $(OBJ)
fclean: clean
rm -f $(NAME)
re: fclean all}
Thanks in advance
You are adding the -g only to the linking command. The object files are generated by the auto compile target of make. This doesn't have the -g flag in it.
You have 2 options -
Change your variable CFLAG to CFLAGS and add -g to it. CFLAGS is picked by the auto compile command and it will create object files with debug info
Add the following target -
%.o: %.c
gcc -g $(CFLAG) -o $# $<
before the $(NAME) target.
The second one gives you more control with the targets but the first method is the standard way of compiling.
Also, always try using standard names for variables unless you specifically need to name them separately.
I'm trying to compile svdlibc on a 64 bit mac. Running the make file returns the error message:
main.c:1: error: CPU you selected does not support x86-64 instruction set
main.c:1: error: CPU you selected does not support x86-64 instruction set
make: *** [main.o] Error 1
Which doesn't make much sense.
The make file is:
# Linux or Windows:
CC = gcc -Wall -O4 -march=i486
# CC = icc -w1 -O3 -march=i486
# Macintosh:
ifeq ($(HOSTTYPE),powerpc)
CC = cc -pipe -O3 -Wall -fno-common -arch ppc
endif
LIBS=-lm
OBJ=svdlib.o svdutil.o las2.o
svd: Makefile main.o libsvd.a
${CC} ${CFLAGS} -o svd main.o libsvd.a ${LIBS}
mv -f $# ${HOSTTYPE}/$#
ln -s ${HOSTTYPE}/$# $#
main.o: Makefile main.c svdlib.h
${CC} ${CFLAGS} -c main.c
libsvd.a: ${HOSTTYPE} ${OBJ}
rm -f $# ${HOSTTYPE}/$#
ar cr $# ${OBJ}
ranlib $#
mv -f $# ${HOSTTYPE}/$#
ln -s ${HOSTTYPE}/$# $#
svdlib.o: Makefile svdlib.h svdlib.c
${CC} ${CFLAGS} -c svdlib.c
svdutil.o: Makefile svdutil.c svdutil.h
${CC} ${CFLAGS} -c svdutil.c
las2.o: Makefile las2.c svdlib.h svdutil.h
${CC} ${CFLAGS} -c las2.c
clean:
rm *.o
$(HOSTTYPE):
if test ! -d $(HOSTTYPE); \
then mkdir $(HOSTTYPE); fi
Editing the make file to alter the -march flag lets the compilation proceed but apparently the linking fails with:
ld: lto: could not merge in main.o because Invalid ALLOCA record for
architecture x86_64
Has anyone done this? Or is there a different svd library that I should use instead? (For large sparse matrices?)
EDIT: porneL seems to have found the problem. Changing the top line in the makefile to:
CC = gcc -Wall -O3 -march=x86-64
compilation work. Haven't tested the results yet, but looks very promising.
-O4 causes this for some reason. Use -O3 instead.
You could try with port ( http://www.macports.org/ ) it seems it s availablee :
svdlibc #1.34 (math, science)
SVDLIBC is a C library to perform singular value decomposition
Basically you ll install macports then , sudo port install svdlibc.