Weak Link on MacOS X

Post questions, comments and feedback to our 3Dconnexion Mac Development Team.

Moderator: Moderators

Post Reply
lorenzo
Posts: 2
Joined: Wed Jun 06, 2007 9:39 am
Location: Italy

Weak Link on MacOS X

Post by lorenzo » Fri Jun 22, 2007 2:56 pm

Hi,
I have bought the Space Navigator and implemented the 3dConnexion sample code in my Universal Binary application for MacOS X. It works. As I have seen, the installer of the driver automatically installs the framework at
/Library/Frameworks/3DconnexionClient.framework
And as the Apple guideline says about the weak links, I have removed the direct link to the 3DconnexionClient.framework and added a line
Other Linker Flags: -weak_framework 3DconnexionClient
It doesn't compile. The compiler says that it cannot locate that framework.
So I have tried the following paths, unsuccessfully:
"3DconnexionClient"
"3DconnexionClient.framework"
<3DconnexionClient>
<3DconnexionClient>
/Library/Framework/3DconnexionClient
/Library/Framework/3DconnexionClient.framework
"/Library/Framework/3DconnexionClient"
"/Library/Framework/3DconnexionClient.framework"
</Library>
</Library>
The compiler still says that it cannot compile because it cannot locate that framework.
So I have added the line
Framework Search Paths: /Library/Frameworks
and now I can quite use successfully
Other Linker Flags: -weak_framework 3DconnexionClient
It compiles and launch. The problem is now when I try to simulate the case of an user who has not that framework at
/Library/Framework/3DconnexionClient.framework
I removed the framework folder from there and launched my application. It runs, but the Console reports this error:
2007-06-22 23:27:43.303 MyOwnApp[8935] CFLog (21): Error loading /Library/QuickTime/3DxQuickTime.component/Contents/MacOS/3DxQuickTime: error code 4, error number 0 (Library not loaded: /Users/alm/Library/Frameworks/3DconnexionClient.framework/Versions/A/3DconnexionClient

I suppose that the 3DConnexion developer "alm" has left some trace of himself on the framework.
Anyway, did I miss something? How to fix this problem?

Thank you and regards
Lorenzo

flomotan
Moderator
Moderator
Posts: 287
Joined: Mon Jan 08, 2007 3:37 pm

Post by flomotan » Mon Jun 25, 2007 8:59 am

The user "alm" was present in earlier versions of the 3DconnexionClient framework. This has been removed in v1.2.0 of the driver

ettore
Moderator
Moderator
Posts: 127
Joined: Wed Mar 14, 2007 5:55 pm
Location: SF Bay Area, CA
Contact:

Post by ettore » Thu Aug 09, 2007 1:46 pm

Moved this topic from the generic Mac OS X Discussion Forum.
ettore pasquini
software engineer
3Dconnexion, inc.

Richard Wright
Posts: 3
Joined: Thu Apr 03, 2008 8:41 am
Location: Lake Mary, FL

Weak Linking Framework

Post by Richard Wright » Thu Apr 03, 2008 8:54 am

Weak linking the 3DConnexion framework was a piece of cake... however the instructions for testing to see if the framework is present does not work. I'm running Leopard, and XCode 3.0.

I have the following declaration at the top of my source file:

extern OSErr InstallConnexionHandlers() __attribute__((weak_import));

Then later, I have

if(InstallConnexionHandlers != NULL) {
...

This produces a compiler error: invalid operands of types '<unknown>' and 'int' to binary 'operator!='

Is there a compiler option somewhere, or something obvious (to everyone else) that I missed?

Richard

ettore
Moderator
Moderator
Posts: 127
Joined: Wed Mar 14, 2007 5:55 pm
Location: SF Bay Area, CA
Contact:

Re: Weak Linking Framework

Post by ettore » Thu Apr 03, 2008 9:21 am

Richard Wright wrote:Weak linking the 3DConnexion framework was a piece of cake... however the instructions for testing to see if the framework is present does not work. I'm running Leopard, and XCode 3.0.

I have the following declaration at the top of my source file:

extern OSErr InstallConnexionHandlers() __attribute__((weak_import));

Then later, I have

if(InstallConnexionHandlers != NULL) {
...

This produces a compiler error: invalid operands of types '<unknown>' and 'int' to binary 'operator!='

Is there a compiler option somewhere, or something obvious (to everyone else) that I missed?

Richard
I don't have Leopard right here, but it seems like the InstallConnexionHandlers function is unknown to the compiler. I assume you included our header file before the weak link directive?

Code: Select all

#include "3DConnexionClient/ConnexionClientAPI.h"
After that, the actual link command is to be added in the target Build options, under Other Linker Flags:

-weak_framework 3DconnexionClient
ettore pasquini
software engineer
3Dconnexion, inc.

Richard Wright
Posts: 3
Joined: Thu Apr 03, 2008 8:41 am
Location: Lake Mary, FL

Weak Linking

Post by Richard Wright » Thu Apr 03, 2008 12:41 pm

Yes, I have your include file included (it will not compile without it). I found I can get the code

if(InstallConnexionHandlers != NULL) {
...

to compile if I do _not_ put the

extern OSErr InstallConnexionHandlers() __attribute....

after the include file. So it appears to work... until I run it on another machine. My program launches, but then crashes because InstallConnexionHandlers is not NULL... that makes no sense. After some fiddling, I finally got this to compile and work correctly:

unsigned int address = (unsigned int)(InstallConnexionHandlers);
if(address != 0u) {
result = InstallConnectionHandlers(...

Very weird. I would not have believed it if I hadn't seen it myself. Comparing address to 0 would not work either, I had to put the u suffix on the literal. I don't know if this is an XCode 3.0 or Leopard Quirk... I even tried printing out the value of address on the console (as hex, signed and unsigned ints), it always came back as zero... but the statements:

if(address != 0) or
if(address != NULL)

always evaluated true.

Anyway, it works fine now and I've tested it on a couple machines with and without the framework installed. Perhaps this post will help someone else later if they have the same problem.

Richard

popular123
Posts: 2
Joined: Thu Aug 20, 2009 1:43 am

hey

Post by popular123 » Fri Aug 21, 2009 11:18 pm

2007-06-22 23:27:43.303 MyOwnApp[8935] CFLog (21): Error loading /Library/QuickTime/3DxQuickTime.component/Contents/MacOS/3DxQuickTime: error code 4, error number 0 (Library not loaded: /Users/alm/Library/Frameworks/3DconnexionClient.framework/Versions/A/3DconnexionClient

flomotan
Moderator
Moderator
Posts: 287
Joined: Mon Jan 08, 2007 3:37 pm

Post by flomotan » Tue Aug 25, 2009 11:54 am

Please ensure you have the latest 1.5.7 driver installed. That comes with an updated framework.

significant-bit
Posts: 4
Joined: Mon Jul 19, 2010 11:07 pm
Location: Hattiesburg, United States

Re: Weak Linking Framework

Post by significant-bit » Mon Jul 19, 2010 11:47 pm

Richard Wright wrote: I have the following declaration at the top of my source file:

extern OSErr InstallConnexionHandlers() __attribute__((weak_import));

Then later, I have

if(InstallConnexionHandlers != NULL) {
...

This produces a compiler error: invalid operands of types '<unknown>' and 'int' to binary 'operator!='

Is there a compiler option somewhere, or something obvious (to everyone else) that I missed?
I had this same problem in June 2010, and the culprit on my end was Objective-C++! This did not work in my .mm file, so I moved the test to a separate C file and exposed it to the rest of the code as a "bool available()" function.

Post Reply