Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: Cannot include GLM in .mm files

  1. #1
    Junior Member Newbie
    Join Date
    May 2010
    Location
    Singapore
    Posts
    5

    Cannot include GLM in .mm files

    Firstly, a big thanks for this great library that Groovounet has written.

    Im trying to write a simple 3d engine for the iPhone and would like to make use of glm internally. I am using C++ but still need to use Cocoa Touch for the initialisation code which is contained in .mm files. I am not using glm from Objective C code.

    The problem is that these mm files include certain C++ classes header files which include glm. glm has certain defines which are reserved keywords in the Objective C language, and since therefore cannot compile.

    Example


    GLView.mm
    ==============
    #include "Renderer.h" //This is a C++ file


    Renderer.h
    ==============
    #include <glm/glm.hpp>


    GLView.mm won't compile because it will indirectly include glm and the compiler will give errors on encountering certain Objective C keywords in the glm header.

    Is there a way to notify the XCode compiler that a particular include in a .mm file is to be treated as C++ code? Something like

    #define COMPILE_AS_CPLUS
    #include <glm/glm.hpp>
    #undef COMPILE_AS_CPLUS

  2. #2
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    936

    Re: Cannot include GLM in .mm files

    Hi GamerSg,

    Thanks!

    Unfortunately, Objective C++ isn't supported yet by GLM. However, I am really interested to add this support. Could you send me a build log or even a XCode project so that I can start working on it? I can then provide GLM snapshots to start working with GLM.

  3. #3
    Junior Member Newbie
    Join Date
    May 2010
    Location
    Singapore
    Posts
    5

    Re: Cannot include GLM in .mm files

    Hi Groovounet,

    The errors are triggered with an extremely simple scenario. Create an empty xcode project file. Add a .mm (Objective C++) file to your project with a minimal main function and include glm.

    From what ive deduced so far, all errors appear to be with enums being named YES and NO. I believe they are reserved keywords in Objective C and are synonymous with true and false in C++.

    Here is a log

    ../external/include/glm/./core/_detail.hpp:179: error: expected identifier before '(' token
    ../external/include/glm/./core/_detail.hpp:179: error: expected `}' before '(' token
    ../external/include/glm/./core/_detail.hpp:179: error: expected ';' before numeric constant
    ../external/include/glm/./core/_detail.hpp:181: error: expected `;' before '}' token
    ../external/include/glm/./core/_detail.hpp:205: error: expected identifier before '(' token
    ../external/include/glm/./core/_detail.hpp:205: error: expected `}' before '(' token
    ../external/include/glm/./core/_detail.hpp:205: error: expected ';' before numeric constant
    ../external/include/glm/./core/_detail.hpp:207: error: expected `;' before '}' token
    ../external/include/glm/./core/_detail.hpp:229: error: expected identifier before '(' token
    ../external/include/glm/./core/_detail.hpp:229: error: expected `}' before '(' token
    ../external/include/glm/./core/_detail.hpp:229: error: expected ';' before numeric constant
    ../external/include/glm/./core/_detail.hpp:231: error: expected `;' before '}' token
    ../external/include/glm/./core/_detail.hpp:232: error: expected declaration before '}' token

  4. #4
    Member Regular Contributor
    Join Date
    Apr 2007
    Posts
    271

    Re: Cannot include GLM in .mm files

    I encountered this often in my own multiplatform projects.
    Usually it is because you named a variable or an argument to be "id". The problem is "id" is a type in objective-C...

    see "section 4. Object datatype (id)" of http://www.faqs.org/faqs/computer-lang/Objective-C/faq/

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    947

    Re: Cannot include GLM in .mm files

    No, the problem is different.

    Personally, I managed to use GLM with Objective-C++.
    The only thing you have to change is those enums which are at that particular position. I don't remember exactly, but some renaming solves the problem. If you are interested, I can check that out for you.

    Anyway, now I have my running application powered by GLM.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  6. #6
    Junior Member Newbie
    Join Date
    May 2010
    Location
    Singapore
    Posts
    5

    Re: Cannot include GLM in .mm files

    Hi aqnuep, if you could point out the changes or better still provide us with the changed files, it would be very helpful. Im sure groove could make use of your changes for the next version of GLM.

  7. #7
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    936

    Re: Cannot include GLM in .mm files

    @GamerSg: Here is a snapshot of the "Objective-C support" branch:

    GLM with Objective C support snapshot

    You can follow the progress and download further updates on this topic by following this link:
    http://ogl-math.git.sourceforge.net/git/...ads/objective-c

    Feel free to report further issues here.
    If the changes required remain that simple, I will apply these changes for the final GLM 0.9.0 release.

    Enjoy!

    @aqnuep:
    Quote Originally Posted by aqnuep
    I don't remember exactly, but some renaming solves the problem. If you are interested, I can check that out for you.

    Anyway, now I have my running application powered by GLM.
    That would be great!

  8. #8
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    936

    Re: Cannot include GLM in .mm files

    I forgot to say that there is a Trac Ticket for this feature if you want:
    https://sourceforge.net/apps/trac/ogl-math/ticket/1

  9. #9
    Junior Member Newbie
    Join Date
    May 2010
    Location
    Singapore
    Posts
    5

    Re: Cannot include GLM in .mm files

    Ive downloaded the snapshot and given it a try and it appears to be working now, although im only using a simple skeleton code in my file and only declared a single vec4 in my code. But atleast it compiles fine, for now atleast.

    Ill keep you updated if i encounter any issues as i make proper use of the library.

    Once again, thanks for the quick fix.

  10. #10
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    936

    Re: Cannot include GLM in .mm files

    Great, thanks!

Posting Permissions

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