阅读:2802回复:16
请教shared libraries 的调用方法(50分)
在mac os 9 上使用mpw编写了一个简单的 shared libraries.基本上就是照着mpw里面 ShLibExample 的例子做的。
1。shared library编译的很正常。 2。我的主程序里调用shared lib 里的函数,告我联不上。 那位明白给指导一下?谢谢。 |
|
|
沙发#
发布于:2003-01-09 20:29
那个例子的源代码和编译说明。
This example demonstrates how to create a shared library on the Macintosh. It builds a fat library, and then a fat application to use that library. To build the C Shared Library Example: make -e -f ShLibExample.make To build the C Shared Library Example suitable for debugging: make -e -f ShLibExample.make -d SymOpt=on The application (ShLibExample) will run successfully only if its shared library (SharedLib) can be found. The shared library will be found if it is in the same folder as the application, or if it is in the system extensions folder, or in an immediate sub-folder of the system extensions folder. If the shared library is not found when the application is launched, the Macintosh will complain that it is missing a piece called \"SharedLib\". // // Main.c - main body of simple C program // // // Copyright ゥ 1993, 1994, Apple Computer, Inc. All rights reserved. // #include \"SharedLib.h\" static WindowPtr gWindow; static Rect gRect; QDGlobals qd; void main () { InitGraf (&qd.thePort); InitFonts (); InitWindows (); InitCursor (); SetRect (&gRect, 100, 100, 400, 200); gWindow = NewWindow (NULL, &gRect, (ConstStr255Param)\"\\pSharedLibExample\", true, rDocProc, (WindowPtr)-1, false, 0); DoMessage(gWindow); } // // SharedLib.c - Source file for simple shared library // // // Copyright ゥ 1993, Apple Computer, Inc. All rights reserved. // #include \"SharedLib.h\" #include <Menus.h> #include <Devices.h> #include <Events.h> char theMessage[80]; static void showMessage (WindowPtr theWindow); static void myPause (void); #pragma export list DoMessage void DoMessage (WindowPtr aWindow) { strcpy (theMessage, (const char *) \"\\pIn Shared Library\"); showMessage (aWindow); myPause (); } static void showMessage (WindowPtr theWindow) { SetPort (theWindow); MoveTo (((theWindow->portRect.right-theWindow->portRect.left) / 2) - (StringWidth ((ConstStr255Param)theMessage) / 2), (theWindow->portRect.bottom-theWindow->portRect.top) / 2); TextFont (systemFont); DrawString ((ConstStr255Param)theMessage); } static void myPause (void) { while (!Button ()) /* wait for user to click */ SystemTask (); /* Give some cpu time to other things running. */ } // // SharedLib.h - header for simple shared library // // // Copyright ゥ 1994, Apple Computer, Inc. All rights reserved. // #include <Windows.h> #include <Quickdraw.h> #include <Fonts.h> #include <string.h> #ifdef __CFM68K__ #pragma lib_export on #endif extern void DoMessage (WindowPtr); #ifdef __CFM68K__ #pragma lib_export off #endif # File: ShLibExample.make # # Builds a fat application and it\'s shared library. # AppName = ShLibExample MakeFile = {AppName}.make App_Type = \'APPL\' App_Creator = \'????\' App_Objects = Main.c.o M68KApp_Objects = Main.o App_Resources = {AppName}.r LibName = SharedLib Lib_Type = \'shlb\' Lib_Creator = \'????\' Lib_Objects = SharedLib.c.o M68KLib_Objects = SharedLib.o Lib_Exports = SharedLib.c.x # Names of export file produced by PPCC for our library. Lib_Resources = {LibName}.r Headers = SharedLib.h SymOpt = off MrCOPT = off MrC_Options = -sym {SymOpt} -opt {MrCOPT} -w 17 SC_Options = -model cfmseg -sym {SymOpt} -mbg full -i {cincludes} -i : -w 17 PPCLink_Options = -sym {SymOpt} ILink_Options = -sym {SymOpt} -mf -model cfmseg ILink_Libraries = \"{SharedLibraries}\"InterfaceLib カ \"{SharedLibraries}\"StdClib カ \"{CFM68KLibraries}\"NuMacRuntime.o PPC_Sys_Libraries = \"{SharedLibraries}\"InterfaceLib カ \"{SharedLibraries}\"StdCLib カ \"{PPCLibraries}\"StdCRuntime.o カ \"{PPCLibraries}\"PPCCRuntime.o .c.o ト .c {MakeFile} # An object depends upon it\'s source. All Objects depend on the Makefile. MrC {MrC_Options} {default}.c -o {Targ} .o ト .c {MakeFile} # An object depends upon it\'s source. All Objects depend on the Makefile. SC {SC_Options} {default}.c -o {Targ} All ト {LibName} {AppName} {App_Objects} {Lib_Objects} トト {Headers} {AppName}.68k トト {M68KApp_Objects} {LibName} ILink {ILink_Options} -xm e カ {deps} カ {ILink_Libraries} カ -o {targ} {AppName}.ppc トト {App_Objects} {LibName} PPCLink カ {deps} カ -o {Targ} カ {PPC_Sys_Libraries} {AppName} ト {AppName}.68k {AppName}.ppc {App_Resources} {MakeFile} duplicate -y {AppName}.68k {Targ} MergeFragment {AppName}.ppc {Targ} Rez {App_Resources} -a -o {Targ} # In truth, our application depends upon the external interfaces of our shared lib # (i.e. the application does not have to be rebuilt every time the library is. But this # rule makes life simplier since we need a library with some good external interfaces # to link our application with. {LibName} ト {LibName}.ppc {LibName}.68k delete -i {targ} MergeFragment -x {deps} {targ} Rez {Lib_Resources} -a -o {Targ} setfile -c {Lib_Creator} -t {Lib_Type} {targ} {LibName}.ppc ト {Lib_Objects} PPCLink {PPCLink_Options} -xm s # Note option to create shared lib (-xm s). カ {Lib_Objects} カ {PPC_Sys_Libraries} カ -o {Targ} MergeFragment -n {LibName} -c -t pwpc -x {targ} # use MergeFragment to create a library cfrg {LibName}.68k ト {M68KLib_Objects} ILink {ILink_Options} -xm s # Note option to create shared lib カ {M68KLib_Objects} カ {ILink_Libraries} カ -o {Targ} MakeFlat {targ} -o {targ} [编辑 - 1/9/03 by moqingsong] |
|
|
板凳#
发布于:2003-01-10 10:15
我只下载了一个mpw,不知还要不要其他的sdk什么的? :(
|
|
|
地板#
发布于:2003-01-10 14:35
呱呱~~~ MPW是虾米冬冬阿~~~
|
|
|
地下室#
发布于:2003-01-10 14:45
看看这些个make文件,头都大了~~~
不知可不可以找到国外的mac fans\'s FTP的站点下到CW阿~~ :( |
|
|
5楼#
发布于:2003-01-10 16:07
code warrior 比mpw好多少?
我实际上并不要用太多的时间,只是简单的要把一个c移植到mac就完了。所以就用了mpw. :( |
|
|
6楼#
发布于:2003-01-10 18:34
this is the error message : ============================================================== # 6:50:48 PM ----- Build of sharelib. # 6:50:48 PM ----- Analyzing dependencies. # 6:50:49 PM ----- Executing build commands. MrC sharelib.c -o :sharelib.c.x -sym off PPCLink -o sharelib \":sharelib.c.x\" \"HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:SharedLibraries:InterfaceLib\" \"HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:SharedLibraries:StdCLib\" \"HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:SharedLibraries:MathLib\" \"HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:PPCLibraries:StdCRuntime.o\" \"HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:PPCLibraries:PPCCRuntime.o\" \"HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:PPCLibraries:PPCToolLibs.o\" -sym off -mf -d -t \'shlb\' -c \'????\' -xm s # 6:50:50 PM ----- Done. make -e -f sharelib.make MrC sharelib.c -o :sharelib.c.x -sym off PPCLink ? -o sharelib ? \":sharelib.c.x\" ? \"{SharedLibraries}InterfaceLib\" \"{SharedLibraries}StdCLib\" \"{SharedLibraries}MathLib\" \"{PPCLibraries}StdCRuntime.o\" \"{PPCLibraries}PPCCRuntime.o\" \"{PPCLibraries}PPCToolLibs.o\" ? -sym off ? -mf -d ? -t \'shlb\' ? -c \'????\' ? -xm s # 6:54:51 PM ----- Build of mainshare. # 6:54:51 PM ----- Analyzing dependencies. # 6:54:51 PM ----- Executing build commands. MrC mainshare.c -o :mainshare.c.x -sym off PPCLink -o mainshare \":mainshare.c.x\" \"HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:SharedLibraries:InterfaceLib\" \"HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:SharedLibraries:StdCLib\" \"HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:SharedLibraries:MathLib\" \"HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:PPCLibraries:StdCRuntime.o\" \"HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:PPCLibraries:PPCCRuntime.o\" \"HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:PPCLibraries:PPCToolLibs.o\" -sym off -mf -d -t \'APPL\' -c \'????\' # Error: File \":mainshare.c.x\" # Reference to unresolved symbol \".ShareDisplay\" # # Unresolved external references: # .ShareDisplay # Error: No output file generated # Error: Error 3034 while linking # Error: There were unresolved references # Fatal error: PPCLink - Execution terminated! ### MPW Shell - Execution of mainshare.makeout terminated. ### MPW Shell - Execution of BuildProgram terminated. |
|
|
7楼#
发布于:2003-01-14 10:59
code warrior 比mpw好多少? ??? biabia~~ :( |
|
|
8楼#
发布于:2003-01-14 11:06
[quote]code warrior 比mpw好多少? ??? biabia~~ :( [/quote] 怎样讲? 我看不懂得呀。。。。 |
|
|
9楼#
发布于:2003-01-14 11:22
[quote][quote]code warrior 比mpw好多少? ??? biabia~~ :( [/quote] 怎样讲? 我看不懂得呀。。。。 [/quote] :D biabia ~~ (只见小蚯蚓嘴巴biabia~~咂吧了两下~~~ 死活讲不出个所以然来~ MUD系统扣除小蚯蚓土币XX元 ) |
|
|
10楼#
发布于:2003-01-14 11:44
晕~倒。。
站起来, 感激涕零。 谢谢捧场。。。。 :D :D |
|
|
11楼#
发布于:2003-01-15 15:36
w8zz把mo弄晕了,哈哈 :D
|
|
|
12楼#
发布于:2003-01-15 15:48
问题自己解决了:
在这里加上自己的库文件就可以了。 ILink_Libraries = \"{SharedLibraries}\"InterfaceLib カ \"{SharedLibraries}\"StdClib カ \"{CFM68KLibraries}\"NuMacRuntime.o 在apple站上有mpw的书下载。 看一下就可以了。一个入门问题。。。。。哎苦闷。 |
|
|
13楼#
发布于:2003-01-17 18:01
congratulation!
|
|
|
14楼#
发布于:2003-01-17 20:40
给分,谢谢大家捧场。 :D
|
|
|
15楼#
发布于:2003-01-18 21:45
收到,谢谢 :)
|
|
|
16楼#
发布于:2003-02-14 12:32
yes
|
|