none
error C3861: 'cos': identifier not found

    Question

  • Hi !

    I am getting similar errors while compinlingy my program. The library fheader file #include<math.h>  is included .
    Am I missing something?

    Thanks!

    8>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1590) : error C3861: 'Cos': identifier not found
    8>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1591) : error C3861: 'sin': identifier not found
    8>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1603) : error C3861: 'floor': identifier not found
    8>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1603) : error C3861: 'min4': identifier not found
    8>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1604) : error C3861: 'floor': identifier not found
    8>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1604) : error C3861: 'min4': identifier not found
    8>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1606) : error C3861: 'ceil': identifier not found
    8>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1606) : error C3861: 'max4': identifier not found
    8>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1607) : error C3861: 'ceil': identifier not found
    8>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1607) : error C3861: 'max4': identifier not found
    • Edited by yade Tuesday, August 25, 2009 11:11 AM
    Monday, August 24, 2009 1:38 PM

Answers

  • Well this is a different error now. Dialogs do not have an OnDraw method, views have OnDraw.

    Also in your code above OnDraw is a global function and you are calling a class method from it (which won't compile obviously).


    http://blog.voidnish.com
    • Marked as answer by Wesley Yao Monday, August 31, 2009 3:23 AM
    Monday, August 24, 2009 2:49 PM
    Moderator
  • Check the math.h file in Visual Studio. It must declare the cos function. Temporary change the filename to something else and rebuild your project. Since there is an #include <math.h> line in your sources, you should obtain “Cannot open include file” error, meaning that the right file is included.

    • Marked as answer by Wesley Yao Monday, August 31, 2009 3:24 AM
    Tuesday, August 25, 2009 2:00 PM
  • I believe that the right one is in ‘VC\include’ subfolder of Visual Studio. The configurated paths specified in Tools à Project and Solutions à VC++ Directories, Show directories for: Include files, which usually should never be touched, must point to this folder. Your project can also include an Additional Include Directories project property. Try to figure out if the right math.h file is included.

     

    If 'c:\users\eyasdel\math.h' is one of your files, then try renaming it to avoid name collisions.

     

    • Marked as answer by Wesley Yao Monday, August 31, 2009 3:23 AM
    Tuesday, August 25, 2009 2:35 PM
  • You can also right-click on the #include <math.h> line and select open-file. Then look at the path to see if you are opening the actual header file or a custom file that you or a colleague wrote.
    http://blog.voidnish.com
    • Marked as answer by Wesley Yao Monday, August 31, 2009 3:24 AM
    Wednesday, August 26, 2009 11:43 AM
    Moderator

All replies

  • It's cos (not Cos).
    http://blog.voidnish.com
    Monday, August 24, 2009 1:50 PM
    Moderator
  • Aaah I changed it to see if it is case senstive or not. I get the same result with 'cos'.

    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1591) : error C3861: 'cos': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1592) : error C3861: 'sin': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1604) : error C3861: 'floor': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1604) : error C3861: 'min4': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1605) : error C3861: 'floor': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1605) : error C3861: 'min4': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1607) : error C3861: 'ceil': identifier not found
    Best,
    Yashar
    Monday, August 24, 2009 1:52 PM
  • 1. Are you sure <math.h> is included for this specific cpp file (directly or indirectly)

    2. Can you show how you are using the code? Perhaps you are using the C++ version (#include <math>, using namespace std;)
    http://blog.voidnish.com
    Monday, August 24, 2009 1:57 PM
    Moderator
  • Nishant I am using c++ code and #include <math.h> is included on top of my file.

    Here is the part of my code where the error is generated !

    Thanks for your feedback in advance.


    void RotateMemoryDC(HBITMAP hBmpSrc, HDC hdcSrc, int SrcX, int SrcY, float angle,HDC &hdcDst, int &dstX, int &dstY)
    {
    	
    
    	// Rotate the bitmap around the center
    	CtX = ((float) SrcX) / 2;
    	CtY = ((float) SrcY) / 2;
    // First, calculate the destination positions for the four courners to get dstX and dstY
        
    	cA = (float) cos(angle);   / C3681
    	sA = (float) sin(angle);   /  C3681
    
    ... 
    ...
    }

    Monday, August 24, 2009 2:02 PM
  • Can you also copy/paste your #include-s (in actual order) ?
    http://blog.voidnish.com
    Monday, August 24, 2009 2:07 PM
    Moderator
  • Yeah sure :


    #include "stdafx.h"
    #include "3DAudioDemo.h"
    #include "3DAudioDemoDlg.h"
    #include "RenderingThread.h"
    #include "WiiRemoteThread.h"
    #include "WiiInterface.h"
    #include "SourcePropertiesEditor.h"
    #include "ddeml.h"
    #include "dde_callback.h"
    #include "sfx_reverb_fdn.h"
    #include "sfx_early_reverb.h"
    #include <math.h>
    
    Monday, August 24, 2009 2:13 PM
  • Ok, and the function RotateMemoryDC - is it declared inline in 3DAudioDemoDlg.h?
    http://blog.voidnish.com
    Monday, August 24, 2009 2:15 PM
    Moderator
  • Here is 3DAudioDemoDlg.h

    This error is include though :

     error C3861: 'RotateMemoryDC': identifier not found

    class CMy3DAudioDemoDlg : public CDialog
    {
    // Construction
    public:
    
    void RotateMemoryDC(HBITMAP hBmpSrc, HDC hdcSrc, int SrcX, int SrcY, float angle,HDC &hdcDst, int &dstX, int &dstY);
    
    }
    
    ...
    function ImplemEntaion
    
    void CMy3DAudioDemoDlg::RotateMemoryDC(HBITMAP hBmpSrc, HDC hdcSrc, int SrcX, int SrcY, float angle,HDC &hdcDst, int &dstX, int &dstY)
    • Edited by yade Monday, August 24, 2009 2:34 PM
    Monday, August 24, 2009 2:27 PM
  • Ok, that rules that out then. Just to be 100% clear on this :

    CMy3DAudioDemoDlg  is declared in 3DAudioDemoDlg.h and implemented in 3DAudioDemoDlg.cpp. Right?

    And the #includes you pasted above are on the top of 3DAudioDemoDlg.cpp.


    http://blog.voidnish.com
    Monday, August 24, 2009 2:36 PM
    Moderator
  • yeah !

    CMy3DAudioDemoDlg  is declared in 3DAudioDemoDlg.h and implemented in 3DAudioDemoDlg.cpp.   Yes exactly .

    Here is where i get the error in

    3dAudioDemoDlg.cpp

    void CMy3DAudioDemoDlg::DrawListener2()
    {

    InvalidateRect(hWnd,NULL,TRUE);


    };

    // Handler for drawing
    void OnDraw(HWND hWnd)
    {
    ........

    hdc = BeginPaint(hWnd, &ps);
    GetClientRect(hWnd, &rt);

    HANDLE hBmp=LoadImage(NULL,"HeadFront.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    HBITMAP hbBmp=(HBITMAP)hBmp;


    RotateMemoryDC(hbBmp, hdcNew, 48, 36, g_angle,hdcMem, dstX, dstY);

    /// here i get error C3861: 'RotateMemoryDC': identifier not found


    };

    void CMy3DAudioDemoDlg::RotateMemoryDC(HBITMAP hBmpSrc, HDC hdcSrc, int SrcX, int SrcY, float angle,HDC &hdcDst, int &dstX, int &dstY)
    {
    HBITMAP hBmpDst;


    // Rotate the bitmap around the center
    CtX = ((float) SrcX) / 2;
    CtY = ((float) SrcY) / 2;

    // First, calculate the destination positions for the four courners to get dstX and dstY

    cA = (float) cos(angle); / C3861 ERROR
    sA = (float) sin(angle); / C3861 ERROR

    x1 = CtX + (-CtX) * cA - (-CtY) * sA ;
    x2 = CtX + (SrcX - CtX) * cA - (-CtY) * sA ;
    x3 = CtX + (SrcX - CtX) * cA - (SrcY - CtY) * sA;
    x4 = CtX + (-CtX) * cA - (SrcY - CtY) * sA ;

    y1 = CtY + (-CtY) * cA + (-CtX) * sA ;
    y2 = CtY + (SrcY - CtY) * cA + (-CtX) * sA ;
    y3 = CtY + (SrcY - CtY) * cA + (SrcX - CtX) * sA ;
    y4 = CtY + (-CtY) * cA + (SrcX - CtX) * sA ;


    }
    Thanks
    • Edited by yade Monday, August 24, 2009 2:46 PM
    Monday, August 24, 2009 2:44 PM
  • Well this is a different error now. Dialogs do not have an OnDraw method, views have OnDraw.

    Also in your code above OnDraw is a global function and you are calling a class method from it (which won't compile obviously).


    http://blog.voidnish.com
    • Marked as answer by Wesley Yao Monday, August 31, 2009 3:23 AM
    Monday, August 24, 2009 2:49 PM
    Moderator
  • Also, for a CDialog derived class, you are expected to override OnPaint (there is no virtual OnDraw for a dialog).
    http://blog.voidnish.com
    Monday, August 24, 2009 2:51 PM
    Moderator
  • I'm going to guess there's a problem in your header file.  Missing } or unclosed namespace, something like that.  Move #include <math.h> up, right after #include "stdafx.h".  If my theory is correct, the errors on the math functions will disappear.
    Hans Passant.
    Monday, August 24, 2009 2:53 PM
    Moderator
  • Thanks Nishant ! Interesting

    I solved that error this way . What about our primary problem with math functions? It still exists.


    void CMy3DAudioDemoDlg::DrawListener2()
    {
    
    	hBmp=LoadImage(NULL,"HeadFront.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);      
        HBITMAP hbBmp=(HBITMAP)hBmp;
    
    
    
    	RotateMemoryDC(hbBmp, hdcNew, 48, 36, g_angle,hdcMem, dstX, dstY);
    
    
    };
    
    
    void CMy3DAudioDemoDlg::RotateMemoryDC(HBITMAP hBmpSrc, HDC hdcSrc, int SrcX, int SrcY, float angle,HDC &hdcDst, int &dstX, int &dstY)
    {
        
    	cA = (float) cos(angle);
    	sA = (float) sin(angle);
    
    	
    	
    }
    


    Monday, August 24, 2009 2:59 PM
  • If Hans' theory that some include somewhere is messed up, you can test that out by including <math.h> in your stdafx.h.
    http://blog.voidnish.com
    Monday, August 24, 2009 3:03 PM
    Moderator
  • It's very strange that none of the above solved the problem.

    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1583) : error C3861: 'sin': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1595) : error C3861: 'floor': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1595) : error C3861: 'min4': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1596) : error C3861: 'floor': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1596) : error C3861: 'min4': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1598) : error C3861: 'ceil': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1598) : error C3861: 'max4': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1599) : error C3861: 'ceil': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1599) : error C3861: 'max4': identifier not found
    Is that really the library that should be added?! Still confused :(

    Monday, August 24, 2009 3:12 PM
  • Are these the first (and only) errors you get? If you have compiler errors before these, then you may get mis-leading error messages. Also your cos-error has disappeared now?
    http://blog.voidnish.com
    Monday, August 24, 2009 3:19 PM
    Moderator
  • Sorry Nishant, Cos error also exists there . The strange thing is that i have the same code in a different project and it works fine but in new project it doesn't.

    However, angle is of type float .
    float angle;
    sA = (float) sin(angle);
    So I thought maybe these functions are defined for double type, tried it but no difference.

    Yes, they are the first error I get !

    I am still thinking of the reasons !
    Tuesday, August 25, 2009 9:38 AM
  • Can you copy/paste your stdafx.h here?
    http://blog.voidnish.com
    Tuesday, August 25, 2009 10:32 AM
    Moderator
  • Hi Nishant !

    Sure , here it is :

    // stdafx.h : include file for standard system include files,
    //  or project specific include files that are used frequently, but
    //      are changed infrequently
    //
    
    #if !defined(AFX_STDAFX_H__30957A5C_6EBA_4499_9ADE_D4CE3571C684__INCLUDED_)
    #define AFX_STDAFX_H__30957A5C_6EBA_4499_9ADE_D4CE3571C684__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    
    #define VC_EXTRALEAN		// Exclude rarely-used stuff from Windows headers
    
    #include <afxwin.h>         // MFC core and standard components
    #include <afxext.h>         // MFC extensions
    #include <afxdisp.h>        // MFC Automation classes
    #include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls
    #ifndef _AFX_NO_AFXCMN_SUPPORT
    #include <afxcmn.h>			// MFC support for Windows Common Controls
    #endif // _AFX_NO_AFXCMN_SUPPORT
    
    
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_STDAFX_H__30957A5C_6EBA_4499_9ADE_D4CE3571C684__INCLUDED_)
    Tuesday, August 25, 2009 11:12 AM
  • Ok, I don't see <math.h> there. Can you add that just below the <afxdtctl.h> line?

    [This is to test the earlier theory]


    http://blog.voidnish.com
    Tuesday, August 25, 2009 11:20 AM
    Moderator
  • I get exactly same results Nishant :

    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1619) : error C3861: 'cos': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1620) : error C3861: 'sin': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1632) : error C3861: 'floor': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1633) : error C3861: 'floor': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1635) : error C3861: 'ceil': identifier not found
    1>c:\users\eyasdel\documents\cvshome\applications\3daudio\emp_demo\3daudiodemodlg.cpp(1636) : error C3861: 'ceil': identifier not found

    Tuesday, August 25, 2009 11:33 AM
  • After you added it to stdafx.h, did you do a rebuild all?
    http://blog.voidnish.com
    Tuesday, August 25, 2009 12:03 PM
    Moderator
  • Also, immediately after the #include <math.h>, manually copy/paste the definition for one of those functions - say cos. Now rebuild and see if you still get the error - if you do, chances are very good that there's something weird about your include files, and that the files you are editing may not be the actual files being included. Has happened before.
    http://blog.voidnish.com
    Tuesday, August 25, 2009 12:06 PM
    Moderator
  • Yes Nishant, I did so. It can't have access to math library functions.
    • Edited by yade Tuesday, August 25, 2009 12:11 PM
    Tuesday, August 25, 2009 12:08 PM
  • I just made a fake definition :
    double cos(double x){return x;}
    and I placed it right below
    #include <afxdtctl.h>
    in stdafx.h
    #include <afxwin.h>         // MFC core and standard components
    #include <afxext.h>         // MFC extensions
    #include <afxdisp.h>        // MFC Automation classes
    #include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls
    #include <math.h>
    double cos(double x)
    {
    return x;
    };

    and the error for cos HAS gone!

    I get the same error when I have #include <math.h> and when I don't!

    What do you think I can do now? Is there any properties configuration changes that might help or ?!





    Tuesday, August 25, 2009 12:52 PM
  • Make sure there is no _INC_MATH symbol defined in Preprocessor Definitions field of project properties.

    Tuesday, August 25, 2009 1:11 PM
  • I think there is no such a thing. Here is what I have in Preprosessor defintion:

    Preprosessor Defintions:

    _VC80_UPGRADE=0x0600
    _AFXDLL
    _MBCS


    Inherited Values

    _VC80_UPGRADE=0x0600
    _AFXDLL
    _MBCS
    Tuesday, August 25, 2009 1:16 PM
  • Check the math.h file in Visual Studio. It must declare the cos function. Temporary change the filename to something else and rebuild your project. Since there is an #include <math.h> line in your sources, you should obtain “Cannot open include file” error, meaning that the right file is included.

    • Marked as answer by Wesley Yao Monday, August 31, 2009 3:24 AM
    Tuesday, August 25, 2009 2:00 PM
  • Viorel_ There are several math.h files in my computer:

    1. math.h       C:\WINDKK\3790,1830\inc\crt
    2.math.h       c:\users\eyasdel\ ...
    3. ...
    4. ...


    How do I know which one is the one Visual Studio using so I can rename/change it?!
    Tuesday, August 25, 2009 2:13 PM
  • I believe that the right one is in ‘VC\include’ subfolder of Visual Studio. The configurated paths specified in Tools à Project and Solutions à VC++ Directories, Show directories for: Include files, which usually should never be touched, must point to this folder. Your project can also include an Additional Include Directories project property. Try to figure out if the right math.h file is included.

     

    If 'c:\users\eyasdel\math.h' is one of your files, then try renaming it to avoid name collisions.

     

    • Marked as answer by Wesley Yao Monday, August 31, 2009 3:23 AM
    Tuesday, August 25, 2009 2:35 PM
  • You can also right-click on the #include <math.h> line and select open-file. Then look at the path to see if you are opening the actual header file or a custom file that you or a colleague wrote.
    http://blog.voidnish.com
    • Marked as answer by Wesley Yao Monday, August 31, 2009 3:24 AM
    Wednesday, August 26, 2009 11:43 AM
    Moderator