A while ago, Alain Fischer announced his new ObjectiveC plugin, allowing Squeak to use Apple's Cocoa and other ObjectiveC libraries. Todd Blanchard and I have since done some further work on it, and it's at the point now where it can begin be used to build Cocoa UIs from within Squeak. As a quick test, I built a native OS X UI for the system browser, which you can see in this screenshot:
http://beta4.com/~avi/browser.jpg
The code is on SqueakSource:
http://kilana.unibe.ch:8888/ObjectiveCBridge/ObjectiveC-avi.70.mcz
You can get a prebuilt plugin (for use with Ian's 3.7 VM) here:
http://beta4.com/~avi/ObjectiveCPlugin
The browser demo can be run with "CCBrowser test". It requires this nib file:
http://beta4.com/~avi/CCBrowser.tgz
You need to untar that and place it inside Contents/Resources/English.lproj of your VM application bundle.
I'm announcing this partly because I've run out of steam on it for now, and am hoping someone else will take it the next step of building UIs for the various Squeak tools (browsers, debuggers, workspaces, inspectors, etc) in Cocoa. A custom NSMorphicView would also be cool, although might be pretty tricky. Anyway, if someone does try to take this on, I'll be more than happy to answer any questions they have about the underlying bridge code.
Cheers, Avi
Great stuff! I'll see what I can do with it, and pester you then :-)
On 1 Jun 2004, at 00:22, Avi Bryant wrote:
A while ago, Alain Fischer announced his new ObjectiveC plugin, allowing Squeak to use Apple's Cocoa and other ObjectiveC libraries. Todd Blanchard and I have since done some further work on it, and it's at the point now where it can begin be used to build Cocoa UIs from within Squeak. As a quick test, I built a native OS X UI for the system browser, which you can see in this screenshot:
http://beta4.com/~avi/browser.jpg
The code is on SqueakSource:
http://kilana.unibe.ch:8888/ObjectiveCBridge/ObjectiveC-avi.70.mcz
You can get a prebuilt plugin (for use with Ian's 3.7 VM) here:
http://beta4.com/~avi/ObjectiveCPlugin
The browser demo can be run with "CCBrowser test". It requires this nib file:
http://beta4.com/~avi/CCBrowser.tgz
You need to untar that and place it inside Contents/Resources/English.lproj of your VM application bundle.
I'm announcing this partly because I've run out of steam on it for now, and am hoping someone else will take it the next step of building UIs for the various Squeak tools (browsers, debuggers, workspaces, inspectors, etc) in Cocoa. A custom NSMorphicView would also be cool, although might be pretty tricky. Anyway, if someone does try to take this on, I'll be more than happy to answer any questions they have about the underlying bridge code.
On 1 Jun 2004, at 00:22, Avi Bryant wrote:
http://beta4.com/~avi/browser.jpg
The code is on SqueakSource:
http://kilana.unibe.ch:8888/ObjectiveCBridge/ObjectiveC-avi.70.mcz
OK, loading this from the repository gets me an error about a dependency that needs to be resolved "SmartSyntaxInterpreterPlugin", which I can't find in a fresh 3.7 beta image. Googling reveals that this was a proposed rename of "TestInterpreterPlugin", which I can't find either, nor the "SmartInterpreterPlugin" that was suggested as a better idea.
Now it seems that this would only be needed for building the actual plugin, which I don't need because I downloaded the binary. So I tried loading it anyway, which proceeds, takes quite some time in downloading/installing and then seems to grind to a halt completely in initializing. Does this simply take a long time? Or do I need to resolve that reference? Or something else?
(I will try again in the meantime)
Cheers,
Marcel
On 1 Jun 2004, at 23:58, Marcel Weiher wrote:
Now it seems that this would only be needed for building the actual plugin, which I don't need because I downloaded the binary. So I tried loading it anyway, which proceeds, takes quite some time in downloading/installing and then seems to grind to a halt completely in initializing. Does this simply take a long time? Or do I need to resolve that reference? Or something else?
(I will try again in the meantime)
OK, I've tried again and it definitely gets stuck in "Initializing...". The progress bar is at about 5% or so (barely started), the image remains pegged at 90% + CPU and locked, meaning Command-. doesn't interrupt and you get a spinning beachball of death.
Curiously, loginwindow goes up to 90% + as well ( dual CPUs ;-), and drops to zero again as soon as the Squeak process is killed, so the two seem to be related, however that would work...
Any ideas?
Cheers,
Marcel
Hi, I am new to mac and I can't get FFI to work in MacOSX. I am using the 3.6 carbon-classic vm. Im still a bit confused with Mach-O. I was used to good'ole elf and dlls.
In order to test I wrote a small example and compiled it both .bundle and .dylib following apple examples. I get the message "cannot find function address".I can use them from C via the NS way (bundle) and linking to a dylib, but cant get sq to find the symbols :(
THIS IS FOR THE DYLIB: this would be answer.c:
int get_answer() { return 42; }
this would be deep.c: #include <stdio.h> int main() { int answer; answer = get_answer(); printf("the answer is %d\n", answer); return 0; }
this would be the Makefile: answer.o: answer.c cc -fno-common -c answer.c
libanswer.dylib: answer.o cc -dynamiclib -install_name libanswer.dylib \ -o libanswer.dylib answer.o
deep.o: deep.c cc -fno-common -c deep.c
deep: deep.o libanswer.dylib $(LD) -o deep deep.o -L. -lanswer
FOR THE BUNDLE: cc -flat_namespace -bundle -undefined supress \ -o libanswer.bundle answer.o I then use NSLookupSymbol() and NSAddressOfSymbol() functions (after loading the file with other NS commands) in the deep.c file.
IN SQUEAK I can't get this to work:
self prueba <cdecl: short 'get_answer' (void) module:'libanswer'> ^self externalCallFailed
Question: which type of library does FFI use? .bundle or dylibs or both? Where does it look for it? putting it in the vm dir doesn't work, there is no ldconfig (ahhhh!)./system/library/frameworks doesent work either (copying my lib into it I mean) The thing is I need to use ODBC with squeak in my mac (Diego Gomez Deck's code I mean). In linux I simply symlinked libiodbc to the vm's directory. In OSX I got libiodbc.dylib only. Any help would be REALLY apreciated! thx in advance!
/diego
You should make sure you have the FFI bundle around, that contains the FFI logic. See ftp://st.cs.uiuc.edu/Smalltalk/Squeak/3.6/mac/carbonplugins/ SqueakFFIPrims.bundle.sit
On Jun 9, 2004, at 10:28 PM, diego bart wrote:
Hi, I am new to mac and I can't get FFI to work in MacOSX. I am using the 3.6 carbon-classic vm. Im still a bit confused with Mach-O. I was used to good'ole elf and dlls.
-- ======================================================================== === John M. McIntosh johnmci@smalltalkconsulting.com 1-800-477-2659 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com ======================================================================== ===
I'm sure I read somewhere is that the function call we make to get the address for a function name doesn't care if it's a bundle or dylib, or something. It does the right thing to resolve the address.
On Jun 9, 2004, at 10:28 PM, diego bart wrote:
In order to test I wrote a small example and compiled it both .bundle and .dylib following apple examples. I get the message "cannot find function address".I can use them from C via the NS way (bundle) and linking to a dylib, but cant get sq to find the symbols :(
-- ======================================================================== === John M. McIntosh johnmci@smalltalkconsulting.com 1-800-477-2659 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com ======================================================================== ===
John M McIntosh writes:
I'm sure I read somewhere is that the function call we make to get the address for a function name doesn't care if it's a bundle or dylib, or something. It does the right thing to resolve the address.
On Jun 9, 2004, at 10:28 PM, diego bart wrote:
In order to test I wrote a small example and compiled it both .bundle and .dylib following apple examples. I get the message "cannot find function address".I can use them from C via the NS way (bundle) and linking to a dylib, but cant get sq to find the symbols :(
Hi thank you for answering.
I already had SqueakFFIPrims.bundle. I think it came with the Carbon version, and the FFI examples work, but I can't get anything else to work with it :( I think I would get the "no function callout mechanism available" (or similar) exception hadn't I gotten the lib, at least this is what happens when you delete it.
Anyway I just in case downloaded the version you mentioned, but it doesnt work either :(
I am using FFI in MacOSX, I simple create a framework in XCode then move the framework xxx.framework to /System/Library/Frameworks , this is a workaround because the other more correct locations: /Library/Frameworks or ~/Library/Frameworks are not working with the current VM.
In Squeak you define (for example):
macCallWith: ba with: res <cdecl: long 'testVF' (VFExternalStructure* VFExternalStructure*) module:'vftest.framework'> ^self externalCallFailed
Where VFExternalStructure is for example a subclass of ExternalData (or the other classes defined in FFI-Kernel).
Then call with (more examples): ba _ ByteArray new: 3456 withAll: 0. res _ ByteArray new: 2800 withAll: 0. [init data, etc...] pba _ VFExternalStructure fromHandle: ba type: ExternalType char. pres _ VFExternalStructure fromHandle: res type: ExternalType char. pBuff _ self macCallWith: pba with: pres.
This example is using ByteArrays (char* in C) you need to change with the other types of (external) data.
On 10/06/2004, at 11:02, Diego Tiscornia wrote:
John M McIntosh writes:
I'm sure I read somewhere is that the function call we make to get the address for a function name doesn't care if it's a bundle or dylib, or something. It does the right thing to resolve the address.
On Jun 9, 2004, at 10:28 PM, diego bart wrote:
In order to test I wrote a small example and compiled it both .bundle and .dylib following apple examples. I get the message "cannot find function address".I can use them from C via the NS way (bundle) and linking to a dylib, but cant get sq to find the symbols :(
Hi thank you for answering.
I already had SqueakFFIPrims.bundle. I think it came with the Carbon version, and the FFI examples work, but I can't get anything else to work with it :( I think I would get the "no function callout mechanism available" (or similar) exception hadn't I gotten the lib, at least this is what happens when you delete it.
Anyway I just in case downloaded the version you mentioned, but it doesnt work either :(
Javier Diaz-Reinoso Web: http://homepage.mac.com/javier_diaz_r/
Javier Diaz-Reinoso wrote:
I am using FFI in MacOSX, I simple create a framework in XCode then move the framework xxx.framework to /System/Library/Frameworks , this is a workaround because the other more correct locations: /Library/Frameworks or ~/Library/Frameworks are not working with the current VM.
great! thanks a lot I'll try this. another question, is anyone using odbc in squeak in macosx?
On 10/06/04 13:02, "Diego Tiscornia" diegobt@hotmail.com wrote:
John M McIntosh writes:
I'm sure I read somewhere is that the function call we make to get the address for a function name doesn't care if it's a bundle or dylib, or something. It does the right thing to resolve the address.
On Jun 9, 2004, at 10:28 PM, diego bart wrote:
In order to test I wrote a small example and compiled it both .bundle and .dylib following apple examples. I get the message "cannot find function address".I can use them from C via the NS way (bundle) and linking to a dylib, but cant get sq to find the symbols :(
Hi thank you for answering.
I already had SqueakFFIPrims.bundle. I think it came with the Carbon version, and the FFI examples work, but I can't get anything else to work with it :( I think I would get the "no function callout mechanism available" (or similar) exception hadn't I gotten the lib, at least this is what happens when you delete it.
Anyway I just in case downloaded the version you mentioned, but it doesnt work either :(
Diego: Try this pre - alpha and thanks to John M McIntosh for clues to me. In a week end I try to complete Quickdraw api and do some tutorial and add to minnow. You can email me diret to edgardec2003@ciudad.com.ar.
Edgar
Hi I thanks to all the advice I could get odbc to work in squeak on my mac. In case its useful to someone this are the steps:
0 I'm supposing you have an odbc dsn working using iodbc (the default mac driver, samething for unixodbc), and you downloaded the odbc client package from squeakMap
1 from a terminal create an odbc.framework directory. (sudo mkdir /System/Library/Frameworks/odbc.framework)
2 symlink the iodbc library into the newly created directory ln -s /usr/lib/libiodbc.dylib \ /System/Library/Frameworks/odbc.framework/libiodbc
3 in squeak browse ODBCLibrary class, change the method moduleName to: moduleName "Return the name of the module for this library" ^ 'libiodbc.framework'
4 inspect ODBCLibrary class and do "default _ nil" (do it) in the inspector. This class is a Singleton and you want the new instance to load the new moduleName.
5 try the ODBCConnection examples!
Thanks to all who helped me out! /diego
Hi Diego,
Thanks for posting your advice! I now almost have ODBC working on my Mac. I did see one typo in your instructions -
1 from a terminal create an odbc.framework directory. (sudo mkdir /System/Library/Frameworks/odbc.framework)
should I think say "libiodbc.framework", as that is the name used later. (The same is true for step 2.)
2 symlink the iodbc library into the newly created directory ln -s /usr/lib/libiodbc.dylib \ /System/Library/Frameworks/odbc.framework/libiodbc
I am still getting an error - maybe you have seen something like it. I have installed FreeTDS, to connect to an MS SQL Server, and have configured iODBC to use it. The connection works with iODBC's 'odbctest' program.
When I try to use my DSN from Squeak, I always get an ODBCError with no detailed error message, at initial connection time. Have you had this happen? What are some possible sources of trouble I could look for?
I think it is finding the library, as it gave me a different message when it could not.
Thanks much, Ben Schroeder
Hi ben, sorry I didn't answer before. Yes, you are right about the typo :/ thx Yes I think you got the FFi part working (for odbc, if you get that error) When you I got ODBCError, I debugged it and found out that the ODBCConnection object hadn't got an open connection, which meant it couldn't establish one, as my connection string was ok, (dsn, usr, pwd) it turned out the problem was with iodbc and/or odbc.ini. What does the debugger tell you?
By the way, I couldn't get the iodbc that shipped with mi mac to work, so I got bored and installed unixodbc from the fink distro, made that work and everything worked fine.
hope this helps!
Ben Schroeder wrote:
Hi Diego,
Thanks for posting your advice! I now almost have ODBC working on my Mac. I did see one typo in your instructions -
1 from a terminal create an odbc.framework directory. (sudo mkdir /System/Library/Frameworks/odbc.framework)
should I think say "libiodbc.framework", as that is the name used later. (The same is true for step 2.)
2 symlink the iodbc library into the newly created directory ln -s /usr/lib/libiodbc.dylib \ /System/Library/Frameworks/odbc.framework/libiodbc
I am still getting an error - maybe you have seen something like it. I have installed FreeTDS, to connect to an MS SQL Server, and have configured iODBC to use it. The connection works with iODBC's 'odbctest' program.
When I try to use my DSN from Squeak, I always get an ODBCError with no detailed error message, at initial connection time. Have you had this happen? What are some possible sources of trouble I could look for?
I think it is finding the library, as it gave me a different message when it could not.
Thanks much, Ben Schroeder
On 6/24/04 8:53 AM, "Diego Tiscornia" diegobt@hotmail.com wrote:
Hi ben, sorry I didn't answer before. Yes, you are right about the typo :/ thx Yes I think you got the FFi part working (for odbc, if you get that error) When you I got ODBCError, I debugged it and found out that the ODBCConnection object hadn't got an open connection, which meant it couldn't establish one, as my connection string was ok, (dsn, usr, pwd) it turned out the problem was with iodbc and/or odbc.ini. What does the debugger tell you?
By the way, I couldn't get the iodbc that shipped with mi mac to work, so I got bored and installed unixodbc from the fink distro, made that work and everything worked fine.
hope this helps!
Hi Diego,
Thanks for your reply. If I remember correctly, I did have something similar to what you say: the driver had allocated handles correctly but couldn't run SQLConnect. The connection string seemed to be correct.
I tried creating the connection using a plain C program, and it failed there too. The nearest I could tell, the FreeTDS library was having trouble dynamically loading the iodbc libraries that it needed.
Following a tip on another mailing list, I tried using the FreeTDS library as the ODBC library directly, rather than going through iodbc, as its interface is the same for at least many things. (That is to say, I made the symlink to the FreeTDS library file instead of to the iodbc one.)
This worked fine! (... at least for the few things I've tried.)
I don't think I need a driver manager right now, but if I do, I may try unixodbc - thanks for the tip.
I hope this helps anyone else trying to get this kind of thing working.
Thanks again for your installation notes and help!
Regards, Ben Schroeder
On Jun 1, 2004, at 3:58 PM, Marcel Weiher wrote:
OK, loading this from the repository gets me an error about a dependency that needs to be resolved "SmartSyntaxInterpreterPlugin", which I can't find in a fresh 3.7 beta image. Googling reveals that this was a proposed rename of "TestInterpreterPlugin", which I can't find either, nor the "SmartInterpreterPlugin" that was suggested as a better idea.
SmartSyntaxInterpreterPlugin is part of VMMaker. But you're right that if you don't need to build the plugin, you can proceed through that warning.
So I tried loading it anyway, which proceeds, takes quite some time in downloading/installing and then seems to grind to a halt completely in initializing. Does this simply take a long time? Or do I need to resolve that reference? Or something else?
Hm, it went by relatively quickly for me (the actual load does take a while because of all the convenience stubs for FoundationKit and AppKit methods). I tried it on a fresh 5923 image, with the Squeak 3.7b-5 VM and the ObjectiveCPlugin already installed.
Which versions are you using?
Avi
Success! Didn't change a thing, except having VMMaker already loaded. This time, the "initializing..." progress bar didn't even appear long enough to be noticeable, the various tests worked and I started playing around with the browser after putting the nib in the right place.
Third time lucky? (Versions were exact same ones you mentioned, all freshly downloaded)
Now I'll play around with it some more....I see you are using the threaded model...interesting...but it's so wonderful to finally have this in place!
Cheers,
Marcel
On 2 Jun 2004, at 02:41, Avi Bryant wrote:
On Jun 1, 2004, at 3:58 PM, Marcel Weiher wrote:
OK, loading this from the repository gets me an error about a dependency that needs to be resolved "SmartSyntaxInterpreterPlugin", which I can't find in a fresh 3.7 beta image. Googling reveals that this was a proposed rename of "TestInterpreterPlugin", which I can't find either, nor the "SmartInterpreterPlugin" that was suggested as a better idea.
SmartSyntaxInterpreterPlugin is part of VMMaker. But you're right that if you don't need to build the plugin, you can proceed through that warning.
So I tried loading it anyway, which proceeds, takes quite some time in downloading/installing and then seems to grind to a halt completely in initializing. Does this simply take a long time? Or do I need to resolve that reference? Or something else?
Hm, it went by relatively quickly for me (the actual load does take a while because of all the convenience stubs for FoundationKit and AppKit methods). I tried it on a fresh 5923 image, with the Squeak 3.7b-5 VM and the ObjectiveCPlugin already installed.
Which versions are you using?
Avi
I am experiencing the same problem as Marcel. I think the trick is "having VMMaker already loaded", but I have no idea what this means. I've scanned the swiki, but nothing really tips me off. Any ideas?
I'm using the unix vm (3.7b-5) with the 5989 image.
Thanks, Wilkes
--- In squeak@yahoogroups.com, Marcel Weiher <marcel@m...> wrote:
Success! Didn't change a thing, except having VMMaker already loaded. This time, the "initializing..." progress bar didn't even appear long enough to be noticeable, the various tests worked and I started playing around with the browser after putting the nib in the right place.
Third time lucky? (Versions were exact same ones you mentioned, all freshly downloaded)
Now I'll play around with it some more....I see you are using the threaded model...interesting...but it's so wonderful to finally have this in place!
Cheers,
Marcel
On 2 Jun 2004, at 02:41, Avi Bryant wrote:
On Jun 1, 2004, at 3:58 PM, Marcel Weiher wrote:
OK, loading this from the repository gets me an error about a dependency that needs to be resolved "SmartSyntaxInterpreterPlugin", which I can't find in a fresh 3.7 beta image. Googling reveals that this was a proposed rename of "TestInterpreterPlugin", which I can't find either, nor the "SmartInterpreterPlugin" that was suggested
as a
better idea.
SmartSyntaxInterpreterPlugin is part of VMMaker. But you're right that if you don't need to build the plugin, you can proceed through that warning.
So I tried loading it anyway, which proceeds, takes quite some time in downloading/installing and then seems to grind to a halt completely in initializing. Does this simply take a long time? Or do I need to resolve that reference? Or something else?
Hm, it went by relatively quickly for me (the actual load does take a while because of all the convenience stubs for FoundationKit and AppKit methods). I tried it on a fresh 5923 image, with the Squeak 3.7b-5 VM and the ObjectiveCPlugin already installed.
Which versions are you using?
Avi
squeak-dev@lists.squeakfoundation.org