I have problems in using the irrklang library. I downloaded the .zip file from https://www.ambiera.com/irrklang/downloads.html. I have a MacBookPro with Mojave 10.14.6.
I tried to compile the following source code:
#include <stdio.h>
#include <irrKlang.h>
using namespace irrklang;
#pragma comment(lib, "irrKlang.lib") // link with irrKlang.dll
int main(int argc, const char** argv){
printf("\nHello World!\n");
return 0;
}
I have a directory which contains
dotnet-4-64
, macosx-gcc
, linux-gcc-64
, winx64-visualStudio
The Makefile is pretty simple (I adapted the one from the examples
directory of the original .zip file):
CPP = g++
OPTS = -dynamiclib -I"include" -L"bin/macosx-gcc" -lirrklang -pthread
all:
$(CPP) main.cpp -o example $(OPTS)
clean:
rm example
I added the -dynamiclib
option because otherwise the linker search for the library in /usr/lib
.
When I run Make
everything seems to work fine, no errors, but if I try to execute ./example
I get the following error:
-bash: ./example: cannot execute binary file
I searched on the web, the only hint I found was to check with file ./example
the compatibility with my OS: the result is
./example: Mach-O 64-bit dynamically linked shared library x86_64
and as expected the binary file actually is executable in this OS. I can not see the problem, does someone have any suggestion?
In addition to the other answer here, there's one more thing you need to do. Dynamic libraries on macOS contain a 'load path' which tell the OS where to find said library to load it when an executable linked about it is launched. This load path is read from the dylib and baked into your executable at link time, which is why you're getting the problem you report in the comments.
Apple provide a utility called install_name_tool
to patch the load path in the executable after linking, so from what you have posted you probably want something like:
install_name_tool -change libirrklang /bin/macosx-gcc/libirrklang example
There's a good writeup about this here:
https://medium.com/@donblas/fun-with-rpath-otool-and-install-name-tool-e3e41ae86172