a question about GetSharedLibrary
I want to use a dylib file in my code.i wrote my code like below:
Code is very simple, I built it successfully. But, when running the function "GetSharedLibrary", it returns Error: "unimpErr". Why?I can't find out the reason.So, please help me, i will thank u very much.
my code is a command-line utility with C++ tools. I added the carbon framework in it.
Code:
#include <string.h>
#include <CodeFragments.h>
BOOL CMacLib::LoadLib(FZ_PCSTR MyDylibFileName)
{
BOOL bSuccess = FALSE;
int nLen = strlen(MyDylibFileName);
char szPLibName[256];
szPLibName[0] = nLen;
memcpy(szPLibName+1, MyDylibFileName, nLen);
OSErr myerr;
CFragArchitecture archType = kPowerPCCFragArch;
CFragLoadOptions findFlags = kReferenceCFrag;
CFragConnectionID connID;
Ptr mainAddr;
Str255 errMessage;
myerr= GetSharedLibrary((ConstStr63Param)szPLibName, archType,
findFlags, &connID, &mainAddr, errMessage);
if(myerr== noErr)
{
bSuccess = TRUE;
}
return bSuccess;
}Code is very simple, I built it successfully. But, when running the function "GetSharedLibrary", it returns Error: "unimpErr". Why?I can't find out the reason.So, please help me, i will thank u very much.

my code is a command-line utility with C++ tools. I added the carbon framework in it.
GetSharedLibrary is for CFM. You need to use CFBundle or NSBundle to dynamically load Mach-O code.
Thank you, but what is CFM? My dylib file was written by c++, i can't use GetSharedLibrary to load it??? Can i use the function "dlopen" to load it ?
CFM was the old binary format, Mach-O is the new and shiny one. Although I would much recommend CFBundle or NSBundle over writing dylibs, I think dlopen should be able to load it, yes.
There is a error in the code. I did not find it.
Now, remove the line "szPLibName[0] = nLen;"
then correct the next line as
"memcpy(szPLibName, MyDylibFileName, nLen); "
But after corrected, the problem is still here.Why?
Now, remove the line "szPLibName[0] = nLen;"
then correct the next line as
"memcpy(szPLibName, MyDylibFileName, nLen); "
But after corrected, the problem is still here.Why?
Because GetSharedLibrary doesn't work on the new Mach-O binaries. GetSharedLibrary will only work if you're building an old Mac OS 9 program. (With exceptions)
To Fenris,
thank you very much, I see.
I tried "dlopen", but it must use the absolut path, or set the environment parameters for path. i need put the dylib files with my execution file. I can not set a dylib name in dlopen to load it??
thank you very much, I see.
I tried "dlopen", but it must use the absolut path, or set the environment parameters for path. i need put the dylib files with my execution file. I can not set a dylib name in dlopen to load it??
Why don't you know where your library is?
i just know that the dylib file and the execution file will be put in the same work directory, but the path of directory can be changed. can i only set the dylib file's name in dlopen?? i think maybe it can not find the file which will be loaded if i only write the name, not path.
you can use CFBundle to find your app's directory, then dlopen or CFBundle to load the dylib.
Is dlopen available in OS X these days? Back in the 10.2 days I used "dlcompat" to get dlopen functionality.
Anyway, CFBundle is your friend. I've implemented C++ classloading by using CFBundle to look up factory functions in my executable as well as bundled plugins and it works like a charm, on both intel and PPC. No need to set architecture flags or any other malarky. It really works, and it works really well.
I can post code if you have any questions.
Anyway, CFBundle is your friend. I've implemented C++ classloading by using CFBundle to look up factory functions in my executable as well as bundled plugins and it works like a charm, on both intel and PPC. No need to set architecture flags or any other malarky. It really works, and it works really well.
I can post code if you have any questions.
dlopen is available, and has been for a while (anyone know if it's there in 10.3 or just 10.4?). The old NeXTStep stuff is deprecated in its favor, even.
The comment in dlfcn.h says it's based on dlcompat.
The comment in dlfcn.h says it's based on dlcompat.
OneSadCookie Wrote:dlopen is available, and has been for a while (anyone know if it's there in 10.3 or just 10.4?).
>This doc< says dlopen works in 10.3 but is "more efficient" in 10.4 (for whatever that's worth).
Looking at the source, it got radically overhauled in 10.4.
Thank u very much, everybody. Finally i used dlopen in my code. It works well. But i still want to know how CBundle works.So, if OK, would you like to post the codes here? Thank you again!

