OpenGL 3.3/4.1 on Mac OSX 10.9 using GLFW library

偶尔善良 提交于 2019-11-28 18:54:39

I will suggest installing glfw via homebrew http://brew.sh/ The advantage being you can always uninstall it neatly by doing brew uninstall glfw3!

You need to have the "Command Line Tools for Xcode" and Xcode install https://github.com/Homebrew/homebrew/wiki/Installation

xcode-select --install

Once Homebrew is installed, open the terminal and run

brew update

brew tap homebrew/versions

brew install glfw3 for glfw3 OR

brew install glfw2 for glfw2

Also, if you desire an static build, use the flag --static

brew install --static glfw3

The libraries and include files will be available at usr/local/lib and usr/local/include

Now, if you have a program that relies in opengl and glfw, you'd want to compile it something like this: gcc program.c -o myapp -framework OpenGl -lglfw3 (or -lglfw2)

If you still have some problems with the glfw header file, you can do:

gcc program.c -o myapp -framework OpenGl -I/usr/local/include -lglfw3

To build the GLFW library from source, only a few steps are required:

  1. Download and extract the GLFW source code.

  2. Open the Terminal.

  3. cd to the extracted directory.

  4. Type in cmake ., hit return.

  5. A Makefile will be created for you.

  6. Type in make, hit return.

  7. After the compilation process, type in sudo make install.

The libraries will be copied to /usr/local/lib/, the header files to /usr/local/include/.

Note: You'll need a compiler suite installed to build software, this would usually be the XCode Command Line Tools package. For this, install and launch XCode from the Store or download the tools from the developer site.

If you have troubles with linker try to compile like this:

g++ youSource.cpp -I/usr/local/include -L/usr/local/lib -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation -framework CoreVideo

or just:

g++ youSource.cpp -I/usr/local/include `pkg-config --cflags glfw3`  `pkg-config --static --libs glfw3`
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!