I have problem with compiling cpp code written in 2010 using MSVC 2019 compiler in matlab as follows (I would like later debug the code in MSVC through attaching it to Matlab process)
>> mex -g entropy\entropy_nsb_c.cpp
It generates errors which are connected in some way with cmath file native to MSVC 2019. I can not find where and why this file is called and makes errors.
The errors look like below. I attached 2 files which are used in this compilation.
>> mex -g entropy\entropy_nsb_c.cpp
Building with 'Microsoft Visual C++ 2019'.
Error using mex
entropy_nsb_c.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(178): error C2062: type 'long' unexpected
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(178): error C2143: syntax error: missing ';' before '{'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(178): error C2447: '{': missing function header (old-style formal
list?)
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(222): error C2143: syntax error: missing ',' before '+'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(222): error C2084: function 'float floor(float) noexcept' already
has a body
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(106): note: see previous definition of 'floor'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(418): error C2062: type 'long' unexpected
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(418): error C2143: syntax error: missing ';' before '{'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(418): error C2447: '{': missing function header (old-style formal
list?)
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(466): error C2143: syntax error: missing ',' before '+'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(466): error C2084: function 'long double floor(long double)
noexcept' already has a body
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(341): note: see previous definition of 'floor'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(658): error C2988: unrecognizable template declaration/definition
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(658): error C2143: syntax error: missing ',' before '+'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(658): error C2995: 'double floor(_Ty) noexcept': function template
has already been defined
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(653): note: see declaration of 'floor'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(658): warning C4348: 'floor': redefinition of default parameter:
parameter 2
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(653): note: see declaration of 'floor'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(659): error C2062: type 'long' unexpected
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(659): error C2143: syntax error: missing ';' before '{'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath(659): error C2447: '{': missing function header (old-style formal
list?)
G:\DATA_WS\Fabian\STAToolkit\spike\entropy\entropy_nsb_c.cpp(1266): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
G:\DATA_WS\Fabian\STAToolkit\spike\entropy\entropy_nsb_c.cpp(1276): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
G:\DATA_WS\Fabian\STAToolkit\spike\entropy\entropy_nsb_c.cpp(1286): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
>> entropy_nsb_c.cpptoolkit_c.h
From where is cmath being included? toolkit_c.h includes math.h which doesn't use the cmath header and entropy_nsb_c.cpp has #include "../gsl/gsl_math.h"
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
Yes, I also could not find at which point that file ‘cmath’ was involved into the compilation (there is no file extension to ‘cmath’, file attached). Its path on HDD is:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\include\cmath
I just use simple command in Matlab to create mex file:
>> mex -g entropy\entropy_nsb_c.cpp
The following functions called from ‘entropy_nsb_c.cpp’ also do not call ‘cmath’
GSL function ‘gsl_math.h’
toolkit_c.h
input_c.h
entropy_c.h
all above files are included in the attached pack ‘wholeToolboxSTAToolkit.zip’ containing all toolbox files (see dropbox link).
I attached compressed file ‘STAToolkit_docs.zip’ (see dropbox link) (open install.html) with the information how that file (and many other) were compiled over 10years ago. It looks that that the new compiler I am using (MSVC 2019) includes into compilation its own file ‘cmath’ as replacement for something when .cpp file is compiled, I suppose. I compiled successfully many other files (with extension .c) from that toolbox, except that one (with extension .cpp). Maybe the extension makes the compiler to use other compiling methods specific to c++. The successfully compiled .c files to .mexw64 files by me with MSVC 2019 are in directory \STAToolkit\spike\ (see the example compilation lines at the end).
When I changed the extension from .cpp to .c to see the compilation results then of course plenty of syntax error appeared.
>> mex -g entropy\entropy_nsb_c.c
I attached complete STAToolkit toolbox (see dropbox link, wholeToolboxSTAToolkit.zip). I would be very grateful if you would you find a while to try to compile/link to .mexw64 that ‘\entropy\entropy_nsb_c.cpp’ file at your side.
I am not expert in C compilers field and not sure how to sort that issue out.
Please attach the .zip file to a post - rather than using dropbox (.zip files can't be previewed from an archive file). If you include all the files required to compile in the .zip file (including the gsl .h etc), I'll have a look for MS VS2019.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
Pls unpack all zip files into directory \spike\.
The file of interest is in directory \spike\entropy\entropy_nsb_c.cpp
I attached the whole toolbox just in case, plus documentation.
Thank you
Best
Arek
Ok. With MS VS2019 for the file entropy_nsb_c.cpp, I'm getting the same error with cmath as you are. I'll investigate.
Last edited by 2kaud; July 21st, 2020 at 02:27 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
/*
* Copyright 2010, Weill Medical College of Cornell University
* All rights reserved.
*
* This software is distributed WITHOUT ANY WARRANTY
* under license "license.txt" included with distribution and
* at http://neurodatabase.org/src/license.
*/
/* Make header C++ compatible */
#ifdef __cplusplus
#include <cmath> // ****ADDED
extern "C" {
#endif
/* Some useful constants */
#define MAXCHARS 256
#define MAXPATH 260
#define BITS_IN_A_BYTE 8
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#ifndef __cplusplus // **** ADDED
#include <math.h> // **** ADDED
#endif // **** ADDED
#include <limits.h>
#include "../input/input_c.h"
#include "../entropy/entropy_c.h"
#include "hist_c.h"
#include "gen_c.h"
#include "sort_c.h"
#ifdef TOOLKIT
#include "mex.h"
#endif
/* Some useful macros */
#define NAT2BIT(x) x/log(2.0)
#define LOGZ(x) (x <= 0 ? 0 : log(x))
#define LOG2Z(x) NAT2BIT(LOGZ(x))
#define XLOGX(x) (-x*LOGZ(x))
#define XLOG2X(x) (-x*LOG2Z(x))
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
#define MIN3(a,b,c) MIN(MIN(a,b),c)
/* Define round and lround for compilers lacking these math.h functions (e.g., Microsoft Visual C++).
* See http://www.velocityreviews.com/forums/t532986-rounding-functions-in-microsoft-visual-cc.html.
*/
#ifndef round
#define round(x) floor(x + 0.5)
#define lround(x) (long)floor(x + 0.5)
#endif
/* Define INFINITY/NAN for compilers lacking symbol (e.g., Microsoft Visual C++).
* See http://www.gamedev.net/community/forums/topic.asp?topic_id=465682.
*/
#ifndef INFINITY
union MSVC_EVIL_FLOAT_HACK
{
unsigned char Bytes[4];
float Value;
};
static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
static union MSVC_EVIL_FLOAT_HACK NAN_HACK = {{0x00, 0x00, 0xC0, 0x7F}};
#define INFINITY (INFINITY_HACK.Value)
#define NAN (NAN_HACK.Value)
#endif
/* Make header C++ compatible */
#ifdef __cplusplus
}
#endif
The problem is with #include <math.h> within the extern "C" block having already included cmath. If you use cmath and exclude math.h if compiling for C++, there are no compiler errors relating to cmath when compiling entropy_nsb_c.cpp
Last edited by 2kaud; July 21st, 2020 at 02:04 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
For info, for C++ cmath is indirectly included by stdexcept, vector, iostream & stream
Is this header file also used for .c programs as well as .cpp programs? For .cpp programs, the C++ includes are recommended ie
cstdlib instead of stdlib.h, cstdio instead of stdio.h etc. Usually the C++ include file is the C one with the .h removed and an initial c added.
Last edited by 2kaud; July 21st, 2020 at 02:07 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
For possibly a better way consider for toolkit_c.h:
Code:
/*
* Copyright 2010, Weill Medical College of Cornell University
* All rights reserved.
*
* This software is distributed WITHOUT ANY WARRANTY
* under license "license.txt" included with distribution and
* at http://neurodatabase.org/src/license.
*/
/* Make header C++ compatible */
#ifdef __cplusplus
#include <cmath> // ****ADDED
#include <cstdlib> // ****ADDED
#include <cstdio> // ****ADDED
#include <cctype> // ****ADDED
#include <cstring> // ****ADDED
#include <climits> // ****ADDED
extern "C" {
#endif
/* Some useful constants */
#define MAXCHARS 256
#define MAXPATH 260
#define BITS_IN_A_BYTE 8
#ifndef __cplusplus // **** ADDED
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#endif // **** ADDED
#include "../input/input_c.h"
#include "../entropy/entropy_c.h"
#include "hist_c.h"
#include "gen_c.h"
#include "sort_c.h"
#ifdef TOOLKIT
#include "mex.h"
#endif
/* Some useful macros */
#define NAT2BIT(x) x/log(2.0)
#define LOGZ(x) (x <= 0 ? 0 : log(x))
#define LOG2Z(x) NAT2BIT(LOGZ(x))
#define XLOGX(x) (-x*LOGZ(x))
#define XLOG2X(x) (-x*LOG2Z(x))
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
#define MIN3(a,b,c) MIN(MIN(a,b),c)
/* Define round and lround for compilers lacking these math.h functions (e.g., Microsoft Visual C++).
* See http://www.velocityreviews.com/forums/t532986-rounding-functions-in-microsoft-visual-cc.html.
*/
#ifndef round
#define round(x) floor(x + 0.5)
#define lround(x) (long)floor(x + 0.5)
#endif
/* Define INFINITY/NAN for compilers lacking symbol (e.g., Microsoft Visual C++).
* See http://www.gamedev.net/community/forums/topic.asp?topic_id=465682.
*/
#ifndef INFINITY
union MSVC_EVIL_FLOAT_HACK
{
unsigned char Bytes[4];
float Value;
};
static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
static union MSVC_EVIL_FLOAT_HACK NAN_HACK = {{0x00, 0x00, 0xC0, 0x7F}};
#define INFINITY (INFINITY_HACK.Value)
#define NAN (NAN_HACK.Value)
#endif
/* Make header C++ compatible */
#ifdef __cplusplus
}
#endif
Which uses the C++ version of the includes when compiling as C++ and the c version of the includes when compiling as c.
Last edited by 2kaud; July 21st, 2020 at 02:24 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
This makes sure that cmath is included first before math.h which seems OK. The problem arises when math.h is included before cmath.
Although it is better to use the C++ includes if compiling as C++.
Last edited by 2kaud; July 21st, 2020 at 02:28 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
Thank you so much for your help. It works with the update to ‘entropy_nsb_c.cpp’. It also works with modifications to both files altogether. I really appreciate your free and immediate help, but can I ask you for further help if it is not overusing your patience, this time with the linker. If yes, could I ask you to try below commands (3)-(6). I tried to sort it out, but again not sure how to do it. It looks that the files ‘entropy_bub_c.obj’ and ‘entropy_nsb_c.obj’ have missing definitions of some functions from GSL library. My GSL directory does not contain theses files. Maybe I should use another more complete GSL library and add in compiled .c files lines like below for all missing definitions:
#include "../../gsl/gsl_vector_calloc.h" (see errors at the end)(gsl_vector_calloc.h is not included in my GSL directory)
If yes, do you know source of the most complete GSL library?
Before running the (3)-(6) command we need to run commands (1)-(2) to generate the ‘entropy_bub_c.obj’ and ‘entropy_nsb_c.obj’ files with missing definitions.
It is example error from the command (3), next commands generate similar errors. Command (6) generates problem with ‘CTWMCMCTreeComp.obj’ file and missing ‘gsl_sf_lngamma.h’ function.
Error using mex
Creating library binlessinfo.lib and object binlessinfo.exp
entropy_bub_c.obj : error LNK2019: unresolved external symbol gsl_vector_calloc referenced in function bag1
entropy_bub_c.obj : error LNK2019: unresolved external symbol gsl_vector_free referenced in function bag1
entropy_bub_c.obj : error LNK2019: unresolved external symbol gsl_matrix_calloc referenced in function bag1
entropy_bub_c.obj : error LNK2019: unresolved external symbol gsl_matrix_free referenced in function bag1
entropy_bub_c.obj : error LNK2019: unresolved external symbol gsl_linalg_SV_decomp referenced in function bag1
entropy_bub_c.obj : error LNK2019: unresolved external symbol gsl_linalg_SV_solve referenced in function bag1
entropy_bub_c.obj : error LNK2019: unresolved external symbol gsl_sf_lngamma referenced in function make_binom
entropy_nsb_c.obj : error LNK2001: unresolved external symbol gsl_sf_lngamma
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_isinf referenced in function "public: __cdecl nsb_entropy::Interpolation::Interpolation(double const
&,double)" (??0Interpolation@nsb_entropy@@QEAA@AEBNN@Z)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_pow_2 referenced in function "private: enum nsb_entropy::NSB_WARN const __cdecl
nsb_entropy::Computation::calculate(void)" (?calculate@Computation@nsb_entropy@@AEAA?BW4NSB_WARN@2@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_pow_3 referenced in function "private: enum nsb_entropy::NSB_WARN const __cdecl
nsb_entropy::Computation::max_evidence(void)" (?max_evidence@Computation@nsb_entropy@@AEAA?BW4NSB_WARN@2@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_pow_4 referenced in function "private: enum nsb_entropy::NSB_WARN const __cdecl
nsb_entropy::Computation::max_evidence(void)" (?max_evidence@Computation@nsb_entropy@@AEAA?BW4NSB_WARN@2@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_pow_5 referenced in function "private: enum nsb_entropy::NSB_WARN const __cdecl
nsb_entropy::Computation::max_evidence(void)" (?max_evidence@Computation@nsb_entropy@@AEAA?BW4NSB_WARN@2@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_pow_6 referenced in function "private: enum nsb_entropy::NSB_WARN const __cdecl
nsb_entropy::Computation::max_evidence(void)" (?max_evidence@Computation@nsb_entropy@@AEAA?BW4NSB_WARN@2@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_pow_7 referenced in function "private: enum nsb_entropy::NSB_WARN const __cdecl
nsb_entropy::Computation::max_evidence(void)" (?max_evidence@Computation@nsb_entropy@@AEAA?BW4NSB_WARN@2@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_pow_8 referenced in function "private: enum nsb_entropy::NSB_WARN const __cdecl
nsb_entropy::Computation::max_evidence(void)" (?max_evidence@Computation@nsb_entropy@@AEAA?BW4NSB_WARN@2@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_pow_9 referenced in function "private: enum nsb_entropy::NSB_WARN const __cdecl
nsb_entropy::Computation::max_evidence(void)" (?max_evidence@Computation@nsb_entropy@@AEAA?BW4NSB_WARN@2@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_pow_int referenced in function "private: enum nsb_entropy::NSB_WARN const __cdecl
nsb_entropy::Computation::max_evidence(void)" (?max_evidence@Computation@nsb_entropy@@AEAA?BW4NSB_WARN@2@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_set_error_handler referenced in function "public: __cdecl nsb_entropy::Computation::Computation(double
const *,double const *,int,int,double,double,int)" (??0Computation@nsb_entropy@@QEAA@PEBN0HHNNH@Z)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_set_error_handler_off referenced in function "public: __cdecl
nsb_entropy::Computation::Computation(double const *,double const *,int,int,double,double,int)" (??0Computation@nsb_entropy@@QEAA@PEBN0HHNNH@Z)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_sf_psi referenced in function "public: __cdecl nsb_entropy::Interpolation::Interpolation(double const
&,double)" (??0Interpolation@nsb_entropy@@QEAA@AEBNN@Z)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_sf_psi_1 referenced in function "public: __cdecl nsb_entropy::Interpolation::Interpolation(double const
&,double)" (??0Interpolation@nsb_entropy@@QEAA@AEBNN@Z)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_sf_psi_n referenced in function "private: enum nsb_entropy::NSB_WARN const __cdecl
nsb_entropy::Computation::max_evidence(void)" (?max_evidence@Computation@nsb_entropy@@AEAA?BW4NSB_WARN@2@XZ)
entropy_ww_c.obj : error LNK2001: unresolved external symbol gsl_sf_psi_n
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_interp_accel_alloc referenced in function "public: __cdecl nsb_entropy::Spline::Spline(double const
*,double const *,int,struct gsl_interp_type const *)" (??0Spline@nsb_entropy@@QEAA@PEBN0HPEBUgsl_interp_type@@@Z)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_interp_accel_free referenced in function "public: __cdecl nsb_entropy::Computation::~Computation(void)"
(??1Computation@nsb_entropy@@QEAA@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_spline_alloc referenced in function "public: __cdecl nsb_entropy::Spline::Spline(double const *,double
const *,int,struct gsl_interp_type const *)" (??0Spline@nsb_entropy@@QEAA@PEBN0HPEBUgsl_interp_type@@@Z)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_spline_init referenced in function "public: __cdecl nsb_entropy::Spline::Spline(double const *,double
const *,int,struct gsl_interp_type const *)" (??0Spline@nsb_entropy@@QEAA@PEBN0HPEBUgsl_interp_type@@@Z)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_spline_eval referenced in function "private: enum nsb_entropy::NSB_WARN const __cdecl
nsb_entropy::Computation::calculate(void)" (?calculate@Computation@nsb_entropy@@AEAA?BW4NSB_WARN@2@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_spline_free referenced in function "public: __cdecl nsb_entropy::Computation::~Computation(void)"
(??1Computation@nsb_entropy@@QEAA@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_integration_workspace_alloc referenced in function "public: __cdecl
nsb_entropy::Workspace::Workspace(int)" (??0Workspace@nsb_entropy@@QEAA@H@Z)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_integration_workspace_free referenced in function "public: __cdecl
nsb_entropy::Workspace::~Workspace(void)" (??1Workspace@nsb_entropy@@QEAA@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol gsl_integration_qag referenced in function "private: enum nsb_entropy::NSB_WARN const __cdecl
nsb_entropy::Computation::calculate(void)" (?calculate@Computation@nsb_entropy@@AEAA?BW4NSB_WARN@2@XZ)
entropy_nsb_c.obj : error LNK2019: unresolved external symbol __imp_gsl_interp_linear referenced in function "public: __cdecl
nsb_entropy::Interpolation::Interpolation(double const &,double)" (??0Interpolation@nsb_entropy@@QEAA@AEBNN@Z)
binlessinfo.mexw64 : fatal error LNK1120: 32 unresolved externals
Your gsl file only has the .h files and not the .c files. Have you created/got a .dll for gsl? If so then you need to link to the appropriate gsl .lib file. If you don't know, find .lib files and see by the name which could be a likely one.
For the first link error:
gsl_vector_calloc is declared in gsl_vector_double.h (included from gsl_vector.h) and its source is in vector\init_source.c. So you need to make sure that vector\init_source.c is part of the compile. Note that there are various files called init_source.c in different directories.
For each of the linker unresolved symbol errors you need to search the gsl files for the appropriate source file (.c) containing the definition and make sure it's included as part of the compile. Note that the definition may not be the same as the declaration. eg the declaration of gsl_vector_calloc is:
gsl_vector *gsl_vector_calloc (const size_t n);
but the definition is:
TYPE (gsl_vector) *
FUNCTION (gsl_vector, calloc) (const size_t n)
{....}
which uses macros.
Also note that gsl is intended to be used/installed from within a linux-like environment (such as cygwin under Windows). How easy it is to use properly from within MS VS I don't know (and don't have the time to investigate further). You might have some investigating to do and changes to be made to get everything compiled properly (such as the ones relating to match.h/cmath etc). The provided make files are for a linux shell (such as cygwin under Windows).
Last edited by 2kaud; July 22nd, 2020 at 04:43 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
describes how to install gsl for Visual Studio 2019
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.