‘isnan’ was not declared in this scope error during "make" - c++

I am trying to make g_elpot (https://jugit.fz-juelich.de/computational-neurophysiology/g_elpot) and got the following error:
g++ -O3 -Wno-unused -funroll-all-loops -std=c++11 -fopenmp -I/usr/local/gromacs/include -I/usr/local/fftw/include -c -o dx.o dx.cpp
dx.cpp: In function ‘void write_dx_file(real*, real*, int*, real (*)[3], const char*, unit_t)’:
dx.cpp:41:33: error: ‘isnan’ was not declared in this scope
if (isnan(grid_values[i]))
^
dx.cpp:41:33: note: suggested alternative:
In file included from /usr/local/gromacs/include/gromacs/math/vectypes.h:40:0,
from dx.h:3,
from dx.cpp:1:
/usr/include/c++/5/cmath:641:5: note: ‘std::isnan’
isnan(_Tp __x)
^
<builtin>: recipe for target 'dx.o' failed
make: *** [dx.o] Error 1
I am using g++ (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609 and cmake version 3.14.0.
My Makefile is:
# Generated automatically from Makefile.in by configure.
#
# This is a Gromacs 3.0 template makefile for your own utility programs.
#
# Copy this file to whatever directory you are using for your own
# software and add more targets like the template one below.
#
# If you are using gmake it is relatively straightforward to add
# an include based on environment variables (like previous Gromacs versions)
# to select compiler flags and stuff automatically, but below it is static:
#
# Variables set by the configuration script:
LIBS = -lgromacs -lfftw3f -lm -fopenmp
LDFLAGS = -L/usr/local/gromacs/lib -L/usr/local/fftw/lib
CPPFLAGS = -I/usr/local/gromacs/include -I/usr/local/fftw/include
CXXFLAGS = -O3 -Wno-unused -funroll-all-loops -std=c++11 -fopenmp
CXX = g++
LD = $(CXX)
g_elpot: g_elpot.o elmap_grid.o spline_interpolation.o fitting.o dx.o spme_grid.o convergence_check.o frame.o result.o units.o molecule.o memory_check.o debug.o
$(LD) $(LDFLAGS) -o $# $^ $(LIBS)
I was trying to run g_elpot and wanted to install it and ran into this issue while running make

Related

How to compile DPDK application such as examples to support C++?

How should I modify Makefiles of DPDK to support c++ compilation? I tried by adding CFLAGS += -lstdc++ to the Makefile of the helloworld example but it seems not working. Is there a more standard way to do that?
Edited:
I'm using the makefile of helloworld example in DPDK 20.08 with some small modifications. I'm building it on ubuntu 20.04 ,and which is not cross-compilation. The DPDK is built with dpdk-setup script and not meson. The makefile is
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation
# binary name
APP = rss_helper
# all source are stored in SRCS-y
# SRCS-y := main.c
SRCS-y := test.cpp
# Build using pkg-config variables if possible
ifeq ($(shell pkg-config --exists libdpdk && echo 0),0)
all: shared
# all: static
.PHONY: shared static
shared: build/$(APP)-shared
ln -sf $(APP)-shared build/$(APP)
static: build/$(APP)-static
ln -sf $(APP)-static build/$(APP)
PKGCONF ?= pkg-config
PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null)
CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk)
LDFLAGS_STATIC = $(shell $(PKGCONF) --static --libs libdpdk)
build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
$(CC) $(CFLAGS) $(SRCS-y) -o $# $(LDFLAGS) $(LDFLAGS_SHARED)
build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build
$(CC) $(CFLAGS) $(SRCS-y) -o $# $(LDFLAGS) $(LDFLAGS_STATIC)
build:
#mkdir -p $#
.PHONY: clean
clean:
rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared
test -d build && rmdir -p build || true
else
ifeq ($(RTE_SDK),)
$(error "Please define RTE_SDK environment variable")
endif
# Default target, detect a build directory, by looking for a path with a .config
RTE_TARGET ?= $(notdir $(abspath $(dir $(firstword $(wildcard $(RTE_SDK)/*/.config)))))
include $(RTE_SDK)/mk/rte.vars.mk
CPPFLAGS += -O3
CPPFLAGS += $(WERROR_FLAGS)
CPPFLAGS += -DALLOW_EXPERIMENTAL_API
CPPFLAGS += -lstdc++
include $(RTE_SDK)/mk/rte.extapp.mk
endif
I changed the name of the source file and flags. The source file test.cpp contains only iostream header and an empty main function (just for test). There are two errors:
can't find the test.cpp with cpp on. It works find when replace test.cpp in makefile with test.c while keeping the actual source file name as test.cpp.
LD rss_helper
gcc: error: test.cpp: No such file or directory
make[1]: *** [/home/syk/dpdk-20.08/mk/rte.app.mk:456: rss_helper] Error 1
make: *** [/home/syk/dpdk-20.08/mk/rte.extapp.mk:15: all] Error 2
Error for LD like below
g++ -O3 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -Wpointer-arith -Wcast-align -Wnested-externs -Wcast-qual -Wformat-nonliteral -Wformat-security -Wundef -Wwrite-strings -Wdeprecated -Wno-missing-field-initializers -Wimplicit-fallthrough=2 -Wno-format-truncation -Wno-address-of-packed-member -DALLOW_EXPERIMENTAL_API -lstdc++ -c -o test.o /home/syk/loadbalancing/rss_helper_demo/test.cpp
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
cc1plus: warning: command line option ‘-Wmissing-prototypes’ is valid for C/ObjC but not for C++
cc1plus: warning: command line option ‘-Wold-style-definition’ is valid for C/ObjC but not for C++
cc1plus: warning: command line option ‘-Wnested-externs’ is valid for C/ObjC but not for C++
LD rss_helper
/usr/bin/ld: test.o: in function `_GLOBAL__sub_I_main':
test.cpp:(.text.startup+0x20): undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: test.cpp:(.text.startup+0x27): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
make[1]: *** [/home/syk/dpdk-20.08/mk/rte.app.mk:456: rss_helper] Error 1
make: *** [/home/syk/dpdk-20.08/mk/rte.extapp.mk:15: all] Error 2
I tried to resolve it by added -lstdc++ but still had it.
Edited-2:
The source file:
#include <iostream>
#include <rte_eal.h>
using namespace std;
class A{
int a;
};
int
main(void){
return 0;
}
It can't include iostream and rte_eal either.
there are 2 possible ways to solve this issue
set environment set CC=g++. Then execute make
edit Makefile to add CC = g++
with these changes I am able build and run the sample code.
linux-vdso.so.1 (0x00007fff0a3e6000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f1389440000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f138904f000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1388cb1000)
/lib64/ld-linux-x86-64.so.2 (0x00007f13899cb000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f1388a99000)
and
ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=6e3fb6ed5f48b8f66fe4c05118f7b6bf6a9a1235, not stripped
You need to modify the makefile inorder to adapt C++:
You need to change CFLAGS to CPPFLAGS
See below reference example:
ifeq ($(RTE_SDK),)
$(error "Please define RTE_SDK environment variable")
endif
# Default target, can be overriden by command line or environment
RTE_TARGET ?= x86_64-native-linuxapp-gcc
include $(RTE_SDK)/mk/rte.vars.mk
# binary name
APP = dpdkrecv
# all source are stored in SRCS-y
SRCS-y := main.c syncshm.c cqf.cpp countingquotientfilter.cpp murmurhash3.cpp
CPPFLAGS += -O3 -mbmi2
CFLAGS += $(WERROR_FLAGS)
include $(RTE_SDK)/mk/rte.extapp.mk
Please share the Makefile,
I am adding
#include algorithm
dpdk ver: dpdk-stable-18.11.2 ,
build with
sudo make install T=x86_64-native-linuxapp-gcc DESTDIR=install

math.h not found when using llvm

I'm trying to build a python wrapper using the following Makefile:
CC=/usr/local/opt/llvm/bin/clang
OS_NAME=$(shell uname -s)
ifeq ($(OS_NAME),Linux)
LAPACKLDFLAGS=/usr/lib64/atlas/libsatlas.so # single-threaded blas
#LAPACKLDFLAGS=/usr/lib64/atlas/libtatlas.so # multi-threaded blas
#BLAS_THREADING=-D MULTITHREADED_BLAS # remove this if wrong
endif
ifeq ($(OS_NAME),Darwin) # Mac OS X
LAPACKLDFLAGS=-framework Accelerate # for OS X
endif
LAPACKCFLAGS=-Dinteger=int $(BLAS_THREADING)
STATICLAPACKLDFLAGS=-fPIC -Wall -g -fopenmp -static -static-libstdc++ /home/lear/douze/tmp/jpeg-6b/libjpeg.a /usr/lib64/libpng.a /usr/lib64/libz.a /usr/lib64/libblas.a /usr/lib/gcc/x86_64-redhat-linux/4.9.2/libgfortran.a /usr/lib/gcc/x86_64-redhat-linux/4.9.2/libquadmath.a # statically linked version
CFLAGS= -fPIC -Wall -g -std=c++11 $(LAPACKCFLAGS) -fopenmp -DUSE_OPENMP -O3
LDFLAGS=-fPIC -Wall -g -ljpeg -lpng -fopenmp
CPYTHONFLAGS=-I/usr/include/python2.7
SOURCES := $(shell find . -name '*.cpp' ! -name 'deepmatching_matlab.cpp')
OBJ := $(SOURCES:%.cpp=%.o)
HEADERS := $(shell find . -name '*.h')
all: deepmatching
.cpp.o: %.cpp %.h
$(CC) -o $# $(CFLAGS) -c $+
deepmatching: $(HEADERS) $(OBJ)
$(CC) -o $# $^ $(LDFLAGS) $(LAPACKLDFLAGS)
deepmatching-static: $(HEADERS) $(OBJ)
$(CC) -o $# $^ $(STATICLAPACKLDFLAGS)
python: $(HEADERS) $(OBJ)
# swig -python $(CPYTHONFLAGS) deepmatching.i # not necessary, only do if you have swig compiler
/usr/local/opt/llvm/bin/clang $(CFLAGS) -c deepmatching_wrap.c $(CPYTHONFLAGS)
/usr/local/opt/llvm/bin/clang -shared $(LDFLAGS) $(LAPACKLDFLAGS) deepmatching_wrap.o $(OBJ) -o _deepmatching.so $(LIBFLAGS)
clean:
rm -f $(OBJ) deepmatching *~ *.pyc .gdb_history deepmatching_wrap.o _deepmatching.so deepmatching.mex???
Previously, CC was set to g++, however, when I tried to build it like this, I'd get "ERROR: clang: error: unsupported option '-fopenmp".
Now I installed "brew install llvm" as this comes with the -fopenmp option. The unsupported error is resolved for now, but now the compiler doesn't seem to find a header file:
(base) MacBook-Pro-van-Brent:deepmatching BrentDeHauwere$ make python
/usr/local/opt/llvm/bin/clang -o hog.o -fPIC -Wall -g -std=c++11 -Dinteger=int -fopenmp -DUSE_OPENMP -O3 -I/usr/local/opt/llvm/include -c hog.cpp
In file included from hog.cpp:18:
In file included from ./std.h:20:
/usr/local/opt/llvm/bin/../include/c++/v1/math.h:300:15: fatal error: 'math.h' file not found
#include_next <math.h>
^~~~~~~~
1 error generated.
make: *** [hog.o] Error 1
I've tried setting options (I might have set them incorrectly) like -L/usr/local/opt/llvm/lib and -I/usr/local/opt/llvm/include, but no result so far. Any idea how I could point the compiler to the right direction for the header files?
Try running xcode-select —install in your terminal. This installs the xcode command line tools which should also install system headers files (as part of the macos sdk) and set your system include paths.

Error while compiling a project which includes CPLEX tool

I am working on the project which has to include the CPLEX tool at some point.
More in detail, I have the following classes implemented
(i.e. the corresponding files): Random.cpp, Instance.cpp, Timer.cpp. Solution.cpp which are included into Hybrid_ea.cpp which also have to include cplex library.
Finally, the project has been executed by running Algorithm.cpp (the main() function defined here).
I want to run the project on Linux platform, creating Makefile which looks like:
TARGET = Algorithm
CXXFLAGS = -ansi -O3
GENOBJS = Random.o
#CPLOBJS = Timer.o Random.o Instance.o Hybrid_ea.o
GREOBJS = Timer.o Random.o Instance.o Solution.o Hybrid_ea.o
SYSTEM = x86-64_linux
LIBFORMAT = static_pic
CPLEXDIR = /home/root/Desktop/projects/software/cplex-12.5/cplex
CONCERTDIR = /home/root/Desktop/projects/software/cplex-12.5/concert
CCC = g++
CCOPT = -m64 -O -fPIC -fexceptions -DNDEBUG -DIL_STD -std=c++11 -fpermissive -w
CPLEXBINDIR = $(CPLEXDIR)/bin/$(BINDIST)
CPLEXLIBDIR = $(CPLEXDIR)/lib/$(SYSTEM)/$(LIBFORMAT)
CONCERTLIBDIR = $(CONCERTDIR)/lib/$(SYSTEM)/$(LIBFORMAT)
CCLNFLAGS = -L$(CPLEXLIBDIR) -lilocplex -lcplex -L$(CONCERTLIBDIR) -lconcert -lm -pthread
CLNFLAGS = -L$(CPLEXLIBDIR) -lcplex -lm -pthread
CONCERTINCDIR = $(CONCERTDIR)/include
CPLEXINCDIR = $(CPLEXDIR)/include
CCFLAGS = $(CCOPT) -I$(CPLEXINCDIR) -I$(CONCERTINCDIR)
all: ${TARGET}
Algorithm: Algorithm.o $(GREOBJS)
$(CCC) $(CCFLAGS) Algorithm.o $(GREOBJS) -o Algorithm $(CCLNFLAGS)
Algorithm.o: Algorithm.cpp
$(CCC) -c $(CCFLAGS) Algorithm.cpp -o Algorithm.o
clean:
#rm -f *~ *.o ${TARGET} core
The linking process is somehow wrong. I checked, my CPLEX version is the right one since the others, simpler projects can be executed;
The full output given when trying to compile the project:
g++ -c -m64 -O -fPIC -fexceptions -DNDEBUG -DIL_STD -std=c++11 -fpermissive -w -I/home/root/Desktop/projects/LCAPS_software/cplex-12.5/cplex/include -I/home/root/Desktop/projects/LCAPS_software/cplex-12.5/concert/include Algorithm.cpp -o Algorithm.o
g++ -ansi -O3 -c -o Timer.o Timer.cc
g++ -ansi -O3 -c -o Random.o Random.cc
g++ -ansi -O3 -c -o Instance.o Instance.cpp
g++ -ansi -O3 -c -o Solution.o Solution.cpp
g++ -ansi -O3 -c -o hybrid_ea.o hybrid_ea.cpp
In file included from hybrid_ea.cpp:22:0:
hybrid_ea.h:39:10: fatal error: ilcplex/ilocplex.h: No such file or directory
#include <ilcplex/ilocplex.h>
^~~~~~~~~~~~~~~~~~~~
compilation terminated.
<builtin>: recipe for target 'hybrid_ea.o' failed
make: *** [hybrid_ea.o] Error 1
Any help would be appreciated.
Only the file Algorithm.cpp is compiled with appropriate options for finding the CPLEX include files:
-I/home/root/Desktop/projects/LCAPS_software/cplex-12.5/cplex/include
-I/home/root/Desktop/projects/LCAPS_software/cplex-12.5/concert/include
As hybrid_ea.h also tries to include some CPLEX header files, the compilation of hybrid_ea.cpp should also have the options above.
If the makefile that you posted in your question is complete, then I suspect that the issue is the following: you didn't define a specific command to compile any .cc or .cpp file, except for Algorithm.cpp. Therefore, all other files are compiled using a default command g++ -ansi -O3 -c -o [file].o [file].cpp. And this default command doesn't have the include directives for the location of the CPLEX libraries.
As explained in ftp://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_10.html, these files are compiled using make's implicit rules. The implicit rule for C++ files is to use $(CXX) -c $(CPPFLAGS) $(CXXFLAGS). Notice how this rule uses CPPFLAGS and CXXFLAGS rather than the variable CCFLAGS that you defined at the end of your makefile to include the proper include directives.
So changing the end of your makefile to the following should work:
CPPFLAGS = $(CCOPT) -I$(CPLEXINCDIR) -I$(CONCERTINCDIR)
all: ${TARGET}
Algorithm: Algorithm.o $(GREOBJS)
$(CCC) $(CCFLAGS) Algorithm.o $(GREOBJS) -o Algorithm $(CCLNFLAGS)
clean:
#rm -f *~ *.o ${TARGET} core
Once you define the variable CPPFLAGS, it will be used automatically to compile any .cpp file that you have in your project.

Error when compiling c++11 code in a Matlab mex file

I have downloaded the following code:
CVPR 2014 intersection over union optimization code
cvpr2014-iou-code-1.0.zip
http://research.microsoft.com/en-us/downloads/e164fe21-ef2b-4e34-98c1-4868968abb06/
What I get is an archive with two folders, one called src/ and another one called matlab/. I am running Linux Fedora 19 and I can compile the code in src/ just fine. The problem arises when I try to compile the code in matlab/.
The README says:
Matlab compilation
------------------
From within Matlab, configure the compiler using "mex -setup", then adjust the
paths in matlab\compile_windows.m or matlab/compile_linux.m scripts and run
either "compile_linux.m" or "compile_windows.m" in the "matlab" directory.
More specifically for Linux:
Linux
=====
From within Matlab run "mex -setup", then edit the mexopts.sh file and modify
the settings
CXXFLAGS='-std=c++11 -fopenmp -march=native -D_GNU_SOURCE'
CXXLIBS="$RPATH $MLIBS -lm -lgomp"
CXXOPTIMFLAGS='-Ofast -DNDEBUG'
This will enable OpenMP and C++11 and should work from G++ 4.7 onwards.
From the matlab/ directory, call compile_linux to build all mex files.
So I open matlab and run mex -setup. I answer yes to the question:
>> mex -setup
Options files control which compiler to use, the compiler and link command
options, and the runtime libraries to link against.
Using the 'mex -setup' command selects an options file that is
placed in /user/wok/home/.matlab/R2012b and used by default for 'mex'. An options
file in the current working directory or specified on the command line
overrides the default options file in /user/wok/home/.matlab/R2012b.
To override the default options file, use the 'mex -f' command
(see 'mex -help' for more information).
The options files available for mex are:
1: /opt/matlab2012b/bin/mexopts.sh :
Template Options file for building gcc MEX-files
0: Exit with no changes
Enter the number of the compiler (0-1):
1
Overwrite /user/wok/home/.matlab/R2012b/mexopts.sh ([y]/n)?
y
/opt/matlab2012b/bin/mexopts.sh is being copied to
/user/wok/home/.matlab/R2012b/mexopts.sh
**************************************************************************
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the new
API. You can find more information about this at:
http://www.mathworks.com/help/techdoc/matlab_external/bsflnue-1.html
Building with the -largeArrayDims option enables the new API.
**************************************************************************
Then I edit the file /user/wok/home/.matlab/R2012b/mexopts.sh and I follow the instructions from the README:
CXX='g++'
CXXFLAGS='-ansi -D_GNU_SOURCE'
CXXFLAGS="$CXXFLAGS -D_FILE_OFFSET_BITS=64"
CXXFLAGS="$CXXFLAGS -fPIC -pthread"
CXXLIBS="$RPATH $MLIBS -lm"
CXXOPTIMFLAGS='-O -DNDEBUG'
CXXDEBUGFLAGS='-g'
becomes:
CXX='g++'
CXXFLAGS='-std=c++11 -fopenmp -march=native -D_GNU_SOURCE'
CXXLIBS="$RPATH $MLIBS -lm -lgomp"
CXXOPTIMFLAGS='-Ofast -DNDEBUG'
CXXDEBUGFLAGS='-g'
After this step, I open matlab and edit compile_linux.m to add the path to Boost:
% You need to have boost 1.49 or higher installed (package libboost-dev on
% most distributions)
%
% Tested on Ubuntu 13.10, Matlab R2012b, gcc 4.8.1
% TODO: this assumes that boost headers are available in /usr/include, as on
% most systems. If you manually installed boost, please add -I/path/to/boost
mex -v -O ...
-output mex_voc_optimize -I../src ...
-I/user/wok/home/Softwares/Boost_1.54/include/boost ...
mex_voc_optimize.cpp matlab_helpers.cpp ...
-largeArrayDims
Edit: Following the first comment from Praetorian, I have added the -v flag.
Finally I run compile_linux, only to get a long list of errors, which I have shortened and pasted below:
>> compile_linux
-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
FILE = /user/wok/home/.matlab/R2012b/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /opt/matlab2012b
-> 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/matlab2012b/bin/glnxa64 -L/opt/matlab2012b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
arguments =
-> 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/matlab2012b/bin/glnxa64 -L/opt/matlab2012b/bin/glnxa64 -lmx -lmex -lmat -lm
arguments =
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -Wl,-rpath-link,/opt/matlab2012b/bin/glnxa64 -L/opt/matlab2012b/bin/glnxa64 -lmx -lmex -lmat -lm
arguments =
-> LD = g++
-> Link flags:
LDFLAGS = -pthread -shared -Wl,--version-script,/opt/matlab2012b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexa64
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------
Warning: You are using gcc version "4.8.2". The version
currently supported with MEX is "4.4.6".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
-> g++ -c -I../src -I/user/wok/home/Softwares/Boost_1.54/include/boost -I/opt/matlab2012b/extern/include -I/opt/matlab2012b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread -O -DNDEBUG "mex_voc_optimize.cpp"
In file included from /usr/include/c++/4.8.2/cstdint:35:0,
from mex_voc_optimize.cpp:8:
/usr/include/c++/4.8.2/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the \
^
In file included from ../src/lfp.h:18:0,
from ../src/voc.h:15,
from mex_voc_optimize.cpp:19:
../src/timing.h:15:2: error: ‘chrono’ in namespace ‘std’ does not name a type
std::chrono::time_point<std::chrono::high_resolution_clock> start_time;
^
../src/timing.h: In member function ‘double timer::elapsed_this_period() const’:
../src/timing.h:20:8: error: ‘std::chrono’ has not been declared
std::chrono::time_point<std::chrono::high_resolution_clock> end_time
^
../src/timing.h:20:32: error: ‘std::chrono’ has not been declared
std::chrono::time_point<std::chrono::high_resolution_clock> end_time
until
../src/voc.h:418:31: note: ‘P’ declared here, later in the translation unit
alpha[k_best] += P(j,k_best);
^
../src/voc.h: In instantiation of ‘std::pair<double, double> voc::prediction_function<TFloat>::compute_objective_c(int) const [with TFloat = double]’:
../src/voc.h:328:56: required from ‘double voc::prediction_function<TFloat>::compute_objective() const [with TFloat = double]’
mex_voc_optimize.cpp:250:39: required from here
../src/voc.h:315:17: error: ‘P’ was not declared in this scope
A_c += P(i,c);
^
../src/voc.h:318:17: error: ‘P’ was not declared in this scope
D_c += P(i,c);
^
mex: compile of ' "mex_voc_optimize.cpp"' failed.
Error using mex (line 206)
Unable to complete successfully.
Error in compile_linux (line 9)
mex -O ...
>>
I have tried editing the code to remove every call to chrono (for timers), then to replace unordered_map with map, etc., but it is a pain. I would like to be able to compile the mex file in matlab/ just like I can compile the c++ code in src/
Thanks to Praetorian's comment, I could pinpoint the problem. I had edited the wrong lines in mexopts.sh. Indeed, the CXXFLAGS appears at 3 different places, I had edited the flags at the first place, but it was necessary and sufficient to edit it at the second place (the first place was a decoy).
See for instance:
$ grep -n CXXLIBS /user/wok/home/.matlab/R2012b/mexopts.sh
74: CXXLIBS="$RPATH $MLIBS -lm"
129: CXXLIBS="$RPATH $MLIBS -lm"
199: CXXLIBS="$MLIBS -lstdc++"
So I edited the lines around line 129. The following lines
CXX='g++'
CXXFLAGS='-ansi -D_GNU_SOURCE'
CXXFLAGS="$CXXFLAGS -fPIC -fno-omit-frame-pointer -pthread"
CXXLIBS="$RPATH $MLIBS -lm"
CXXOPTIMFLAGS='-O -DNDEBUG'
CXXDEBUGFLAGS='-g'
become
CXX='g++'
CXXFLAGS='-std=c++11 -fopenmp -march=native -D_GNU_SOURCE'
CXXFLAGS="$CXXFLAGS -fPIC -fno-omit-frame-pointer -pthread"
CXXLIBS="$RPATH $MLIBS -lm -lgomp"
CXXOPTIMFLAGS='-Ofast -DNDEBUG'
CXXDEBUGFLAGS='-g'

Automake & Autoconf - Program Doesn't Recognize Static Library Just Built

I am developing a library called libspellcheck, and a program that uses it to check spelling called spellcheck. Here is my directory structure:
libspellcheck
-> doc
-> man
-> libspellcheck (libspellcheck source)
-> spellcheck (spellcheck source)
I wanted to use a configure script instead of a plain Makefile as I had been using. Everything goes okay until I try compiling spellcheck:
Making all in libspellcheck
make[1]: Entering directory `/home/iandun/libspellcheck-devel/libspellcheck/libspellcheck'
g++ -DHAVE_CONFIG_H -I. -g -O2 -MT checker.o -MD -MP -MF .deps/checker.Tpo -c -o checker.o checker.cpp
mv -f .deps/checker.Tpo .deps/checker.Po
g++ -DHAVE_CONFIG_H -I. -g -O2 -MT SpellCorrector.o -MD -MP -MF .deps/SpellCorrector.Tpo -c -o SpellCorrector.o SpellCorrector.cpp
mv -f .deps/SpellCorrector.Tpo .deps/SpellCorrector.Po
rm -f libspellcheck.a
ar cru libspellcheck.a checker.o SpellCorrector.o
ranlib libspellcheck.a
make[1]: Leaving directory `/home/iandun/libspellcheck-devel/libspellcheck/libspellcheck'
Making all in spellcheck
make[1]: Entering directory `/home/iandun/libspellcheck-devel/libspellcheck/spellcheck'
g++ -DHAVE_CONFIG_H -I. -g -O2 -MT spellcheck.o -MD -MP -MF .deps/spellcheck.Tpo -c -o spellcheck.o spellcheck.cpp
spellcheck.cpp: In function 'int main(int, char**)':
spellcheck.cpp:111:21: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char *dictionary = "/etc/english.dict"; //Default Dictionary
^
spellcheck.cpp:164:14: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
dictionary = "/etc/english.dict";
^
mv -f .deps/spellcheck.Tpo .deps/spellcheck.Po
g++ -DHAVE_CONFIG_H -I. -g -O2 -MT meta.o -MD -MP -MF .deps/meta.Tpo -c -o meta.o meta.cpp
mv -f .deps/meta.Tpo .deps/meta.Po
g++ -g -O2 "../libspellcheck/libspellcheck.a" -o spellcheck spellcheck.o meta.o
spellcheck.o: In function `correctMisspelled(std::string, std::string)':
/home/iandun/libspellcheck-devel/libspellcheck/spellcheck/spellcheck.cpp:29: undefined reference to `correctSpelling(std::string, std::string)'
spellcheck.o: In function `doFileCheck(char*, char*, char*, spelling)':
/home/iandun/libspellcheck-devel/libspellcheck/spellcheck/spellcheck.cpp:61: undefined reference to `check_spelling_file(char*, char*, std::string)'
spellcheck.o: In function `main':
/home/iandun/libspellcheck-devel/libspellcheck/spellcheck/spellcheck.cpp:193: undefined reference to `add_word(char*, char*)'
/home/iandun/libspellcheck-devel/libspellcheck/spellcheck/spellcheck.cpp:224: undefined reference to `check_spelling_string(char*, std::string, std::string)'
meta.o: In function `do_about_msg()':
/home/iandun/libspellcheck-devel/libspellcheck/spellcheck/meta.cpp:29: undefined reference to `lib_version()'
collect2: error: ld returned 1 exit status
make[1]: *** [spellcheck] Error 1
make[1]: Leaving directory `/home/iandun/libspellcheck-devel/libspellcheck/spellcheck'
make: *** [all-recursive] Error 1
I put a reference to libspellcheck.a in my Makefile.am file in the spellcheck directory:
CFLAGS = -m32 -Wall
LDFLAGS = "../libspellcheck/libspellcheck.a"
bin_PROGRAMS = spellcheck
spellcheck_SOURCES = spellcheck.cpp meta.cpp
And also changed my references to the spellcheck header file:
#include "../libspellcheck/spellcheck.h"
Here is my Makefile.am in the libspellcheck folder:
CFLAGS = -m32 -Wall
LDFLAGS =
lib_LIBRARIES = libspellcheck.a
libspellcheck_a_SOURCES = checker.cpp SpellCorrector.cpp
include_HEADERS = spellcheck.h SpellCorrector.h
Here is my Makefile.am in the main folder:
AUTOMAKE_OPTIONS = foreign
SUBDIRS = libspellcheck spellcheck man
And my configure.ac:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT(libspellcheck, 1.25, corinthianmonthly#hotmail.com)
AC_OUTPUT(Makefile libspellcheck/Makefile spellcheck/Makefile man/Makefile)
AC_CONFIG_SRCDIR([])
AC_CONFIG_HEADERS([])
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CXX
AC_PROG_RANLIB
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h,iostream,fstream,string,stdio.h,sstream,cctype,algorithm,boost/algorithm/string.hpp])
# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_TYPE_SIZE_T
# Checks for library functions.
AC_OUTPUT
What am I doing wrong?
CFLAGS = -m32 -Wall
LDFLAGS = "../libspellcheck/libspellcheck.a"
First, these are user flags. Use the AM_* forms instead.
Second, LDFLAGS is for flags. It is put near the start of the command line. But, for linking, order matters, so you want to use LDADD instead. There are a few ways to do this but perhaps the best is to use the per-target variable:
spellcheck_LDADD = ../libspellcheck/libspellcheck.a
You don't need those quotes.