Use OpenCV in mex function : error after compilation - c++

I am working on a project developed under matlab, but I had to use C ++ and OpenCV.
In order to integrate my work with the project, I need to use mex-files. So I installed Matlab 2013 on my computer and gcc 4.4.
I modified the file ~/.matlab/R2013a/mexopts.sh in order to set the right compiler and options for opencv.
This is the output of the compilation in matlab with mex -v
**************************************************************************
Warning: Neither -compatibleArrayDims nor -largeArrayDims is selected.
Using -compatibleArrayDims. In the future, MATLAB will require
the use of -largeArrayDims and remove the -compatibleArrayDims
option. For more information, see:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html
**************************************************************************
-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
FILE = /home/amine/.matlab/R2013a/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /usr/local/MATLAB/R2013a
-> CC = gcc-4.4
-> CC flags:
CFLAGS = -std=c99 -D_GNU_SOURCE `pkg-config --cflags opencv` -fexceptions -fPIC -fno-omit-frame-pointer -pthread
CDEBUGFLAGS = -g
COPTIMFLAGS = -O -DNDEBUG
CLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2013a/bin/glnxa64 -L/usr/local/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
arguments = -DMX_COMPAT_32
-> CXX = g++-4.4
-> CXX flags:
CXXFLAGS = -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O -DNDEBUG
CXXLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2013a/bin/glnxa64 -L/usr/local/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2013a/bin/glnxa64 -L/usr/local/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> LD = g++-4.4
-> Link flags:
LDFLAGS = -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2013a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_ocl.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so /usr/lib/x86_64-linux-gnu/libXext.so /usr/lib/x86_64-linux-gnu/libX11.so /usr/lib/x86_64-linux-gnu/libICE.so /usr/lib/x86_64-linux-gnu/libSM.so /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so -ltbb -lrt -lpthread -lm -ldl
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexa64
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "mxFunction.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "verifAndHyp.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../Description/Statistic/statistic.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../Description/Statistic/classes.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../Verification/contradiction.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../HypothesisGeneration/hypothesis.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../Description/HoughTransform/hough.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../Description/HoughTransform/utils.cpp"
-> g++-4.4 -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -D_GNU_SOURCE `pkg-config --cflags opencv` -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "../Verification/distance.cpp"
-> g++-4.4 -O -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2013a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_ocl.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so /usr/lib/x86_64-linux-gnu/libXext.so /usr/lib/x86_64-linux-gnu/libX11.so /usr/lib/x86_64-linux-gnu/libICE.so /usr/lib/x86_64-linux-gnu/libSM.so /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so -ltbb -lrt -lpthread -lm -ldl -o "mxFunction.mexa64" mxFunction.o verifAndHyp.o statistic.o classes.o contradiction.o hypothesis.o hough.o utils.o distance.o -Wl,-rpath-link,/usr/local/MATLAB/R2013a/bin/glnxa64 -L/usr/local/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm
But when I try to use the mxFunction like this mxFunction('path_to_my_file'), the result is :
Invalid MEX-file '/home/amine/Stage2A/stage2a/src/HypothesisGeneration/mxFunction.mexa64': /usr/local/lib/libopencv_ocl.so.2.4: undefined symbol:
_ZTIN2cv16ParallelLoopBodyE
Could you help to resolv this problem ?
PS : I'm using ubuntu 14.04 and Opencv 2.4.8

If you would like to compile a C/C++ file containing OpenCV code into a MEX-file I strongly recommend that you use mexOpenCV instead of mex.
Have a look at this site to set it up properly:
http://de.mathworks.com/help/vision/ug/opencv-interface.html?refresh=true
It tells you how to install the visionSupportPackages which are mandatory to compile OpenCV code into a mex file.

Related

