27

I've got two projects in Xcode, both of them use OpenCL and cl.hpp - OpenCL wrappers for C++.

I'm on Mac OS 10.11.4, using clang-703.0.29 version 7.3.0 and the latest (and pretty bizarre) version of Xcode (Version 7.3 (7D175)).

The first project compiles and builds very well. The result of a build is a static library (.a file). The second one uses this library (I'm just copying & pasting the lib and the headers into this project's directory). I'm also linking OpenCL.framework with this project.

The problem is, the second project doesn't build. It says:

CGLTypes.h - Missing ',' between enumerators

This error is on line 75:

kCGLPFAStereo OPENGL_ENUM_DEPRECATED(10_0, 10_11)        =   6,

It is the only error I'm getting. This happens when cl.hpp includes OpenCL/opencl.h which includes OpenCL/cl_gl_ext.h with #include <OpenGL/CGLTypes.h> in it.

The Base SDK is set to Latest (OS X 10.11). Exactly the same problem has occurred here, but it has been resolved by an OS update. My Mac OS version is already the latest, so I can't do this.

To sum up, the problem is that two projects use the same version of OpenCL, are built on the same machine with the same settings, the same compiler, etc, but one of them doesn't compile.

Edit: here's a link to the first project: Matrix on GitHub. I'll try to add the second one as soon as possible. In fact, it's an ANN that uses Matrix to do operations with matrices. The only thing I do is I include cl.hpp and all the .hpps from Matrix. I'm also trying to link with the .a Matrix library, but the build process doesn't even get to this phase.

What should I do to fix that?

Community
  • 1
  • 1
ForceBru
  • 43,482
  • 10
  • 63
  • 98
  • 32 bit 64 bit vagueness maybe? Both compilers, OSes and binding files are ok? – huseyin tugrul buyukisik Mar 28 '16 at 21:15
  • @huseyintugrulbuyukisik, this is happening _on the same computer_, with _the same compiler_. So, I guess, they're OK – ForceBru Mar 29 '16 at 11:12
  • Are the Framework headers included in the same way? That is, does the answer [here](http://stackoverflow.com/questions/22456384/objective-c-in-qt-with-mavericks) shed any light? – Paul Roub Apr 17 '16 at 19:07
  • @PaulRoub, yes, these headers are included properly (you can check the contents of `cl.hpp` I linked to, if you want). I don't include anything except `cl.hpp` and some standard headers – ForceBru Apr 17 '16 at 19:13
  • Could come from an invisible typo though, or a character being coded a different-than-usual way but being displayed a regular way. – marsei Apr 18 '16 at 10:42
  • 12
    Start with a diff tool. Copy both projects. Confirm problem on copies. Use diff tool to find differencrs. Eliminate them, using source control to be able to roll back. Eventtually produce extremely small difference that triggers problem. – Yakk - Adam Nevraumont Apr 18 '16 at 11:05
  • Is it possible to add a link to a github or other resource that contains both the projects? Also, consider [MCVE](http://stackoverflow.com/help/mcve), i.e., strip your project step by step until it builds again, then add until it doesn't. Since the 2nd project uses the first, it is possible that the problem is actually with the first project, not the 2nd. Try to use _[fakes](https://en.wikipedia.org/wiki/Mock_object#Mocks.2C_fakes_and_stubs)_ so you can remove the dependency on the 1st project. This may help pinpointing _where_ to search for the root of the issue. – Abel Apr 18 '16 at 13:11
  • @Abel, here you are the [first project](https://github.com/ForceBru/Matrix). It builds and works perfectly well. I'll try to create a repo with the second project as soon as possible. Though, the problem seems to be in a _system header_ (which is very odd) and there are no other errors complaining about my `.a` library. – ForceBru Apr 18 '16 at 13:14
  • You probably want to edit your question with links to both projects, so that everyone wanting to help finds them. I don't have the exact same version of MacOS, but I can try to build them. – Abel Apr 18 '16 at 13:16
  • @ForceBru Custom macros and/or order of inclusion could theoretically lead to system headers being parsed in a bogus way, or your copy could be corrupted. Are you sure that specific file is even included in the working project? – Siguza Apr 18 '16 at 13:49
  • @Siguza, you mean, `cl.hpp`? Yes, it is, OpenCL won't work otherwise. – ForceBru Apr 18 '16 at 13:50
  • @ForceBru No, `CGLTypes.h`. – Siguza Apr 18 '16 at 14:01
  • @Siguza, I've explained it in the question: I include only `cl.hpp`, which includes `OpenCL/opencl.h` which includes `OpenCL/cl_gl_ext.h` with `#include ` in it. So, yes, I do. – ForceBru Apr 18 '16 at 14:03
  • I have come across an OpenCL bug before when trying to get a GPU coin miner compiled. I traced it to a guy frustrated with Apple not updating the drive to interface with the AMD API properly in one spcific case. – Almo Apr 19 '16 at 15:24
  • Well, I created a new Xcode project and copied the source files of the second ('broken') project there (as per recommendation of @Yakk). Now it builds well. The question is why? `diff` shows a lot of stuff (Xcode seems to be generating some sort of IDs for each project, sure enough, they differ a lot). The weird thing I noticed is that the original is built with `CreatedOnToolsVersion = 7.1;` while the other with `CreatedOnToolsVersion = 7.3;`. How do I eliminate this difference? – ForceBru Apr 19 '16 at 19:51
  • 2
    @ForceBru This is why many developers prefer not using IDEs to generate build projects: they generate random "features" you don't understand and can break in ways you cannot reasonably understand. As it happens, text editors usually work on the generated files. Instead of "generate new project with XCode", *copy the XCode project files*. Look for any mention of absolute paths into the project, fix them. Now use text editor and diff tool and source control to isolate the problem. – Yakk - Adam Nevraumont Apr 19 '16 at 19:57
  • @Yakk, if I copy the project's files (just create a new directory & copy everything, including the `.xcodeproj` file, there), I get the very same error. – ForceBru Apr 19 '16 at 20:01
  • @ForceBru So now you have to projects that are nominally the same, yet one generates the error and another does not. Either say "oh well, I'll use the one that works", you can do the diff-dance between them, using source control and a text editor to remove differences carefully and testing for the problem. – Yakk - Adam Nevraumont Apr 19 '16 at 20:06
  • @Yakk, now everything works (_thanks for your suggestion_), and I'm happy, so for now I won't bother checking what was wrong (that `CreatedOnToolsVersion`, I presume; BTW, WTF is this? gonna check on Google), maybe later. – ForceBru Apr 19 '16 at 20:20
  • @Yakk, you may want to post an answer here since your solution really helped me – ForceBru Apr 23 '16 at 18:10
  • @ForceBru I just gave an algorithm to find a solution. You solved it; please post it yourself :) – Yakk - Adam Nevraumont Apr 23 '16 at 18:12

1 Answers1

5

Well, the problem was that the second ('broken') project was using the old version of Xcode tools (CreatedOnToolsVersion = 7.1) for some reason. The first one was built with CreatedOnToolsVersion = 7.3;.

If I build Matrix without OpenCL support and link the second project with the generated .a library, everything works fine, so the problem was clearly with OpenCL and different CreatedOnToolsVersion settings.

The problem was solved by creating a new project and copying the files there.

Special thanks to @Yakk for their suggestion in the comments!

ForceBru
  • 43,482
  • 10
  • 63
  • 98