CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 4 1234 LastLast
Results 1 to 15 of 50

Thread: Problem with cmath/gsl

  1. #1
    Join Date
    Jul 2020
    Posts
    24

    Problem with cmath/gsl

    Hi,

    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

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,797

    Re: problem with cmath when compiling code

    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,267

    Re: Problem with cmath

    [new thread started]

    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!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  4. #4
    Join Date
    Jul 2020
    Posts
    24

    Re: Problem with cmath

    Hi,

    Thank you for your very quick answer.

    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.

    Best
    Arek

    https://www.dropbox.com/s/bi7h8g1brg...sktop.zip?dl=0


    >> mex -g info\binless\binlessembed.c input_c.obj input_mx.obj gen_c.obj gen_mx.obj sort_c.obj info\binless\BinlessEmbedComp.c info\binless\binless_mx.c
    >> mex -g info\binless\binlessopen.c input_c.obj input_mx.obj gen_c.obj gen_mx.obj sort_c.obj info\binless\BinlessOpenComp.c info\binless\binless_mx.c
    >> mex -g info\binless\binlesswarp.c input_c.obj input_mx.obj gen_c.obj gen_mx.obj sort_c.obj info\binless\BinlessWarpComp.c info\binless\binless_mx.c
    >> mex -g info\direct\directbin.c input_c.obj input_mx.obj gen_c.obj gen_mx.obj sort_c.obj info\direct\DirectBinComp.c info\direct\direct_mx.c
    >> mex -g info\metric\metricdist.c input_c.obj input_mx.obj gen_c.obj gen_mx.obj sort_c.obj info\metric\MetricDistAllQComp.c info\metric\MetricDistAllQKComp.c info\metric\MetricDistCommonQKComp.c info\metric\MetricDistSingleQComp.c info\metric\MetricDistSingleQKComp.c info\metric\metric_mx.c

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,267

    Re: Problem with cmath

    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!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  6. #6
    Join Date
    Jul 2020
    Posts
    24

    Re: Problem with cmath

    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
    Attached Files Attached Files

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,267

    Re: Problem with cmath

    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!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  8. #8
    Join Date
    Jul 2020
    Posts
    24

    Re: Problem with cmath

    Thank you so much. Did you try it within MSVC or Matlab environment. If within MSVC, could you pls let me know how.
    Have a nice day.

  9. #9
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,267

    Re: Problem with cmath

    Try these changes 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
    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!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  10. #10
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,267

    Re: Problem with cmath

    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!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  11. #11
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,267

    Re: Problem with cmath

    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!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  12. #12
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,267

    Re: Problem with cmath

    Alternatively, without changing toolkit_c.h, then the order of the #includes in entropy_nsb_c.cpp can be altered. Consider for entropy_nsb_c.cpp:

    Code:
    #define _CRT_SECURE_NO_WARNINGS			// ****ADDED
    
    //#include "../shared/toolkit_c.h"		// ****REMOVED
    #include <stdexcept>
    #include <sstream>
    #include <vector>
    
    #ifdef DEBUG
    #include <iostream>
    #endif
    
    #include "../shared/toolkit_c.h"		// ****ADDED
    
    #include "../gsl/gsl_math.h"
    #include "../gsl/gsl_errno.h"
    #include "../gsl/gsl_sf_gamma.h"
    #include "../gsl/gsl_sf_psi.h"
    #include "../gsl/gsl_spline.h"
    #include "../gsl/gsl_integration.h"
    with the original toolkit_c.h

    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!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  13. #13
    Join Date
    Jul 2020
    Posts
    24

    Re: Problem with cmath

    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.


    (1)
    >> mex -c input\input_c.c input\input_mx.c shared\gen_c.c shared\gen_mx.c shared\sort_c.c
    (2)
    >> mex -c entropy\entropy_bub_c.c entropy\entropy_bub_mx.c entropy\entropy_c.c entropy\entropy_chaoshen_c.c entropy\entropy_jack_c.c entropy\entropy_ma_c.c entropy\entropy_mx.c entropy\entropy_nsb_c.cpp entropy\entropy_nsb_mx.cpp entropy\entropy_plugin_c.c entropy\entropy_tpmc_c.c entropy\entropy_tpmc_mx.c entropy\entropy_ww_c.c entropy\entropy_ww_mx.c entropy\variance_boot_c.c entropy\variance_boot_mx.c entropy\variance_jack_c.c shared\hist_c.c shared\hist_mx.c


    (3)
    >> mex -g info\binless\binlessinfo.c input_c.obj input_mx.obj gen_c.obj gen_mx.obj sort_c.obj entropy_bub_c.obj entropy_bub_mx.obj entropy_c.obj entropy_chaoshen_c.obj entropy_jack_c.obj entropy_ma_c.obj entropy_mx.obj entropy_nsb_c.obj entropy_nsb_mx.obj entropy_plugin_c.obj entropy_tpmc_c.obj entropy_tpmc_mx.obj entropy_ww_c.obj entropy_ww_mx.obj variance_boot_c.obj variance_boot_mx.obj variance_jack_c.obj hist_c.obj hist_mx.obj info\binless\BinlessInfoComp.c shared\MatrixToHist2DComp.c shared\Info2DComp.c info\binless\binless_mx.c
    (4)
    >> mex -g info\ctwmcmc\ctwmcmcbridge.cpp input_c.obj input_mx.obj gen_c.obj gen_mx.obj sort_c.obj entropy_bub_c.obj entropy_bub_mx.obj entropy_c.obj entropy_chaoshen_c.obj entropy_jack_c.obj entropy_ma_c.obj entropy_mx.obj entropy_nsb_c.obj entropy_nsb_mx.obj entropy_plugin_c.obj entropy_tpmc_c.obj entropy_tpmc_mx.obj entropy_ww_c.obj entropy_ww_mx.obj variance_boot_c.obj variance_boot_mx.obj variance_jack_c.obj hist_c.obj hist_mx.obj info\ctwmcmc\CTWMCMCSampleComp.cpp info\ctwmcmc\CTWMCMCTreeComp.cpp info\ctwmcmc\ctwmcmc_c.cpp info\ctwmcmc\ctwmcmc_mx.cpp
    (5)
    >> mex -g info\ctwmcmc\ctwmcmcsample.cpp input_c.obj input_mx.obj gen_c.obj gen_mx.obj sort_c.obj entropy_bub_c.obj entropy_bub_mx.obj entropy_c.obj entropy_chaoshen_c.obj entropy_jack_c.obj entropy_ma_c.obj entropy_mx.obj entropy_nsb_c.obj entropy_nsb_mx.obj entropy_plugin_c.obj entropy_tpmc_c.obj entropy_tpmc_mx.obj entropy_ww_c.obj entropy_ww_mx.obj variance_boot_c.obj variance_boot_mx.obj variance_jack_c.obj hist_c.obj hist_mx.obj info\ctwmcmc\CTWMCMCSampleComp.cpp info\ctwmcmc\ctwmcmc_c.cpp info\ctwmcmc\ctwmcmc_mx.cpp
    (6)
    >> mex -g info\ctwmcmc\ctwmcmctree.cpp input_c.obj input_mx.obj gen_c.obj gen_mx.obj sort_c.obj info\ctwmcmc\CTWMCMCTreeComp.cpp info\ctwmcmc\ctwmcmc_c.cpp info\ctwmcmc\ctwmcmc_mx.cpp



    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

  14. #14
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,267

    Re: Problem with cmath

    The latest gsl can be downloaded from http://mirror.koddos.net/gnu/gsl/ as a .tar.gz file [mods please leave the link]

    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!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  15. #15
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,267

    Re: Problem with cmath

    This link https://solarianprogrammer.com/2020/...s-macos-linux/

    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!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

Page 1 of 4 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)