undefined reference to `__cudaPopCallConfiguration'

I am trying to compile a cuda code that I have received from Github (https://github.com/exafmm/exafmm-alpha).
The Makefile.include contains:
.SUFFIXES: .cxx .cu .f90 .o
.PHONY: docs
CUDA_INSTALL_PATH = /usr/local/cuda
#DEVICE = cpu
DEVICE = gpu
CXX = mpicxx -g -O3 -lstdc++ -fPIC -fopenmp -ffast-math -funroll-loops -rdynamic -Wfatal-errors -I../include
NVCC = nvcc -Xcompiler "-fopenmp -O3" -lstdc++ -use_fast_math -I../include
FC = mpif90 -g -O3 -fPIC -fopenmp -funroll-loops -rdynamic -I../include
FCC = mpif90 -c -O3 -fPIC -fopenmp -funroll-loops -rdynamic -I../include
LFLAGS = -D$(DEVICE) -lstdc++ -ldl -lm
LFLAGS += -lmpi_cxx
LFLAGS += -lpthread
ifeq ($(DEVICE),gpu)
LFLAGS += -lcudart
endif
OBJECT = ../kernel/$(DEVICE)Laplace.o ../kernel/$(DEVICE)BiotSavart.o\
../kernel/$(DEVICE)Stretching.o ../kernel/$(DEVICE)Gaussian.o\
../kernel/$(DEVICE)CoulombVdW.o
.cxx.o:
$(CXX) -c $? -o $# $(LFLAGS)
.cu.o:
$(NVCC) -c $? -o $# $(LFLAGS)
.f90.o:
$(FC) -c $? -o $#
And the Makefile is:
include ../Makefile.include
lib_parallel_ij: parallel_wrapper_ij.o $(OBJECT)
ar -cr libfmm.a parallel_wrapper_ij.o $(OBJECT)
ranlib libfmm.a
test_parallel_ij: test_parallel_ij.o
make lib_parallel_ij
$(FC) $? -L. -lfmm $(LFLAGS)
mpirun -np 2 ./a.out
When I tried to compile the code, I get the following errors.
mpif90 -g -O3 -fPIC -fopenmp -funroll-loops -rdynamic -I../include -c test_parallel_ij.f90 -o test_parallel_ij.o
make lib_parallel_ij
make[1]: Entering directory '/home/bidesh/panelCode/UVLM/NVLM_FMM/solver_single_rotor_try/exafmm-alpha-vortex/wrapper'
mpicxx -g -O3 -lstdc++ -fPIC -fopenmp -ffast-math -funroll-loops -rdynamic -Wfatal-errors -I../include -c parallel_wrapper_ij.cxx -o parallel_wrapper_ij.o -Dgpu -lstdc++ -ldl -lm -lmpi_cxx -lpthread -lcudart
nvcc -Xcompiler "-fopenmp -O3" -lstdc++ -use_fast_math -I../include -c ../kernel/gpuLaplace.cu -o ../kernel/gpuLaplace.o -Dgpu -lstdc++ -ldl -lm -lmpi_cxx -lpthread -lcudart
nvcc -Xcompiler "-fopenmp -O3" -lstdc++ -use_fast_math -I../include -c ../kernel/gpuBiotSavart.cu -o ../kernel/gpuBiotSavart.o -Dgpu -lstdc++ -ldl -lm -lmpi_cxx -lpthread -lcudart
../kernel/gpuBiotSavart.cu(542): warning #177-D: variable "SQRT4PI" was declared but never referenced
../kernel/gpuBiotSavart.cu(548): warning #550-D: variable "r" was set but never used
nvcc -Xcompiler "-fopenmp -O3" -lstdc++ -use_fast_math -I../include -c ../kernel/gpuStretching.cu -o ../kernel/gpuStretching.o -Dgpu -lstdc++ -ldl -lm -lmpi_cxx -lpthread -lcudart
nvcc -Xcompiler "-fopenmp -O3" -lstdc++ -use_fast_math -I../include -c ../kernel/gpuGaussian.cu -o ../kernel/gpuGaussian.o -Dgpu -lstdc++ -ldl -lm -lmpi_cxx -lpthread -lcudart
nvcc -Xcompiler "-fopenmp -O3" -lstdc++ -use_fast_math -I../include -c ../kernel/gpuCoulombVdW.cu -o ../kernel/gpuCoulombVdW.o -Dgpu -lstdc++ -ldl -lm -lmpi_cxx -lpthread -lcudart
ar -cr libfmm.a parallel_wrapper_ij.o ../kernel/gpuLaplace.o ../kernel/gpuBiotSavart.o ../kernel/gpuStretching.o ../kernel/gpuGaussian.o ../kernel/gpuCoulombVdW.o
ranlib libfmm.a
make[1]: Leaving directory '/home/bidesh/panelCode/UVLM/NVLM_FMM/solver_single_rotor_try/exafmm-alpha-vortex/wrapper'
mpif90 -g -O3 -fPIC -fopenmp -funroll-loops -rdynamic -I../include test_parallel_ij.o -L. -lfmm -Dgpu -lstdc++ -ldl -lm -lmpi_cxx -lpthread -lcudart
./libfmm.a(gpuLaplace.o): In function `LaplaceL2P_GPU(int*, int*, double*, double*)':
tmpxft_0000397c_00000000-6_gpuLaplace.cudafe1.cpp:(.text+0xc2): undefined reference to `__cudaPopCallConfiguration'
....
./libfmm.a(gpuLaplace.o): In function `Kernel::LaplaceL2P()':
tmpxft_0000397c_00000000-6_gpuLaplace.cudafe1.cpp:(.text+0x3e06): undefined reference to `__cudaPushCallConfiguration'
....
./libfmm.a(gpuCoulombVdW.o): In function `__sti____cudaRegisterAll()':
tmpxft_00003a87_00000000-6_gpuCoulombVdW.cudafe1.cpp:(.text.startup+0x189): undefined reference to `__cudaRegisterFatBinaryEnd'
....
I tried to find the installation of cuda:
whereis cuda
cuda: /usr/lib/cuda /usr/include/cuda.h /usr/local/cuda
I could not fix the error, can anyone give any hint to fix it?
Thank you.

Getting error: "nvlink error : Undefined reference to '_ZN8Strategy8backtestEPddd'"

I am getting the following error when running make for my CUDA (v7.5) application:
nvlink error : Undefined reference to '_ZN8Strategy8backtestEPddd'
I'm not sure why. It seems something is likely wrong with my Makefile. Here it is -- any ideas what might be causing the error? Thank you in advance!
CC = nvcc
CFLAGS = -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field
LFLAGS = -L/usr/local/lib -Llib $(shell pkg-config --libs libmongoc-1.0 libbson-1.0)
INCLUDES = -I/usr/include -I/usr/local/include -Iinclude $(shell pkg-config --cflags libmongoc-1.0 libbson-1.0)
LIBS = -lgsl -lcblas
BIN = ./bin
OBJDIR = ./obj
OBJ = factories/optimizationStrategyFactory.o positions/callPosition.o positions/putPosition.o \
positions/position.o strategies/reversalsOptimizationStrategy.o strategies/optimizationStrategy.o \
strategies/strategy.o factories/optimizerFactory.o optimizers/reversalsOptimizer.o optimizers/optimizer.o \
factories/dataParserFactory.o dataParsers/oandaDataParser.o dataParsers/dataParser.o \
studies/study.o studies/smaStudy.o studies/emaStudy.o studies/rsiStudy.o \
studies/stochasticOscillatorStudy.o studies/polynomialRegressionChannelStudy.o
all: prepareData optimize
prepareData: src/prepareData.cu $(addprefix lib/,$(OBJ))
#mkdir -p $(BIN)
$(CC) $(CFLAGS) $(INCLUDES) -o $(BIN)/$# src/prepareData.cu $(addprefix $(OBJDIR)/,$(addprefix lib/,$(OBJ))) $(LFLAGS) $(LIBS)
optimize: src/optimize.cu $(addprefix lib/,$(OBJ))
#mkdir -p $(BIN)
$(CC) $(CFLAGS) $(INCLUDES) -o $(BIN)/$# src/optimize.cu $(addprefix $(OBJDIR)/,$(addprefix lib/,$(OBJ))) $(LFLAGS) $(LIBS)
%.o: %.cu
#mkdir -p $(OBJDIR)/lib/strategies $(OBJDIR)/lib/positions $(OBJDIR)/lib/factories $(OBJDIR)/lib/optimizers $(OBJDIR)/lib/dataParsers $(OBJDIR)/lib/studies
$(CC) $(CFLAGS) $(INCLUDES) -o $(OBJDIR)/$# --device-c $<
clean:
rm -rf $(BIN) $(OBJDIR)
And here is the full compiler output:
rm -rf ./bin ./obj
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/factories/optimizationStrategyFactory.o --device-c lib/factories/optimizationStrategyFactory.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/positions/callPosition.o --device-c lib/positions/callPosition.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/positions/putPosition.o --device-c lib/positions/putPosition.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/positions/position.o --device-c lib/positions/position.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/strategies/reversalsOptimizationStrategy.o --device-c lib/strategies/reversalsOptimizationStrategy.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/strategies/optimizationStrategy.o --device-c lib/strategies/optimizationStrategy.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/strategies/strategy.o --device-c lib/strategies/strategy.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/factories/optimizerFactory.o --device-c lib/factories/optimizerFactory.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/optimizers/reversalsOptimizer.o --device-c lib/optimizers/reversalsOptimizer.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/optimizers/optimizer.o --device-c lib/optimizers/optimizer.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/factories/dataParserFactory.o --device-c lib/factories/dataParserFactory.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/dataParsers/oandaDataParser.o --device-c lib/dataParsers/oandaDataParser.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/dataParsers/dataParser.o --device-c lib/dataParsers/dataParser.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/studies/study.o --device-c lib/studies/study.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/studies/smaStudy.o --device-c lib/studies/smaStudy.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/studies/emaStudy.o --device-c lib/studies/emaStudy.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/studies/rsiStudy.o --device-c lib/studies/rsiStudy.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/studies/stochasticOscillatorStudy.o --device-c lib/studies/stochasticOscillatorStudy.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./obj/lib/studies/polynomialRegressionChannelStudy.o --device-c lib/studies/polynomialRegressionChannelStudy.cu
nvcc -std=c++11 -m64 -arch=compute_35 -code=sm_35 --compiler-options=-Wall,-Wno-unused-function,-Wno-unused-local-typedef,-Wno-unused-private-field -I/usr/include -I/usr/local/include -Iinclude -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -o ./bin/prepareData src/prepareData.cu ./obj/lib/factories/optimizationStrategyFactory.o ./obj/lib/positions/callPosition.o ./obj/lib/positions/putPosition.o ./obj/lib/positions/position.o ./obj/lib/strategies/reversalsOptimizationStrategy.o ./obj/lib/strategies/optimizationStrategy.o ./obj/lib/strategies/strategy.o ./obj/lib/factories/optimizerFactory.o ./obj/lib/optimizers/reversalsOptimizer.o ./obj/lib/optimizers/optimizer.o ./obj/lib/factories/dataParserFactory.o ./obj/lib/dataParsers/oandaDataParser.o ./obj/lib/dataParsers/dataParser.o ./obj/lib/studies/study.o ./obj/lib/studies/smaStudy.o ./obj/lib/studies/emaStudy.o ./obj/lib/studies/rsiStudy.o ./obj/lib/studies/stochasticOscillatorStudy.o ./obj/lib/studies/polynomialRegressionChannelStudy.o -L/usr/local/lib -Llib -L/usr/local/lib -lsasl2 -lssl -lcrypto -lz -lmongoc-1.0 -lbson-1.0 -lgsl -lcblas
nvlink info : Function '_ZN12CallPosition13getProfitLossEv' has address taken but no possible call to it
nvlink info : Function '_ZN12CallPosition18getTransactionTypeEv' has address taken but no possible call to it
nvlink info : Function '_ZN11PutPosition13getProfitLossEv' has address taken but no possible call to it
nvlink info : Function '_ZN11PutPosition18getTransactionTypeEv' has address taken but no possible call to it
nvlink info : Function '_ZN8PositionD1Ev' has address taken but no possible call to it
nvlink info : Function '_ZN8PositionD0Ev' has address taken but no possible call to it
nvlink info : Function '_ZN12CallPositionD1Ev' has address taken but no possible call to it
nvlink info : Function '_ZN12CallPositionD0Ev' has address taken but no possible call to it
nvlink info : Function '_ZN11PutPositionD1Ev' has address taken but no possible call to it
nvlink info : Function '_ZN11PutPositionD0Ev' has address taken but no possible call to it
nvlink info : Function '_ZN29ReversalsOptimizationStrategy8backtestEPddd' has address taken but no possible call to it
nvlink info : Function '_ZN20OptimizationStrategy4tickEPd' has address taken but no possible call to it
nvlink info : Function '_ZN8Strategy8backtestEPddd' has address taken but no possible call to it
nvlink error : Undefined reference to '_ZN8Strategy8backtestEPddd' in './obj/lib/strategies/optimizationStrategy.o'
make: *** [prepareData] Error 255
Note this started happening around the time I added --device-c (which some code changes require).
Turns out objects passed to CUDA kernels cannot have virtual functions. See this thread.
However, it seems that objects instantiated and used only within the kernel can have virtual functions.

Using external shared library in R

I have written a few c++ function for integration into an R package by Rcpp, and these functions reply on the boost filesystem library. I have specified these in src/Makevar:
PKG_LIBS = -lboost_system -lboost_filesystem
And the package compiles ok:
==> R CMD INSTALL --preclean --no-multiarch --with-keep.source txtutils2
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c RcppExports.cpp -o RcppExports.o
* installing to library ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library’
* installing *source* package ‘txtutils2’ ...
** libs
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c bedcollc.cpp -o bedcollc.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c bedcollr.cpp -o bedcollr.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c countlines.cpp -o countlines.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c fileSize.cpp -o fileSize.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c ncols.cpp -o ncols.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c printlines.cpp -o printlines.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c readbed.cpp -o readbed.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c readcol.cpp -o readcol.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -std=c++11 -c readcols.cpp -o readcols.o
clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o txtutils2.so RcppExports.o bedcollc.o bedcollr.o countlines.o fileSize.o ncols.o printlines.o readbed.o readcol.o readcols.o -lboost_system -lboost_filesystem -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/3.1/Resources/library/txtutils2/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (txtutils2)
But when I try to load it, something goes wrong:
> library(txtutils2)
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/txtutils2/libs/txtutils2.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/txtutils2/libs/txtutils2.so, 6): Library not loaded: libboost_system.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/txtutils2/libs/txtutils2.so
Reason: image not found
Error: package or namespace load failed for ‘txtutils2’
I am on osx 10.10, if that matters.
General instructions on usage of external shared libs in R is also most welcome.
As far as I know, what you have met is not the problem of Rcpp even not the problem of R. It may be about linking on OSX.
I don't use Mac, so I just give you some advice. Try
otool -L yourpackagename.so
You should see a link to the boost library you use. You need to check whether the path is right.

C++11 link issue with pthread

I have wrote a simple code which uses c++11 thread. It compiles correct but when I try to run it I have the following error:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Aborted (core dumped)
I am using gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1). This is the output of the makefile which I am using
g++ -std=c++11 -DHAVE_CONFIG_H -I. -I../../../.. -I../../../.. -I/usr/local_machine/openmpi-1.6.5/include -pthread -DMPIPP_H -DENABLE_MPI=1 -O3 -Wall -DNDEBUG -funroll-loops -finline-functions -pthread -fomit-frame-pointer -ffast-math -mfpmath=sse -msse3 -MT threadtest-threadtest.o -MD -MP -MF .deps/threadtest-threadtest.Tpo -c -o threadtest-threadtest.o `test -f 'threadtest.cc' || echo './'`threadtest.cc
mv -f .deps/threadtest-threadtest.Tpo .deps/threadtest-threadtest.Po
/bin/bash ../../../../libtool --tag=CXX --mode=link g++ -std=c++11 -O3 -Wall -DNDEBUG -funroll-loops -finline-functions -pthread -fomit-frame-pointer -ffast-math -mfpmath=sse -msse3 -o threadtest threadtest-threadtest.o -pthread -L/usr/local_machine/openmpi-1.6.5/lib -lmpi -ldl -lm -Wl,--export-dynamic -lrt -lnsl -lutil -lm -ldl ../../../../lib/libdunecommon.la -lm
libtool: link: g++ -std=c++11 -O3 -Wall -DNDEBUG -funroll-loops -finline-functions -pthread -fomit-frame-pointer -ffast-math -mfpmath=sse -msse3 -o threadtest threadtest-threadtest.o -pthread -Wl,--export-dynamic -L/usr/local_machine/openmpi-1.6.5/lib /usr/local_machine/openmpi-1.6.5/lib/libmpi.so -lrt -lnsl -lutil -ldl ../../../../lib/.libs/libdunecommon.a -llapack -lblas -lgfortran -lquadmath -lm -pthread -Wl,-rpath -Wl,/usr/local_machine/openmpi-1.6.5/lib -Wl,-rpath -Wl,/usr/local_machine/openmpi-1.6.5/lib
As you can see there is the flag -pthread. What am I doing wrong? Because if I compile a simple code as
g++ threadstest.cc -o threadstest -pthread -std=c++11
everything works fine therefore in my makefile there is something which interferes with -pthread but I don't understand what it is.
Additional information: a workaround which works is to add -Wl,--no-as-needed at the linking stage.
the answer for similar question "Compiling multithread code with g++ (-Wl,--no-as-needed NOT working)"
is
-pthread is a flag for the compiler, not the linker, the right one for the linker is -lpthread

MATLAB MEX C++ file Compiling error g++ command not found

I'm trying to compile a C++ file (mysql.cpp) in MATLAB with MEX Function on Linux server.
I'm getting this error which I'm not able to figure out why?
/opt/MATLAB/R2013a/bin/mex: line 1343: g++: command not found
mex: compile of ' "mysql.cpp"' failed.
I use this command:
mex -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient mysql.cpp
and here are the MEX Compiler Configuration Details: -
-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
FILE = /root/.matlab/R2013a/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /opt/MATLAB/R2013a
-> CC = gcc
-> CC flags:
CFLAGS = -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread
CDEBUGFLAGS = -g
COPTIMFLAGS = -O -DNDEBUG
CLIBS = -Wl,-rpath-link,/opt/MATLAB/R2013a/bin/glnxa64 -L/opt/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
arguments = -DMX_COMPAT_32
-> CXX = g++
-> CXX flags:
CXXFLAGS = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O -DNDEBUG
CXXLIBS = -Wl,-rpath-link,/opt/MATLAB/R2013a/bin/glnxa64 -L/opt/MATLAB/R2013a
/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -Wl,-rpath-link,/opt/MATLAB/R2013a/bin/glnxa64 -L/opt/MATLAB/R2013a
/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> LD = g++
-> Link flags:
LDFLAGS = -pthread -shared -Wl,--version-script,/opt/MATLAB/R2013a/extern
/lib/glnxa64/mexFunction.map -Wl,--no-undefined
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexa64
arguments = -Lusr/lib/mysql -lmysqlclient
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments = -Lusr/lib/mysql -lmysqlclient
Please help me to find out what is wrong.
Yeah, you should install a compiler before compiling. Mex is just a tool which calls one underneath and since g++ is the C++ compiler of gcc you should install this one.
As far as I know it will still not work, because matlab supports only gcc 4.3 (not sure about that). So install a gcc and run
mex -setup
Afterwards you should be able to compile.