I'm trying to use CLion (thus CMake) to create OpenGL applications using C++ on MacOS Monterey using a 2021 (so M1 based) Macbook.
Glew2 and GLFW3 are installed correctly using Homebrew, XCode and the commandline tools are installed as well.

Creating and compiling/running through XCode works fine, but using the same libraries and C++ source code from CLion doesn't work.
First it can't find the OpenGL library headers, I fixed that by placing a symlink from their location inside the XCode application libraries in a public location.
Problem is that now I get a linker error stating that Glew and GLFW are Arch64 and it's trying to build an x64 application from CLion. When forcing CLion to compile to arch64 I get an error that the OpenGL core libraries it's trying to link to are x64. Apparently XCode is smart enough to link to the correct libraries automagically but CMake can't find them.

Any ideas as to why this happens and what to do to resolve the problem?

Recommended Answers

All 3 Replies

I can't answer this one directly so I'll write a little about my work at command line app building. Not only must you get the right libraries and such on the machine but there can be other requirements such as environment variables that the the compiler and linker use to find files and such.

Again, I do not have your setup so I can't check this out but again, command line builds can be challenging to those that didn't live prior to the GUI epoch.

Are you adept at looking at the environment variables and know what this compiler/linker uses for said variables?

Have you heard of hardcoded-library-path issues? This question is more to help me understand where you are in your understanding of compilers and linkers.

yeah, everything is there. I've created symlinks from the files inside the XCode installation to places where CMake can see them.

While everything is there (you wrote that) you didn't mention if you know about the environment variables used and to call out paths when you can't get the compiler and linker to go get what you thought it should.

That is, you need to learn about how the command line tools work. I've worked this in the Linux and Windows OSes but no exposure to your setup. I doubt it's much different because MacOS has a lot of roots in BSD.

https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html writes:

The exact search directory list depends on the target system, how GCC is configured, and where it is installed. You can find the default search directory list for your version of CPP by invoking it with the -v option. For example,
cpp -v /dev/null -o /dev/null

As I don't use or need clion I don't know where the documentation is. You on the other hand would know this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.