i want compile mongodb from source in OpenBSD 6.6
according this link we must be changed compiler version in scons parameters but this parameters has not effect.
after install any requirements :
buildscripts/scons.py MONGO_VERSION=4.3.5 -j4 --d --cc=egcc --cxx=eg++ --disable-warnings-as-errors --ssl=off mongod mongo
output
scons version: 3.1.2
python version: 3 7 4 'final' 0
CC is gcc
gcc found in $PATH at /usr/bin/gcc
CXX is g++
g++ found in $PATH at /usr/bin/g++
Checking whether the C compiler works... yes
Checking whether the C++ compiler works... yes
Checking that the C++ compiler can link a C++ program... yes
Checking if C++ compiler "g++" is GCC... yes
Checking if C compiler "gcc" is GCC... yes
Detected a x86_64 processor
Checking if target OS openbsd is supported by the toolchain... yes
Checking if C compiler is GCC 8.2 or newer...no
Checking if C++ compiler is GCC 8.2 or newer...no
ERROR: Refusing to build with compiler that does not meet requirements
See /home/mongo-r4.3.5/build/scons/config.log for details
scons/config.log
file /home/mongo-r4.3.5/SConstruct,line 1300:
Configure(confdir = build/scons/opt/sconf_temp)
scons: Configure: Checking whether the C compiler works...
build/scons/opt/sconf_temp/conftest_737c003a897167642b70f8cdde8a0eaf_0.c <-
|
|int main(void)
|{
| return 0;
|}
|
gcc -o build/scons/opt/sconf_temp/conftest_737c003a897167642b70f8cdde8a0eaf_0_4e018b83dbae4a564d3abaec0d4c8465.o -c build/scons/opt/sconf_temp/conftest_737c003a897167642b70f8cdde8a0eaf_0.c
scons: Configure: yes
scons: Configure: Checking whether the C++ compiler works...
build/scons/opt/sconf_temp/conftest_737c003a897167642b70f8cdde8a0eaf_1.cpp <-
|
|int main(void)
|{
| return 0;
|}
|
g++ -o build/scons/opt/sconf_temp/conftest_737c003a897167642b70f8cdde8a0eaf_1_f4c6a764e80b6d2f336f5311c617b0d0.o -c build/scons/opt/sconf_temp/conftest_737c003a897167642b70f8cdde8a0eaf_1.cpp
scons: Configure: yes
scons: Configure: Checking that the C++ compiler can link a C++ program...
build/scons/opt/sconf_temp/conftest_ac30bfea77045c1c67c4f51773b51414_0.cpp <-
|
|#include <iostream>
|#include <cstdlib>
|
|int main() {
| std::cout << "Hello, World" << std::endl;
| return EXIT_SUCCESS;
|}
|
g++ -o build/scons/opt/sconf_temp/conftest_ac30bfea77045c1c67c4f51773b51414_0.o -c build/scons/opt/sconf_temp/conftest_ac30bfea77045c1c67c4f51773b51414_0.cpp
g++ -o build/scons/opt/sconf_temp/conftest_ac30bfea77045c1c67c4f51773b51414_0_fb048025625fc91381d082d9ffbfb5b5 build/scons/opt/sconf_temp/conftest_ac30bfea77045c1c67c4f51773b51414_0.o
scons: Configure: yes
scons: Configure: Checking if C++ compiler "g++" is GCC...
build/scons/opt/sconf_temp/conftest_4f0e9b4472e273623d18770138ab2253_0.cpp <-
|
|#if defined(__GNUC__) && !defined(__clang__)
|/* we are using toolchain defined(__GNUC__) && !defined(__clang__) */
|#else
|#error
|#endif
|
g++ -o build/scons/opt/sconf_temp/conftest_4f0e9b4472e273623d18770138ab2253_0_a53f49f0a5b49d3a1930add1c669ff5d.o -c build/scons/opt/sconf_temp/conftest_4f0e9b4472e273623d18770138ab2253_0.cpp
scons: Configure: yes
scons: Configure: Checking if C compiler "gcc" is GCC...
build/scons/opt/sconf_temp/conftest_4f0e9b4472e273623d18770138ab2253_1.c <-
|
|#if defined(__GNUC__) && !defined(__clang__)
|/* we are using toolchain defined(__GNUC__) && !defined(__clang__) */
|#else
|#error
|#endif
|
gcc -o build/scons/opt/sconf_temp/conftest_4f0e9b4472e273623d18770138ab2253_1_ea0252cf890ba84f7517f6fab562dbfd.o -c build/scons/opt/sconf_temp/conftest_4f0e9b4472e273623d18770138ab2253_1.c
scons: Configure: yes
build/scons/opt/sconf_temp/conftest_88c70ef45b935cd9e8e481913b1c9792_0.c <-
|
|#if defined(__arm__)
|/* Detected arm */
|#else
|#error not arm
|#endif
|
gcc -o build/scons/opt/sconf_temp/conftest_88c70ef45b935cd9e8e481913b1c9792_0_56b3766c230d14b22692a2e42ffc5229.o -c build/scons/opt/sconf_temp/conftest_88c70ef45b935cd9e8e481913b1c9792_0.c
build/scons/opt/sconf_temp/conftest_88c70ef45b935cd9e8e481913b1c9792_0.c:5:2: error: #error not arm
build/scons/opt/sconf_temp/conftest_aa9c0ec15eb67315005e48c7142d5763_0.c <-
|
|#if defined(__arm64__) || defined(__aarch64__)
|/* Detected aarch64 */
|#else
|#error not aarch64
|#endif
|
gcc -o build/scons/opt/sconf_temp/conftest_aa9c0ec15eb67315005e48c7142d5763_0_4907f655c8dbe62d40c4d0e3b5d4b442.o -c build/scons/opt/sconf_temp/conftest_aa9c0ec15eb67315005e48c7142d5763_0.c
build/scons/opt/sconf_temp/conftest_aa9c0ec15eb67315005e48c7142d5763_0.c:5:2: error: #error not aarch64
build/scons/opt/sconf_temp/conftest_067efcd68b39191f21773501607a9c8e_0.c <-
|
|#if defined(__i386) || defined(_M_IX86)
|/* Detected i386 */
|#else
|#error not i386
|#endif
|
gcc -o build/scons/opt/sconf_temp/conftest_067efcd68b39191f21773501607a9c8e_0_d874f0935a66606de8e5f3cd15acdcd5.o -c build/scons/opt/sconf_temp/conftest_067efcd68b39191f21773501607a9c8e_0.c
build/scons/opt/sconf_temp/conftest_067efcd68b39191f21773501607a9c8e_0.c:5:2: error: #error not i386
build/scons/opt/sconf_temp/conftest_c0b1d7f6a7951557b08b1879d2707012_0.c <-
|
|#if defined(__powerpc64__)
|/* Detected ppc64le */
|#else
|#error not ppc64le
|#endif
|
gcc -o build/scons/opt/sconf_temp/conftest_c0b1d7f6a7951557b08b1879d2707012_0_b03372b9b60e0f4472112644b94166bc.o -c build/scons/opt/sconf_temp/conftest_c0b1d7f6a7951557b08b1879d2707012_0.c
build/scons/opt/sconf_temp/conftest_c0b1d7f6a7951557b08b1879d2707012_0.c:5:2: error: #error not ppc64le
build/scons/opt/sconf_temp/conftest_6732939b06375ebbd46b5e264f3adb2e_0.c <-
|
|#if defined(__x86_64) || defined(_M_AMD64)
|/* Detected x86_64 */
|#else
|#error not x86_64
|#endif
|
gcc -o build/scons/opt/sconf_temp/conftest_6732939b06375ebbd46b5e264f3adb2e_0_750e5292f9cc0aa3a08058bf9313e042.o -c build/scons/opt/sconf_temp/conftest_6732939b06375ebbd46b5e264f3adb2e_0.c
scons: Configure: Detected a x86_64 processor
scons: Configure: Checking if target OS openbsd is supported by the toolchain...
build/scons/opt/sconf_temp/conftest_613421ebbfe8385e1a2f5e967e179457_0.c <-
|
|#if defined(__APPLE__)
|#include <TargetConditionals.h>
|#endif
|#if defined(__OpenBSD__)
|/* detected openbsd */
|#else
|#error
|#endif
|
gcc -o build/scons/opt/sconf_temp/conftest_613421ebbfe8385e1a2f5e967e179457_0_d1c28ea2c0ebdf26a0347f9a123b4526.o -c build/scons/opt/sconf_temp/conftest_613421ebbfe8385e1a2f5e967e179457_0.c
scons: Configure: yes
file /home/mongo-r4.3.5/SConstruct,line 2228:
Configure(confdir = build/scons/opt/sconf_temp)
scons: Configure: Checking if C compiler is GCC 8.2 or newer...
build/scons/opt/sconf_temp/conftest_fe605161eb05ed15a28dad50dd5c2d3a_0.c <-
|
|#if !defined(__GNUC__) || defined(__clang__)
|#error
|#endif
|
|#if (__GNUC__ < 8) || (__GNUC__ == 8 && __GNUC_MINOR__ < 2)
|#error GCC 8.2 or newer is required to build MongoDB
|#endif
|
|int main(int argc, char* argv[]) {
| return 0;
|}
|
Compiling build/scons/opt/sconf_temp/conftest_fe605161eb05ed15a28dad50dd5c2d3a_0_b43c784ef1c4af62a5fb20c3947ce1d6.o
build/scons/opt/sconf_temp/conftest_fe605161eb05ed15a28dad50dd5c2d3a_0.c:7:2: error: #error GCC 8.2 or newer is required to build MongoDB
scons: Configure: no
scons: Configure: Checking if C++ compiler is GCC 8.2 or newer...
build/scons/opt/sconf_temp/conftest_fe605161eb05ed15a28dad50dd5c2d3a_1.cpp <-
|
|#if !defined(__GNUC__) || defined(__clang__)
|#error
|#endif
|
|#if (__GNUC__ < 8) || (__GNUC__ == 8 && __GNUC_MINOR__ < 2)
|#error GCC 8.2 or newer is required to build MongoDB
|#endif
|
|int main(int argc, char* argv[]) {
| return 0;
|}
|
Compiling build/scons/opt/sconf_temp/conftest_fe605161eb05ed15a28dad50dd5c2d3a_1_f4a5f31a5fc1ca8177787fe1e36f2441.o
build/scons/opt/sconf_temp/conftest_fe605161eb05ed15a28dad50dd5c2d3a_1.cpp:7:2: error: #error GCC 8.2 or newer is required to build MongoDB
scons: Configure: no
submitted in jira
Where did you get that --cc=egcc --cxx=eg++ sets the compiler? That would imply the Mongo build scripts have set up to accept those two arguments, and at a quick glance (just the SConsctruct) I don't see it. Maybe try CC=egcc instead?
Related
I am trying to install scipy under cygwin with pip, unfortunately I have some compilation errors! I attach log files. I have searched on web but have found nothing.
thanks
2023-02-11T17:48:15,190 [250/1620] Compiling C++ object scipy/special/_ufuncs_cxx.cpython-39-x86_64-cygwin.dll.p/_faddeeva.cxx.o
2023-02-11T17:48:15,191 FAILED: scipy/special/_ufuncs_cxx.cpython-39-x86_64-cygwin.dll.p/_faddeeva.cxx.o
2023-02-11T17:48:15,192 c++ -Iscipy/special/_ufuncs_cxx.cpython-39-x86_64-cygwin.dll.p -Iscipy/special -I../../scipy/special -I/tmp/pip-build-env-m1hcjhav/overlay/lib/python3.9/site-packages/numpy/core/include -I../../scipy/_lib/boost -Iscipy/_lib -I../../scipy/_lib -I../../scipy/_build_utils/src -I/usr/include/python3.9 -fvisibility=hidden -fvisibility-inlines-hidden -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c++14 -O2 -Wno-cpp -MD -MQ scipy/special/_ufuncs_cxx.cpython-39-x86_64-cygwin.dll.p/_faddeeva.cxx.o -MF scipy/special/_ufuncs_cxx.cpython-39-x86_64-cygwin.dll.p/_faddeeva.cxx.o.d -o scipy/special/_ufuncs_cxx.cpython-39-x86_64-cygwin.dll.p/_faddeeva.cxx.o -c ../../scipy/special/_faddeeva.cxx
2023-02-11T17:48:15,193 ../../scipy/special/_faddeeva.cxx: In function ‘npy_cdouble faddeeva_ndtr(npy_cdouble)’:
2023-02-11T17:48:15,194 ../../scipy/special/_faddeeva.cxx:79:10: error: ‘M_SQRT1_2’ was not declared in this scope; did you mean ‘NPY_SQRT1_2’?
2023-02-11T17:48:15,196 79 | z *= M_SQRT1_2;
2023-02-11T17:48:15,199 | ^~~~~~~~~
2023-02-11T17:48:15,200 | NPY_SQRT1_2
2023-02-11T17:48:15,201 ../../scipy/special/_faddeeva.cxx: In function ‘double faddeeva_log_ndtr(double)’:
2023-02-11T17:48:15,202 ../../scipy/special/_faddeeva.cxx:108:18: error: ‘M_SQRT1_2’ was not declared in this scope; did you mean ‘NPY_SQRT1_2’?
2023-02-11T17:48:15,203 108 | double t = x*M_SQRT1_2;
2023-02-11T17:48:15,204 | ^~~~~~~~~
2023-02-11T17:48:15,205 | NPY_SQRT1_2
2023-02-11T17:48:15,206 ../../scipy/special/_faddeeva.cxx: In function ‘npy_cdouble faddeeva_log_ndtr_complex(npy_cdouble)’:
2023-02-11T17:48:15,207 ../../scipy/special/_faddeeva.cxx:130:53: error: ‘M_SQRT1_2’ was not declared in this scope; did you mean ‘NPY_SQRT1_2’?
2023-02-11T17:48:15,208 130 | complex<double> w = -0.5 * Faddeeva::erfc(z*M_SQRT1_2);
2023-02-11T17:48:15,209 | ^~~~~~~~~
2023-02-11T17:48:15,210 | NPY_SQRT1_2
2023-02-11T17:48:15,211 ../../scipy/special/_faddeeva.cxx:136:11: error: ‘M_SQRT1_2’ was not declared in this scope; did you mean ‘NPY_SQRT1_2’?
2023-02-11T17:48:15,212 136 | z *= -M_SQRT1_2;
2023-02-11T17:48:15,218 | ^~~~~~~~~
2023-02-11T17:48:15,219 | NPY_SQRT1_2
2023-02-11T17:48:15,220 ../../scipy/special/_faddeeva.cxx:146:34: error: ‘M_PI’ was not declared in this scope
2023-02-11T17:48:15,221 146 | double im = fmod(mIm_z2, 2.0*M_PI);
2023-02-11T17:48:15,223 | ^~~~
2023-02-11T17:48:15,224 ../../scipy/special/_faddeeva.cxx: In function ‘double faddeeva_voigt_profile(double, double, double)’:
2023-02-11T17:48:15,225 ../../scipy/special/_faddeeva.cxx:177:24: error: ‘M_PI’ was not declared in this scope
2023-02-11T17:48:15,226 177 | return gamma / M_PI / (x*x + gamma*gamma);
2023-02-11T17:48:15,227 | ^~~~
I expect to find a solution to this compilation problem! Since I cannot intervene in the code, I don't have much room for action.
My question is about linking errors I get when compiling with external libraries using mex. I'm trying to compile C++ code using the external library fftw3 using Matlab's mex on MacOS using clang++. Here is an example
main.cpp
#include "fftw3.h"
int main(){
double * test = (double *) fftw_malloc(10*sizeof(double));
}
compiling this works
$ clang++ main.cpp -L/usr/local/lib -lfftw3
Now I try something similar with mex
mex.cpp
#include "math.h"
#include "matrix.h"
#include "mex.h"
#include "fftw3.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double * test = (double *) fftw_malloc(10*sizeof(double));
}
in MATLAB
>> mex -setup C++;
>> mex -L/usr/local/lib -lfftw3 CXXFLAGS='-L/usr/local/lib -lfftw3' mex.cpp
Building with 'Xcode Clang++'.
Error using mex
clang: warning: -lfftw3: 'linker' input unused
clang: warning: argument unused during compilation: '-L/usr/local/lib'
/path/to/file/mex.cpp:4:10:
fatal error: 'fftw3.h' file not found
#include "fftw3.h"
^
1 error generated.
using the -v flag I get more detailed errors
Verbose mode is on.
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:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
... Looking for compiler 'Xcode Clang++' ...
... Looking for environment variable 'DEVELOPER_DIR' ...No.
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer' ...Yes.
... Executing command 'which xcrun' ...Yes ('/usr/bin/xcrun').
... Looking for folder '/usr/bin' ...Yes.
... Executing command 'defaults read com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...No.
... Executing command 'defaults read /Library/Preferences/com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...Yes ('7.1.1').
... Executing command '
agreed=7.1.1
if echo $agreed | grep -E '[\.\"]' >/dev/null; then
lhs=`expr "$agreed" : '\([0-9]*\)[\.].*'`
rhs=`expr "$agreed" : '[0-9]*[\.]\(.*\)$'`
if echo $rhs | grep -E '[\."]' >/dev/null; then
rhs=`expr "$rhs" : '\([0-9]*\)[\.].*'`
fi
if [ $lhs -gt 4 ] || ( [ $lhs -eq 4 ] && [ $rhs -ge 3 ] ); then
echo $agreed
else
exit 1
fi
fi' ...Yes ('7.1.1').
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk' ...Yes.
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk' ...Yes.
... Executing command 'echo /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk | rev | cut -c1-10 | rev | egrep -oh '[0-9]+\.[0-9]+'' ...Yes ('10.11').
Found installed compiler 'Xcode Clang++'.
Options file details
-------------------------------------------------------------------
Compiler location: /Applications/Xcode.app/Contents/Developer
Options file: ~/.matlab/R2014b/mex_C++_maci64.xml
CMDLINE100 : /usr/bin/xcrun -sdk macosx10.11 clang++ -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2014b.app/extern/include" -I"/Applications/MATLAB_R2014b.app/simulink/include" -L/usr/local/lib -lfftw3 -O2 -DNDEBUG /path/to/file/mex.cpp -o /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.o
CMDLINE200 : /usr/bin/xcrun -sdk macosx10.11 clang++ -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.11 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -framework Cocoa -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014b.app/extern/lib/maci64/mexFunction.map" -O -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014b.app/extern/lib/maci64/mexFunction.map" /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.o -lfftw3 -L/usr/local/lib -L"/Applications/MATLAB_R2014b.app/bin/maci64" -lmx -lmex -lmat -o mex.mexmaci64
CMDLINE300 : rm -f /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.o
CXX : /usr/bin/xcrun -sdk macosx10.11 clang++
DEFINES : -DMX_COMPAT_32 -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CXXFLAGS : -L/usr/local/lib -lfftw3
INCLUDE : -I"/Applications/MATLAB_R2014b.app/extern/include" -I"/Applications/MATLAB_R2014b.app/simulink/include"
CXXOPTIMFLAGS : -O2 -DNDEBUG
CXXDEBUGFLAGS : -g
LDXX : /usr/bin/xcrun -sdk macosx10.11 clang++
LDFLAGS : -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.11 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -framework Cocoa -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014b.app/extern/lib/maci64/mexFunction.map"
LDBUNDLE : -bundle
LINKEXPORT : -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014b.app/extern/lib/maci64/mexFunction.map"
LINKLIBS : -lfftw3 -L/usr/local/lib -L"/Applications/MATLAB_R2014b.app/bin/maci64" -lmx -lmex -lmat
LDOPTIMFLAGS : -O
LDDEBUGFLAGS : -g
OBJEXT : .o
LDEXT : .mexmaci64
DEVELOPER_DIR_CHECK :
XCODE_DIR : /Applications/Xcode.app/Contents/Developer
XCRUN_DIR : /usr/bin
XCODE_AGREED_VERSION : 7.1.1
ISYSROOT : /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
SDKVER : 10.11
MATLABROOT : /Applications/MATLAB_R2014b.app
ARCH : maci64
SRC : /path/to/file/mex.cpp
OBJ : /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.o
OBJS : /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.o
SRCROOT : /path/to/file/mex
DEF : /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.def
EXP : mex.exp
LIB : mex.lib
EXE : mex.mexmaci64
ILK : mex.ilk
MANIFEST : mex.mexmaci64.manifest
TEMPNAME : mex
EXEDIR :
EXENAME : mex
OPTIM : -O2 -DNDEBUG
LINKOPTIM : -O
-------------------------------------------------------------------
Building with 'Xcode Clang++'.
/usr/bin/xcrun -sdk macosx10.11 clang++ -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2014b.app/extern/include" -I"/Applications/MATLAB_R2014b.app/simulink/include" -L/usr/local/lib -lfftw3 -O2 -DNDEBUG /path/to/file/mex.cpp -o /var/folders/09/dysbhb1d5zn98sq8lzkwpn5r0000gn/T//mex_291104578803706_45753/mex.o
Error using mex
clang: warning: -lfftw3: 'linker' input unused
clang: warning: argument unused during compilation: '-L/usr/local/lib'
/path/to/file/mex.cpp:4:10:
fatal error: 'fftw3.h' file not found
#include "fftw3.h"
^
1 error generated.
The warnings
clang: warning: -lfftw3: 'linker' input unused
clang: warning: argument unused during compilation: '-L/usr/local/lib'
are there because you are setting CXXFLAGS to contain these flags. This variable is for compiler flags, but -L and -l are linker flags. Simply remove the CXXFLAGS definition from your mex command.
The error
/path/to/file/mex.cpp:4:10:
fatal error: 'fftw3.h' file not found
#include "fftw3.h"
^
1 error generated.
is because the compiler cannot find the fftw4.h header file. You need to tell the compiler where to find it:
mex -I/usr/local/include -L/usr/local/lib -lfftw3 mex.cpp
Note that in your first case, where you call clang++ directly, it is likely that CLang is configured to look for header files in /usr/local/include, it's a standard place. But when mex invokes your compiler (I don't even know if it's the same one?) apparently this location is not added to the search path.
Summary
I am trying to write some MEX files that use LAPACK, and I thought I'd start by looking through the examples provided by MathWorks.
However, I am having some trouble compiling them. After copying the matrixDivide.c example from [MATLAB root]/extern/examples/refbook into a working directory, I tried to build a mex file, but it failed with error undefined reference to `dgesv_' (where dgesv is the name of the LAPACK routine being called).
I was able to build a different mex example (timestwo.c) that doesn't use LAPACK.
So what's going on? What's the deal with the trailing underscore? What about this memcpy warning?
More info
I think this is fairly similar to the issues encountered by this user:
How can I use CLAPACK,BLAS or LAPACK in a mex file?
I've tried this with MATLAB R2013b and R2014b. I am running on 64-bit Linux (RHEL 6) and my compiler is gcc 4.4.7 (which is not the MathWorks recommended version, but is the newest version I can get).
Here are the relevant portions of the code I'm trying to compile:
1 /*=========================================================
2 * matrixDivide.c - Example for illustrating how to use
3 * LAPACK within a C MEX-file.
4 *
5 * X = matrixDivide(A,B) computes the solution to a
6 * system of linear equations A * X = B
7 * using LAPACK routine DGESV, where
8 * A is an N-by-N matrix
9 * X and B are N-by-1 matrices.
10 *
11 * This is a MEX-file for MATLAB.
12 * Copyright 2009-2010 The MathWorks, Inc.
13 *=======================================================*/
14 /* $Revision: 1.1.6.3 $ $Date: 2011/01/28 18:11:56 $ */
15
16 #if !defined(_WIN32)
17 #define dgesv dgesv_
18 #endif
19
20 #include "mex.h"
21 #include "lapack.h"
22
23 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
24 {
[ snip ]
73 /* Call LAPACK */
74 dgesv(&m,&n,A2,&m,iPivot,B2,&p,&info);
75 /* plhs[0] now holds X */
76
77 mxDestroyArray(Awork);
78 mxDestroyArray(mxPivot);
79 }
Here is the output of the failed mex build:
>> mex -v -largeArrayDims matrixDivide.c
-> mexopts.sh sourced from directory (DIR = $MATLAB/bin)
FILE = /sw/matlab/R2013b/bin/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /sw/matlab/R2013b
-> 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,/sw/matlab/R2013b/bin/glnxa64 -L/sw/matlab/R2013b/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,/sw/matlab/R2013b/bin/glnxa64 -L/sw/matlab/R2013b/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,/sw/matlab/R2013b/bin/glnxa64 -L/sw/matlab/R2013b/bin/glnxa64 -lmx -lmex -lmat -lm
arguments =
-> LD = gcc
-> Link flags:
LDFLAGS = -pthread -shared -Wl,--version-script,/sw/matlab/R2013b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexa64
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------
-> gcc -c -I/sw/matlab/R2013b/extern/include -I/sw/matlab/R2013b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread -O -DNDEBUG "matrixDivide.c"
In file included from matrixDivide.c:21:
/sw/matlab/R2013b/extern/include/lapack.h:6907:1: warning: "dgesv" redefined
matrixDivide.c:17:1: warning: this is the location of the previous definition
matrixDivide.c: In function `mexFunction':
matrixDivide.c:64: warning: incompatible implicit declaration of built-in function ?memcpy?
-> gcc -O -pthread -shared -Wl,--version-script,/sw/matlab/R2013b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -o "matrixDivide.mexa64" matrixDivide.o -Wl,-rpath-link,/sw/matlab/R2013b/bin/glnxa64 -L/sw/matlab/R2013b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
matrixDivide.o: In function `mexFunction':
matrixDivide.c:(.text+0x1c6): undefined reference to `dgesv_'
collect2: ld returned 1 exit status
mex: link of ' "matrixDivide.mexa64"' failed.
After some more messing around, I figured out my (rather elementary) mistake.
You need to specify the -lmwlapack option (and/or -lmwblas, as appropriate) to the linker:
mex -largeArrayDims -lmwlapack matrixDivide.c
It even says so on the MathWorks page I was trying to follow along on. RTFM!
i tried to build the mod_tile as in the link
then i was getting the same error
and tried came got the fix from this forum
i exported these
export CXXFLAGS="$(mapnik-config --cflags)"
export LDFLAGS="$(mapnik-config --ldflags)"
adding #include at the top of src/gen_tile.cpp
and changed the Makefile with --std=gnu++11
and i'm new to the linux and the cpp
Making all in iniparser3.0b
make[1]: Entering directory `/root/src/mod_tile/iniparser3.0b'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/root/src/mod_tile/iniparser3.0b'
make[1]: Entering directory `/root/src/mod_tile'
depbase=`echo src/gen_tile.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
g++ -DHAVE_CONFIG_H -I. -I./includes -I/usr/include/freetype2 -I/usr/local/include -I/usr/local/include/mapnik/agg -I/opt/PostgreSQL/9.3/include -I/usr/include -I/usr/include/freetype2 -I/usr/include/libxml2 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/libpng12 -I/usr/include -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libdrm -I/usr/include/libpng12 -DSYSTEM_LIBINIPARSER=0 -I/usr/local/include -I/usr/local/include/mapnik/agg -I/opt/PostgreSQL/9.3/include -I/usr/include -I/usr/include/freetype2 -I/usr/include/libxml2 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/libpng12 -DSHAPE_MEMORY_MAPPED_FILE -DBIGINT -DBOOST_REGEX_HAS_ICU -DHAVE_JPEG -DMAPNIK_USE_PROJ4 -DHAVE_PNG -DHAVE_TIFF -DLINUX -DMAPNIK_THREADSAFE -DBOOST_SPIRIT_NO_PREDEFINED_TERMINALS=1 -DBOOST_PHOENIX_NO_PREDEFINED_TERMINALS=1 -DBOOST_SPIRIT_USE_PHOENIX_V3=1 -DNDEBUG -DHAVE_CAIRO -DGRID_RENDERER -DHAVE_LIBXML2 -std=c++11 -Wall -Wsign-compare -pthread -ftemplate-depth-300 -Wno-pragmas -O3 -MT src/gen_tile.o -MD -MP -MF $depbase.Tpo -c -o src/gen_tile.o src/gen_tile.cpp &&\
mv -f $depbase.Tpo $depbase.Po
src/gen_tile.cpp: In function ‘void parameterize_map_max_connections(mapnik::Map&, int)’:
src/gen_tile.cpp:180:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < m.layer_count(); i++) {
^
src/gen_tile.cpp:181:22: error: ‘class mapnik::Map’ has no member named ‘getLayer’
layer& l = m.getLayer(i);
^
src/gen_tile.cpp:182:43: error: invalid use of incomplete type ‘class mapnik::datasource’
parameters params = l.datasource()->params();
^
In file included from src/gen_tile.cpp:1:0:
/usr/local/include/mapnik/layer.hpp:37:7: error: forward declaration of ‘class mapnik::datasource’
class datasource;
^
src/gen_tile.cpp:188:9: error: ‘shared_ptr’ is not a member of ‘boost’
boost::shared_ptr<datasource> ds = datasource_cache::instance().create(params);
^
src/gen_tile.cpp:188:9: note: suggested alternative:
In file included from /usr/include/c++/4.8/bits/shared_ptr.h:52:0,
from /usr/include/c++/4.8/memory:82,
from /usr/local/include/mapnik/layer.hpp:32,
from src/gen_tile.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr_base.h:261:11: note: ‘std::shared_ptr’
class shared_ptr;
^
src/gen_tile.cpp:188:37: error: expected primary-expression before ‘>’ token
boost::shared_ptr<datasource> ds = datasource_cache::instance().create(params);
^
src/gen_tile.cpp:188:39: error: ‘ds’ was not declared in this scope
boost::shared_ptr<datasource> ds = datasource_cache::instance().create(params);
^
src/gen_tile.cpp: In function ‘protoCmd render(xmlmapconfig*, int, int, int, char*, metaTile&)’:
src/gen_tile.cpp:259:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (yy = 0; yy < render_size_ty; yy++) {
^
src/gen_tile.cpp:260:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (xx = 0; xx < render_size_tx; xx++) {
^
make[1]: *** [src/gen_tile.o] Error 1
make[1]: Leaving directory `/root/src/mod_tile'
make: *** [all-recursive] Error 1
Please let me know anything i did wrong in the flow?
i am using this code
https://github.com/springmeyer/mod_tile
to build mod_tile now its working fine.
Up until recently I've been able to compile mex functions fine on my mac osx 10.8.4
but now it gives me the error as follows (for convenience I have included the entire -v invocation):
**************************************************************************
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 = .)
FILE = /Users/munanxu/Dropbox/Code/CUDA/mexThomasTDM/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /Applications/MATLAB_R2013a.app
-> CC = xcrun -sdk macosx10.7 clang
-> CC flags:
CFLAGS = -fno-common -arch x86_64 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOS
X10.7.sdk -mmacosx-version-min=10.7 -fexceptions
CDEBUGFLAGS = -g
COPTIMFLAGS = -O2 -DNDEBUG
CLIBS = -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx -lmex -lmat -
lstdc++
arguments = -DMX_COMPAT_32
-> CXX = xcrun -sdk macosx10.7 clang++
-> CXX flags:
CXXFLAGS = -fno-common -fexceptions -arch x86_64 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX
10.7.sdk -mmacosx-version-min=10.7
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O2 -DNDEBUG
CXXLIBS = -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx -lmex -lmat -
lstdc++
arguments = -DMX_COMPAT_32
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -m64 -fbackslash
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx -lmex -lmat -L
-lgfortran -L -lgfortranbegin
arguments = -DMX_COMPAT_32
-> LD = xcrun -sdk macosx10.7 clang
-> Link flags:
LDFLAGS = -arch x86_64 -Wl,-
syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/
SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7 -bundle -Wl,-
exported_symbols_list,/Applications/MATLAB_R2013a.app/extern/lib/maci64/mexFunction.map
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexmaci64
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------
-> xcrun -sdk macosx10.7 clang -g -arch x86_64 -Wl,-
syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/
SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7 -bundle -Wl,-
exported_symbols_list,/Applications/MATLAB_R2013a.app/extern/lib/maci64/mexFunction.map -o
"inputsTest.mexmaci64" "inputsTest.o" -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx
-lmex -lmat -lstdc++
Undefined symbols for architecture x86_64:
"_mexFunction", referenced from:
-exported_symbol[s_list] command line option
ld: symbol(s) not found for architecture x86_64
I had copied the original mexopts.sh file to the local directory to ensure that the mex compiler was using the correct version. I had also previously compiled my cpp file using g++ just to make sure the code was compiled natively for the x86_64 architecture. However, the same result occurs when I attempt to use the mex compiler to do compilation and linking.
Any ideas on what might be going on here? It seems that people have had this issue before, but mostly with missing libraries or definitions. I have definitely defined a mexFunction in my source file.
I think Amro is correct, I would put this as a comment, but it's a bit large, I find this for clang command line options to select target CPU
Registered Targets:
alpha - Alpha [experimental]
arm - ARM
bfin - Analog Devices Blackfin [experimental]
c - C backend ... ...
mblaze - MBlaze
mips - Mips ...
msp430 - MSP430 [experimental] ...
thumb - Thumb
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
xcore - XCoreI'm thinking Amro is correct:
So is -arch x86-64 the right command line switch, rather than x86_64