Dynamic library loading code disapeared


#1

Hi Jules,

These functions disapeared in the last big changes of the mac platform specific code. Is there a reason why you moved them, or are we the only ones to use it ? : )

// in mac platform specific code
#include "../../../src/juce_core/misc/juce_PlatformUtilities.h"
#include <dlfcn.h>

void* PlatformUtilities::loadDynamicLibrary (const String& name)
  {return dlopen ((const char*) name, RTLD_GLOBAL | RTLD_NOW);}
void PlatformUtilities::freeDynamicLibrary (void* handle)
  {dlclose(handle);}
void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  {return dlsym (libraryHandle, (const char*)procedureName);}

#2

I think they were old carbon functions, and the cocoa equivalent didn’t work in the same way. I don’t think there’s really a cross-platform function that fits…


#3

These are c calls, but they are not supported by windows. You can call them directly or you can put them in a header file and include that header files in source files where you need those calls.

Something like this.

#if WIN32
	#define DYNAMIC_LIBRARY_LOAD(X) ::LoadLibrary(X)
	#define DYNAMIC_LIBRARY_INSTANCE HMODULE
	#define DYNAMIC_LIBRARY_FREE ::FreeLibrary
	#define DYNAMIC_LIBRARY_LOAD_PROC ::GetProcAddress
#else
	#define DYNAMIC_LIBRARY_LOAD(X) dlopen(X,RTLD_LAZY)
	#define DYNAMIC_LIBRARY_INSTANCE void*
	#define DYNAMIC_LIBRARY_FREE dlclose
	#define DYNAMIC_LIBRARY_LOAD_PROC dlsym	

You are not the only one to use it. I use it for loading couple of dll’s on mac and pc without juce.


#4

well, I don’t know anything about cocoa, but we were just missing these functions on MacOS to load some dynamic libraries.
These functions are now inside a

code block so I was wandering why and if you plan to replace them …

For now I just commented out the #if and use the implementation that I gave in my first post.


#5

The problem is that on the mac there are at least 3 different ways you could load different kinds of library/bundle, and in cocoa you no longer have a way of getting function pointers from it - it’s all class-based instead. So really, I can’t see much point in trying to make a cross-platform way of doing it!