How to specify separate compilation options for different targets in qmake? - qmake

Is there any way to specify separate compilation options for different targets in qmake ?
For example:
QMAKE_CXXFLAGS += -O
SOURCES += file1.cpp
QMAKE_CXXFLAGS += -std=gnu++0x -O
SOURCES += file2.cpp
So file1.cpp will be compiled only with -O option and file file2.cpp with -std=gnu++0x -O options.

You could create and use a separate "extra compiler", as follows:
# Use the built-in compiler for file1.cpp
QMAKE_CXXFLAGS += -O
SOURCES += file1.cpp
# Create a new compiler for file2.cpp
gnupp0x.input = SOURCES_GNUPP0X
gnupp0x.output = ${QMAKE_FILE_BASE}.o
gnupp0x.commands = g++ -std=gnu++0x $$QMAKE_CXXFLAGS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}
QMAKE_EXTRA_COMPILERS += gnupp0x
# Use the new compiler for file2.cpp
SOURCES_GNUPP0X += file2.cpp

Related

shared:ERROR: BINARYEN_ROOT is set to empty value in /root/.emscripten

I am trying to run a docker image with the following command:
docker run -v $PWD/build:/app/build --rm tflite-find-arena-size
However this error pops up to me. I am using MacOS. I tried brew install it but that didn't help. I also opened ~/.emscripten file and checked that BINARYEN_ROOT is not empty. Please help.
shared:ERROR: BINARYEN_ROOT is set to empty value in /root/.emscripten
Makefile.emcc:31: recipe for target 'build' failed
make: *** [build] Error 1
This is the makefile that I am using:
NAME = find-arena-size
CC = emcc
CXX = em++
CFLAGS ?= -Wall
MACROS += -DTF_LITE_DISABLE_X86_NEON
CXXFLAGS += -std=c++11
EMCCFLAGS += -s WASM=0
EMCCFLAGS += --bind
CFLAGS += -I.
CFLAGS += -Isource
CFLAGS += -Iedge-impulse-sdk/
CFLAGS += -Iedge-impulse-sdk/tensorflow
CFLAGS += -Iedge-impulse-sdk/third_party
CFLAGS += -Iedge-impulse-sdk/third_party/flatbuffers
CFLAGS += -Iedge-impulse-sdk/third_party/flatbuffers/include
CFLAGS += -Iedge-impulse-sdk/third_party/flatbuffers/include/flatbuffers
CFLAGS += -Iedge-impulse-sdk/third_party/gemmlowp/
CFLAGS += -Iedge-impulse-sdk/third_party/gemmlowp/fixedpoint
CFLAGS += -Iedge-impulse-sdk/third_party/gemmlowp/internal
CFLAGS += -Iedge-impulse-sdk/third_party/ruy
CFLAGS += -Imodel-parameters
CFLAGS += -Iedge-impulse-sdk/porting
all: build
.PHONY: build clean
build:
echo "Mazenm"
mkdir -p build/emcc
$(CC) -c $(MACROS) $(CFLAGS) $(LFLAGS) edge-impulse-sdk/tensorflow/lite/c/common.c -o build/emcc/common.o
$(CXX) $(MACROS) $(CXXFLAGS) $(CFLAGS) $(LFLAGS) $(EMCCFLAGS) emcc/emcc_binding.cpp edge-impulse-sdk/tensorflow/lite/kernels/*.cc edge-impulse-sdk/tensorflow/lite/kernels/internal/*.cc edge-impulse-sdk/tensorflow/lite/micro/kernels/*.cc edge-impulse-sdk/tensorflow/lite/micro/*.cc edge-impulse-sdk/tensorflow/lite/micro/memory_planner/*.cc edge-impulse-sdk/tensorflow/lite/core/api/*.cc ./edge-impulse-sdk/dsp/memory.cpp emcc/porting/*.c* build/emcc/common.o -o build/emcc/$(NAME).js
rm build/emcc/*.o
clean:
rm -r build/emcc
Which docker image are you using? How did you install emscripten (emsdk?) within the docker image.
There is a semi-official docker image you can use via docker pull emscripten/emsdk.
However you should be able to install the emsdk directly on MacOS without needing to use docker at all. This is the recommended way to install emscripten. If you have problems with installing the emsdk directly please file a bug at https://github.com/emscripten-core/emsdk
It's looks like emsdk is not activated. Mabe path to emsdk is not correct.

compiling with HDF5: unable to link library files (fortran 90)

I am currently try to compile these files using HDF5
I have directly linked and included everything necessary ( I think) but still the compile unable to find the files that is needed
This is my Makefile:
CC = h5cc
FC = h5fc
LD = h5fc
FDEBUG = -std -g -traceback
CFLAGS = -g -O0 -Wall -pedantic
FFLAGS = -g -O0 -Wall -I$(H5DIR)/include -L$(H5DIR)/lib/libhdf5hl_fortran.a
LDFLAGS = -I$(H5DIR)/include -L$(H5DIR)/lib/libhdf5hl_fortran.a
#LDFLAGS = -I$(MKLROOT)/include -L$(MKLROOT) -mkl=sequential
# -opt-block-factor=16 -opt-prefetch=4 \
.SUFFIXES:
.SUFFIXES: .c .f .f90 .F90 .o
OBJS = timing.o \
kinds.o \
rw_matrix.o \
EXE = matmul_omp.exe
all: $(EXE)
$(EXE): $(OBJS) matmul_omp.o
$(LD) $(LDFLAGS) -o $# $^
.f90.o:
-$(RM) -f $*.o $*.mod
$(FC) $(FFLAGS) -c $<
.c.o:
$(CC) $(CFLAGS) -c $<
.PHONEY: clean
clean:
THis is the err:
h5fc -I/curc/tools/x_86_64/rh6/hdf5/1.8.13/szip/2.1/zlib/1.2.8/jpeglib/9a/openmpi/1.8.2/intel/13.0.0/include -L/curc/tools/x_86_64/rh6/hdf5/1.8.13/szip/2.1/zlib/1.2.8/jpeglib/9a/openmpi/1.8.2/intel/13.0.0/lib/libhdf5hl_fortran.a -o matmul_omp.exe timing.o matmul_omp.o
gfortran: /usr/lib64/libhdf5hl_fortran.a: No such file or directory
gfortran: /usr/lib64/libhdf5_hl.a: No such file or directory
gfortran: /usr/lib64/libhdf5_fortran.a: No such file or directory
gfortran: /usr/lib64/libhdf5.a: No such file or directory
As you can see that I directly link libhdf5hl_fortran.a. but i dont know why the error is giving a different directory /usr/lib64/
I think you have a couple of things wrong here.
If you are using h5fc then you shouldn't need to add all the include and lib paths. That is the whole point of the helper applications.
You are adding the paths that have Intel, yet your h5fc has a GNU (gfortran) error.
The gfortran build of HDF5 looks as if it does not have the fortran bindings built.
I would suggest trying the following. Using the full paths (as you have done) but call ifort instead of h5fc:
ifort -I/curc/tools/x_86_64/rh6/hdf5/1.8.13/szip/2.1/zlib/1.2.8/jpeglib/9a/openmpi/1.8.2/intel/13.0.0/include \
-L/curc/tools/x_86_64/rh6/hdf5/1.8.13/szip/2.1/zlib/1.2.8/jpeglib/9a/openmpi/1.8.2/intel/13.0.0/lib/libhdf5hl_fortran.a \
-o matmul_omp.exe timing.o matmul_omp.o

CUDA collect2 ld returned 1 exit status

I'm trying to compile Mars for cuda 4.2.9 (cuda 5.0 eliminated a lot of header files used by Mars). Versions below 5.0 seem to utilize this monstrous makefile common.mk and I'm having a hard time configuring it to get the code to work. The object files compile just fine but I'm getting this error:
/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/bin/ld: cannot find -lcutil_x86_64
/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/bin/ld: cannot find -lshrutil_x86_64
collect2: ld returned 1 exit status
make: *** [/home/ian/code/cuda-4.2.9/C/bin/linux/release/MatrixMul] Error 1
Why is this happening? How can I remedy it?
Here is the makefile for MatrixMul:
################################################################################
#
# Build script for project
#
################################################################################
# Add source files here
EXECUTABLE := MatrixMul
# Cuda source files (compiled with cudacc)
CUFILES := main.cu MarsLib.cu MarsScan.cu MarsSort.cu
# C/C++ source files (compiled with gcc / c++)
CCFILES := MarsUtils.cpp
################################################################################
# Rules and targets
include ../cuda-4.2.9/C/common/common.mk
The lines of common.mk that I edited:
# Basic directory setup for SDK
# (override directories only if they are not already defined)
SRCDIR ?=
ROOTDIR ?= /home/ian/code/cuda-4.2.9
ROOTBINDIR ?= $(ROOTDIR)/C/bin
BINDIR ?= $(ROOTBINDIR)/$(OSLOWER)
ROOTOBJDIR ?= obj
LIBDIR := $(ROOTDIR)/C/lib
COMMONDIR := $(ROOTDIR)/C/common
SHAREDDIR := $(ROOTDIR)/shared/
Original values:
# Basic directory setup for SDK
# (override directories only if they are not already defined)
SRCDIR ?=
ROOTDIR ?= ..
ROOTBINDIR ?= $(ROOTDIR)/../bin
BINDIR ?= $(ROOTBINDIR)/$(OSLOWER)
ROOTOBJDIR ?= obj
LIBDIR := $(ROOTDIR)/../lib
COMMONDIR := $(ROOTDIR)/../common
SHAREDDIR := $(ROOTDIR)/../shared/
And the whole common.mk:
################################################################################
#
# Common build script for CUDA source projects for Linux and Mac platforms
#
################################################################################
.SUFFIXES : .cu .cu_dbg.o .c_dbg.o .cpp_dbg.o .cu_rel.o .c_rel.o .cpp_rel.o .cubin .ptx
# Add new SM Versions here as devices with new Compute Capability are released
SM_VERSIONS := 10 11 12 13 20 21 30
CUDA_INSTALL_PATH ?= /home/ian/code/cuda-4.2.9/cuda/
ifdef cuda-install
CUDA_INSTALL_PATH := $(cuda-install)
endif
# detect OS
OSUPPER = $(shell uname -s 2>/dev/null | tr [:lower:] [:upper:])
OSLOWER = $(shell uname -s 2>/dev/null | tr [:upper:] [:lower:])
# 'linux' is output for Linux system, 'darwin' for OS X
DARWIN = $(strip $(findstring DARWIN, $(OSUPPER)))
ifneq ($(DARWIN),)
SNOWLEOPARD = $(strip $(findstring 10.6, $(shell egrep "<string>10\.6" /System/Library/CoreServices/SystemVersion.plist)))
LION = $(strip $(findstring 10.7, $(shell egrep "<string>10\.7" /System/Library/CoreServices/SystemVersion.plist)))
endif
# detect 32-bit or 64-bit platform
HP_64 = $(shell uname -m | grep 64)
OSARCH= $(shell uname -m)
# Basic directory setup for SDK
# (override directories only if they are not already defined)
SRCDIR ?=
ROOTDIR ?= /home/ian/code/cuda-4.2.9/cuda/C
ROOTBINDIR ?= $(ROOTDIR)/bin
BINDIR ?= $(ROOTBINDIR)/$(OSLOWER)
ROOTOBJDIR ?= obj
LIBDIR := $(ROOTDIR)/lib
COMMONDIR := $(ROOTDIR)/common
SHAREDDIR := $(ROOTDIR)/../shared/
# Compilers
NVCC := $(CUDA_INSTALL_PATH)/bin/nvcc
CXX := g++ -fPIC
CC := gcc -fPIC
LINK := g++ -fPIC
# Includes
INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/include -I$(COMMONDIR)/inc -I$(SHAREDDIR)/inc
# Warning flags
CXXWARN_FLAGS := \
-W -Wall \
-Wimplicit \
-Wswitch \
-Wformat \
-Wchar-subscripts \
-Wparentheses \
-Wmultichar \
-Wtrigraphs \
-Wpointer-arith \
-Wcast-align \
-Wreturn-type \
-Wno-unused-function \
$(SPACE)
CWARN_FLAGS := $(CXXWARN_FLAGS) \
-Wstrict-prototypes \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wnested-externs \
-Wmain \
# architecture flag for nvcc and gcc compilers build
CUBIN_ARCH_FLAG :=
CXX_ARCH_FLAGS :=
NVCCFLAGS :=
LIB_ARCH := $(OSARCH)
# Determining the necessary Cross-Compilation Flags
# 32-bit OS, but we target 64-bit cross compilation
ifeq ($(x86_64),1)
NVCCFLAGS += -m64
LIB_ARCH = x86_64
ifneq ($(DARWIN),)
CXX_ARCH_FLAGS += -arch x86_64
else
CXX_ARCH_FLAGS += -m64
endif
else
# 64-bit OS, and we target 32-bit cross compilation
ifeq ($(i386),1)
NVCCFLAGS += -m32
LIB_ARCH = i386
ifneq ($(DARWIN),)
CXX_ARCH_FLAGS += -arch i386
else
CXX_ARCH_FLAGS += -m32
endif
else
ifeq "$(strip $(HP_64))" ""
LIB_ARCH = i386
NVCCFLAGS += -m32
ifneq ($(DARWIN),)
CXX_ARCH_FLAGS += -arch i386
else
CXX_ARCH_FLAGS += -m32
endif
else
ifeq "$(strip $(HP_64))" ""
LIB_ARCH = i386
NVCCFLAGS += -m32
ifneq ($(DARWIN),)
CXX_ARCH_FLAGS += -arch i386
else
CXX_ARCH_FLAGS += -m32
endif
else
LIB_ARCH = x86_64
NVCCFLAGS += -m64
ifneq ($(DARWIN),)
CXX_ARCH_FLAGS += -arch x86_64
else
CXX_ARCH_FLAGS += -m64
endif
endif
endif
endif
# Compiler-specific flags (by default, we always use sm_10, sm_20, and sm_30), unless we use the SMVERSION template
GENCODE_SM10 := -gencode=arch=compute_10,code=\"sm_10,compute_10\"
GENCODE_SM20 := -gencode=arch=compute_20,code=\"sm_20,compute_20\"
GENCODE_SM30 := -gencode=arch=compute_30,code=\"sm_30,compute_30\"
CXXFLAGS += $(CXXWARN_FLAGS) $(CXX_ARCH_FLAGS)
CFLAGS += $(CWARN_FLAGS) $(CXX_ARCH_FLAGS)
LINKFLAGS +=
LINK += $(LINKFLAGS) $(CXX_ARCH_FLAGS)
# This option for Mac allows CUDA applications to work without requiring to set DYLD_LIBRARY_PATH
ifneq ($(DARWIN),)
LINK += -Xlinker -rpath $(CUDA_INSTALL_PATH)/lib
endif
# Common flags
COMMONFLAGS += $(INCLUDES) -DUNIX
# If we are enabling GPU based debugging, then we want to use -G, warning that this
# May have a significant impact on GPU device code, since optimizations are turned off
ifeq ($(gpudbg),1)
NVCCFLAGS += -G
dbg = $(gpudbg)
endif
# Debug/release configuration
ifeq ($(dbg),1)
COMMONFLAGS += -g
NVCCFLAGS += -D_DEBUG
CXXFLAGS += -D_DEBUG
CFLAGS += -D_DEBUG
BINSUBDIR := debug
LIBSUFFIX := D
else
COMMONFLAGS += -O2
BINSUBDIR := release
LIBSUFFIX :=
NVCCFLAGS += --compiler-options -fno-strict-aliasing
CXXFLAGS += -fno-strict-aliasing
CFLAGS += -fno-strict-aliasing
endif
# architecture flag for cubin build
CUBIN_ARCH_FLAG :=
# OpenGL is used or not (if it is used, then it is necessary to include GLEW)
ifeq ($(USEGLLIB),1)
ifneq ($(DARWIN),)
OPENGLLIB := -L/System/Library/Frameworks/OpenGL.framework/Libraries
OPENGLLIB += -lGL -lGLU $(COMMONDIR)/lib/$(OSLOWER)/libGLEW.a
else
# this case for linux platforms
OPENGLLIB := -lGL -lGLU -lX11 -lXi -lXmu
# check if x86_64 flag has been set, otherwise, check HP_64 is i386/x86_64
ifeq ($(x86_64),1)
OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
else
ifeq ($(i386),)
ifeq "$(strip $(HP_64))" ""
OPENGLLIB += -lGLEW -L/usr/X11R6/lib
else
OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
endif
endif
endif
# check if i386 flag has been set, otehrwise check HP_64 is i386/x86_64
ifeq ($(i386),1)
OPENGLLIB += -lGLEW -L/usr/X11R6/lib
else
ifeq ($(x86_64),)
ifeq "$(strip $(HP_64))" ""
OPENGLLIB += -lGLEW -L/usr/X11R6/lib
else
OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
endif
endif
endif
endif
endif
ifeq ($(USEGLUT),1)
ifneq ($(DARWIN),)
OPENGLLIB += -framework GLUT
else
ifeq ($(x86_64),1)
OPENGLLIB += -lglut -L/usr/lib64
endif
ifeq ($(i386),1)
OPENGLLIB += -lglut -L/usr/lib
endif
ifeq ($(x86_64),)
ifeq ($(i386),)
OPENGLLIB += -lglut
endif
endif
endif
endif
ifeq ($(USEPARAMGL),1)
PARAMGLLIB := -lparamgl_$(LIB_ARCH)$(LIBSUFFIX)
endif
ifeq ($(USERENDERCHECKGL),1)
RENDERCHECKGLLIB := -lrendercheckgl_$(LIB_ARCH)$(LIBSUFFIX)
endif
ifeq ($(USENVCUVID), 1)
ifneq ($(DARWIN),)
NVCUVIDLIB := -L../../common/lib/darwin -lnvcuvid
endif
endif
# Libs
ifneq ($(DARWIN),)
LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib $(NVCUVIDLIB)
else
ifeq "$(strip $(HP_64))" ""
ifeq ($(x86_64),1)
LIB := -L$(CUDA_INSTALL_PATH)/lib64 -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
else
LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
endif
else
ifeq ($(i386),1)
LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
else
LIB := -L$(CUDA_INSTALL_PATH)/lib64 -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
endif
endif
endif
# If dynamically linking to CUDA and CUDART, we exclude the libraries from the LIB
ifeq ($(USECUDADYNLIB),1)
LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) ${LIB} -ldl -rdynamic
else
# static linking, we will statically link against CUDA and CUDART
ifeq ($(USEDRVAPI),1)
LIB += -lcuda ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) ${LIB}
else
ifeq ($(emu),1)
LIB += -lcudartemu
else
LIB += -lcudart
endif
LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) ${LIB}
endif
endif
ifeq ($(USECUFFT),1)
ifeq ($(emu),1)
LIB += -lcufftemu
else
LIB += -lcufft
endif
endif
ifeq ($(USECUBLAS),1)
ifeq ($(emu),1)
LIB += -lcublasemu
else
LIB += -lcublas
endif
endif
ifeq ($(USECURAND),1)
LIB += -lcurand
endif
ifeq ($(USECUSPARSE),1)
LIB += -lcusparse
endif
# Lib/exe configuration
# Lib/exe configuration
# Lib/exe configuration
ifneq ($(STATIC_LIB),)
TARGETDIR := $(LIBDIR)
TARGET := $(subst .a,_$(LIB_ARCH)$(LIBSUFFIX).a,$(LIBDIR)/$(STATIC_LIB))
LINKLINE = ar rucv $(TARGET) $(OBJS)
else
ifneq ($(OMIT_CUTIL_LIB),1)
LIB += -lcutil_$(LIB_ARCH)$(LIBSUFFIX)
endif
ifneq ($(OMIT_SHRUTIL_LIB),1)
LIB += -lshrutil_$(LIB_ARCH)$(LIBSUFFIX)
endif
# Device emulation configuration
ifeq ($(emu), 1)
NVCCFLAGS += -deviceemu
CUDACCFLAGS +=
BINSUBDIR := emu$(BINSUBDIR)
# consistency, makes developing easier
CXXFLAGS += -D__DEVICE_EMULATION__
CFLAGS += -D__DEVICE_EMULATION__
endif
TARGETDIR := $(BINDIR)/$(BINSUBDIR)
TARGET := $(TARGETDIR)/$(EXECUTABLE)
LINKLINE = $(LINK) -o $(TARGET) $(OBJS) $(LIB)
endif
# check if verbose
ifeq ($(verbose), 1)
VERBOSE :=
else
VERBOSE := #
endif
################################################################################
# Check for input flags and set compiler flags appropriately
################################################################################
ifeq ($(fastmath), 1)
NVCCFLAGS += -use_fast_math
endif
ifeq ($(keep), 1)
NVCCFLAGS += -keep
NVCC_KEEP_CLEAN := *.i* *.cubin *.cu.c *.cudafe* *.fatbin.c *.ptx
endif
ifdef maxregisters
NVCCFLAGS += -maxrregcount $(maxregisters)
endif
ifeq ($(ptxas), 1)
NVCCFLAGS += --ptxas-options=-v
endif
# Add cudacc flags
NVCCFLAGS += $(CUDACCFLAGS)
# Add common flags
NVCCFLAGS += $(COMMONFLAGS)
CXXFLAGS += $(COMMONFLAGS)
CFLAGS += $(COMMONFLAGS)
ifeq ($(nvcc_warn_verbose),1)
NVCCFLAGS += $(addprefix --compiler-options ,$(CXXWARN_FLAGS))
NVCCFLAGS += --compiler-options -fno-strict-aliasing
endif
################################################################################
# Set up object files
################################################################################
OBJDIR := $(ROOTOBJDIR)/$(LIB_ARCH)/$(BINSUBDIR)
OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp.o,$(notdir $(CCFILES)))
OBJS += $(patsubst %.c,$(OBJDIR)/%.c.o,$(notdir $(CFILES)))
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu.o,$(notdir $(CUFILES)))
################################################################################
# Set up cubin output files
################################################################################
CUBINDIR := $(SRCDIR)data
CUBINS += $(patsubst %.cu,$(CUBINDIR)/%.cubin,$(notdir $(CUBINFILES)))
################################################################################
# Set up PTX output files
################################################################################
PTXDIR := $(SRCDIR)data
PTXBINS += $(patsubst %.cu,$(PTXDIR)/%.ptx,$(notdir $(PTXFILES)))
################################################################################
# Rules
################################################################################
$(OBJDIR)/%.c.o : $(SRCDIR)%.c $(C_DEPS)
$(VERBOSE)$(CC) $(CFLAGS) -o $# -c $<
$(OBJDIR)/%.cpp.o : $(SRCDIR)%.cpp $(C_DEPS)
$(VERBOSE)$(CXX) $(CXXFLAGS) -o $# -c $<
# Default arch includes gencode for sm_10, sm_20, sm_30, and other archs from GENCODE_ARCH declared in the makefile
$(OBJDIR)/%.cu.o : $(SRCDIR)%.cu $(CU_DEPS)
$(VERBOSE)$(NVCC) $(GENCODE_SM10) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -c $<
# Default arch includes gencode for sm_10, sm_20, sm_30, and other archs from GENCODE_ARCH declared in the makefile
$(CUBINDIR)/%.cubin : $(SRCDIR)%.cu cubindirectory
$(VERBOSE)$(NVCC) $(GENCODE_SM10) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -cubin $<
$(PTXDIR)/%.ptx : $(SRCDIR)%.cu ptxdirectory
$(VERBOSE)$(NVCC) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $# -ptx $<
# The following definition is a template that gets instantiated for each SM
# version (sm_10, sm_13, etc.) stored in SMVERSIONS. It does 2 things:
# 1. It adds to OBJS a .cu_sm_XX.o for each .cu file it finds in CUFILES_sm_XX.
# 2. It generates a rule for building .cu_sm_XX.o files from the corresponding
# .cu file.
#
# The intended use for this is to allow Makefiles that use common.mk to compile
# files to different Compute Capability targets (aka SM arch version). To do
# so, in the Makefile, list files for each SM arch separately, like so:
# This will be used over the default rule abov
#
# CUFILES_sm_10 := mycudakernel_sm10.cu app.cu
# CUFILES_sm_12 := anothercudakernel_sm12.cu
#
define SMVERSION_template
#OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_$(1).o,$(notdir $(CUFILES_$(1))))
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_$(1).o,$(notdir $(CUFILES_sm_$(1))))
$(OBJDIR)/%.cu_$(1).o : $(SRCDIR)%.cu $(CU_DEPS)
# $(VERBOSE)$(NVCC) -o $$# -c $$< $(NVCCFLAGS) $(1)
$(VERBOSE)$(NVCC) -gencode=arch=compute_$(1),code=\"sm_$(1),compute_$(1)\" $(GENCODE_SM20) $(GENCODE_SM30) -o $$# -c $$< $(NVCCFLAGS)
endef
# This line invokes the above template for each arch version stored in
# SM_VERSIONS. The call function invokes the template, and the eval
# function interprets it as make commands.
$(foreach smver,$(SM_VERSIONS),$(eval $(call SMVERSION_template,$(smver))))
$(TARGET): makedirectories $(OBJS) $(CUBINS) $(PTXBINS) Makefile
$(VERBOSE)$(LINKLINE)
cubindirectory:
$(VERBOSE)mkdir -p $(CUBINDIR)
ptxdirectory:
$(VERBOSE)mkdir -p $(PTXDIR)
makedirectories:
$(VERBOSE)mkdir -p $(LIBDIR)
$(VERBOSE)mkdir -p $(OBJDIR)
$(VERBOSE)mkdir -p $(TARGETDIR)
tidy :
$(VERBOSE)find . | egrep "#" | xargs rm -f
$(VERBOSE)find . | egrep "\~" | xargs rm -f
clean : tidy
$(VERBOSE)rm -f *.stub.c *.gpu *.cu.cpp *.i *.ii
$(VERBOSE)rm -f *.cubin *.ptx *.fatbin.c *.hash
$(VERBOSE)rm -f *.cudafe1.c *.cudafe2.c *.cudafe1.cpp *.cudafe2.cpp
$(VERBOSE)rm -f $(OBJS)
$(VERBOSE)rm -f $(CUBINS)
$(VERBOSE)rm -f $(PTXBINS)
$(VERBOSE)rm -f $(TARGET)
$(VERBOSE)rm -f $(NVCC_KEEP_CLEAN)
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.ppm
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.pgm
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.bin
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.bmp
$(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.txt
$(VERBOSE)rm -f $(CUBINDIR)/*.cubin $(PTXDIR)/*.ptx
$(VERBOSE)rm -rf $(ROOTOBJDIR)
$(VERBOSE)rm -rf $(LIBDIR)
$(VERBOSE)rm -rf $(OBJDIR)
$(VERBOSE)rm -rf $(TARGETDIR)
clobber : clean
$(VERBOSE)rm -rf $(COMMONDIR)/lib/*.a
$(VERBOSE)rm -rf $(SHAREDDIR)/lib/*.a
$(VERBOSE)rm -rf $(COMMONDIR)/obj
$(VERBOSE)rm -rf $(SHAREDDIR)/obj
Why is this happening?
libcutil_x86_64.lib and libshrutil_x86_64.lib are libraries that are built by the cuda samples (called CUDA SDK in cuda 4.2 and earlier) when a proper make operation has been done after the CUDA SDK is installed. The linker cannot find these libraries and so is throwing these errors.
How can I remedy it?
Make sure that the CUDA 4.2 SDK has been properly installed and that the necessary make operation has been done to build the samples and therefore the requisite libraries. If you're unsure how to install the CUDA SDK or make the sample codes, review the /home/ian/code/cuda-4.2.9/CUDA_SDK_Release_Notes.txt file (especially linux install instructions). You may also be interested in the GPU_COMPUTING_SDK_Description.rtf file in that directory and also the files in the .../doc/release subdirectory. If you have not properly built the samples, the libraries won't be available and you'll have no luck linking your own matrixMul-MARS project. Note that you can specify the directory path to install the CUDA SDK at. Let's assume that from here on that ... in a path represents your SDK install path (which might be /home/ian/code/cuda-4.2.9/NVIDIA_GPU_Computing_SDK or something similar.) If things are jumbled in what you already have, you may want to start clean and re-run the installer.
Create a new project directory for your matrixMul-MARS project, at the same level as the other C source project directories, i.e. .../C/src/myMARS or something similar.
Copy all the files from .../C/src/matrixMul directory into your new .../C/src/myMARS directory.
Make the necessary changes to the Makefile in your new project directory (only) corresponding to what you have shown here, such as including additional files to be built, etc. You should not have to make any changes to common.mk.
Now execute make in your new project directory.

How to use precompiled headers with a qmake extra compiler?

When using the default qmake compiler (via the SOURCES variable), I can use precompiled headers like so:
CONFIG += precompile_header
PRECOMPILED_HEADER = stable.h
SOURCES = main.c
However, I'd like to use a custom compiler (via QMAKE_EXTRA_COMPILERS). I tried this:
CONFIG += precompile_header
PRECOMPILED_HEADER = stable.h
MY_SOURCES = main.c
my.input = MY_SOURCES
my.output = ${QMAKE_FILE_IN_BASE}.o
my.commands = clang $$QMAKE_CFLAGS_USE_PRECOMPILE -c ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT}
QMAKE_EXTRA_COMPILERS += my
...and the precompiled headers are built, but my custom compiler fails because QMAKE_CFLAGS_USE_PRECOMPILE doesn't contain the path to the precompiled header. (It is defined as -Xclang -include-pch -Xclang ${QMAKE_PCH_OUTPUT}, and apparently ${QMAKE_PCH_OUTPUT} is empty.)
How can I get the name of the generated precompiled header, so I can pass it as a parameter to my custom compiler?
Looking at the qmake source code, precompiled header handling seems to be hardcoded in UnixMakefileGenerator::init() to only work for the built-in C, CXX, OBJC, and OBJCXX compilers.
QMAKE_PCH_OUTPUT, for GCC and Clang-style precompiled headers, is constructed by combining PRECOMPILED_DIR, TARGET, one of c/c++/objective-c/objective-c++, and QMAKE_PCH_OUTPUT_EXT. So, in the question's second example, the following command line should work:
my.commands = clang -Xclang -include-pch -Xclang $$TARGET/c$$QMAKE_PCH_OUTPUT_EXT -c ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT}

How to execute external programs from qmake?

I am trying run a program from a qmake .pro file which modifies the final binary. I have already tried system(...) but it does not work. The reason I want this is because by default some properties of the binary prevent debugging and it is inconvenient to do it manually every time. I can do this from simple makefiles.
Here is my .pro file:
TARGET = lprog_server
QT += core \
xml \
network
HEADERS += Network/PlayerJoined.hh \
...
SOURCES += Globals.cc \
...
FORMS +=
RESOURCES +=
QMAKE_LFLAGS += -lboost_random-mt
system(paxctl -pemrxs lprog_server)
It is needed for my homework but the assignment is not to execute something from qmake. It is in fact a server-client software using Qt already more than 2500 lines long.
QMAKE_POST_LINK=paxctl -pemrxs $(TARGET)

Resources