How to link OpenAL on the command line (OS X) - macos

I'm trying to compile a project which is using OpenAL on Mac OS X 10.7. If I would be using XCode I could link the OpenAL.framework, but in the directory
/System/Library/Frameworks/OpenAL.framework/
theres no subdirectory called 'Libraries'. So what should I link against?

This is just a generic answer to link frameworks in the Mac, it should work for OpenAL.framework
% gcc -framework OpenAL -o test test.c
Also see this old GCC article

Related

How do I link with the IOKit framework on macOS 12.4?

I am working on a C project with its own make-based build system. The project tries to interact with the SCSI subsystem through the IOKit framework. I am developing for arm64 macOS 12.4. The IT staff at our institute has set up this computer for software development, though I don't know exactly what this entails. Compiling and executing simple C programs seems to work fine.
Now, when linking the project, I get an error that the IOKit framework is not found.
ld: framework not found IOKit
fatal error: /Library/Developer/CommandLineTools/usr/bin/libtool: internal link edit command failed
smake: *** Code 1 (Operation not permitted) from command line for target '../../../../../libs/arm64-darwin-clang/pic/libmakestate.dylib'.
smake: The following command caused the error:
echo " ==> LINKING dynamic library \"../../../../../libs/arm64-darwin-clang/pic/libmakestate.dylib\""; libtool -dynamic -o ../../../../../libs/arm64-darwin-clang/pic/libmakestate.dylib -L../../../../../libs/arm64-darwin-clang/pic -L/usr/local/lib -framework IOKit -framework CoreFoundation -install_name /opt/schily/lib/libmakestate.dylib `echo OBJ/arm64-darwin-clang/pic/ld_file.o OBJ/arm64-darwin-clang/pic/lock.o | cat` -lc
Are there any additional options I have to supply to get access to the IOKit framework? A solution that is not specific to the particular macOS version in use would be best.
I have found an old question on a similar topic, but it seems to concern very old versions of macOS and I'm not sure if it is relevant. Also, I do not have permissions to move system files around on this computer.
Please bear with me, I'm not at all experienced in macOS development and am just trying to get this code to work. If you need any additional information, do not hesitate to ask.
This appears to be a consequence of using libtool to link. I was able to produce a working shared library using clang -dynamiclib as indicated in the manual.

GLUT on Mac misses mUI

I'm trying to recompile an older unix OpenGL program on the mac. I came to the moment when most of dependencies are fulfilled. However, now I'm stuck on mUI extension of GLUT. I checked on my linux machine and there is a whole directory lib/mui with sources and include/mui with headers in glut-3.7. After compiling on linux I ended up with library files libglut.so.3.7 and libmui.a. The later one I linked to my program. I have found no trace of mui in GLUT.framework (OSX 10.9, Xcode 6.2; gcc/gfortran 5.0). Has anybody idea how to deal with this problem. I'm a bit afraid to compile glut myself, as I have no idea what will happen to my build if two different GLUTs exist. Should I just compile glut3.7 and statically link my code to this library?
In the end I have compiled the libmui.a file using sources from glut-3.7.
I adapted the make file for linux. The main change was replacing OpenGL and Glut libraries to frameworks:
LIBRARIES = -framework glui -framework glut -framework OpenGL -lXmu -lXext -lX11 -lm
In *.C files I have replaced call to GLUT with:
#ifdef __APPLE__
#include <GLUT/glut.h>
#elif
#include <GL/glut.h>
#endif
That was. I linked the libmui.a to my elderly application and it worked without any trouble.

OpenGL 3.3/4.1 on Mac OSX 10.9 using GLFW library

I’m trying to use OpenGL 3.3/4.1 on my Mac OSX 10.9 now that its finally available. I’ve been using the SuperBible 5 book and its examples to learn 3.3. I just found out that its actually only running OpenGL 2.1 though for my examples when my vertex shader started refusing to compile. I found that I need to get ahold of this GLFW library to do OpenGL windowing for me. This library will allow me to use the 4.1 version of OpenGL that OSX is capable of running. My question is does anybody have a static version of the Mac OSX 9 OpenGL library GLFW version 3.0.4 they can just send me? It is kind of a real pain trying to build the library from scratch as because it involves installing CMake and then the library code and then trying to get it all to work together and compile. I really only need the library so I can start getting OpenGL 3.3/4.1 to run.
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:
Download and extract the GLFW source code.
Open the Terminal.
cd to the extracted directory.
Type in cmake ., hit return.
A Makefile will be created for you.
Type in make, hit return.
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`

Setting up OpenGL and GLFW on Mac OS X 10.8.2

I am having an issue setting up GLFW / OpenGL on Mac. I am running a fully updated Mac OSX 10.8.2, so I am assuming that I have the most up to date mac-compatible OpenGL version and I have compiled the GLFW libraries (2.7.7) using homebrew (OS X package manager).
I am trying to use the following guide, open.gl , and am using the recommended code snippet to verify OpenGL and GLFW are working properly:
\#include <GL/glfw.h>
int main()
{
glfwInit();
glfwSleep( 1.0 );
glfwTerminate();
}
This should show a console application and exit after a second.
I am compiling with g++ in terminal and receiving no compile errors:
g++ a.cpp -lglfw -framework OpenGL -framework Cocoa -framework IOkit
When I run the program with
./a.out
nothing happens, but I do get the 1 second delay before it closes, so I know that much is working.
Let me know if there is any further information that might be helpful.
You have no GL context or window - just a command line application running on a terminal.
Refer to the glfwOpenWindow documentation.

How to compile for Mac OS X 10.5

I'd like to compile my application for version 10.5 and forward. Ever since I upgraded to Snow Leopard and installed the latest XCode, gcc defaults to 10.6. I've tried -isysroot /Developer/SDKs/MacOSX10.5.sdk but that doesn't seem to work. Is there a GCC flag that allows me to set the SDK?
(Incidentally, I changed the gcc symbolic link to point to gcc-4.0 instead of gcc-4.2 and it worked but I thought I could tell the latest GCC to compile for an older SDK).
Thanks,
Rui
In XCode you only need to set the deployment target to OSX 10.5.
For gcc you need to set -mmacosx-version-min=10.5.

Resources