TOP / Phidgets RFID開発キット コマンドラインからコンパイル on MacOSX

Phidgets RFID開発キット コマンドラインからコンパイル on MacOSX

Mac OSXは無償でXcodeという統合開発環境が付いてきます。MicrosoftのVisualStudioのように XcodeがMac OSXの標準開発環境ですが、内部ではアップル・コンピュータ用に拡張されたgccが コンパイラとして使われています。

そう考えると、当然コマンドラインからも実行できるはずなので実際に試してみました。

結果から言うと、問題なく実行できたのですが、C/C++言語の知識があまりないため単純なところで 躓いてしまいました。其の時に海外の方に助けていただいたので其の時のメモです。


Hi All

My name is Satoshi Okita.
I am trying to build command line. but I can not linkage.
I had not probrem to build following sourcecode by Xcode 1.5
on Mac OSX 10.3.9 and All Phidgets Official application running now.

Can I build it by gcc on MacOSX ?

And, Do you know a good linkage guide or tutorial in the Internet ?

---my environment
* Mac OSX 10.3.9
* Xcode 1.5 and patch
* gcc (GCC) 3.3 20030304 (Apple Computer, Inc. build 1671)
* Phidget RFID Kit (version2? print 'PhidgetRFID' on board)

--- follow is my commandline step ---

-bash-3.00$ uname -a
Darwin es.local 7.9.0 Darwin Kernel Version 7.9.0: Wed Mar 30 20:11:17 PST 2005;
 root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC Power Macintosh powerpc
-bash-3.00$ gcc --version
gcc (GCC) 3.3 20030304 (Apple Computer, Inc. build 1671)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

-bash-3.00$ cat main.cpp
/*
main.cpp of Phidgets Official customize by satoshiokita
*/
#include <stdio.h>
#include <CoreFoundation/CoreFoundation.h>
#include <Phidget20/phidget20.h>

CPhidgetManagerHandle phidlist =0;

int something;

int gotAttach(CPhidgetManagerHandle phidm, void *, CPhidgetHandle phid) {

  char *id, *error;

  CPhidget_getDeviceType((CPhidgetHandle)phid,&id);
  printf("Device Added: %s\n",id);

  return 0;
}

int gotDetach(CPhidgetManagerHandle phidm, void *, CPhidgetHandle phid) {
  char *id;

  CPhidget_getDeviceType((CPhidgetHandle )phid,&id);
  printf("Device Removed: %s\n",id);

  return 0;
}

//this is called by the timer in the run loop
void doStuff(CFRunLoopTimerRef timer, void *Handle) {

  fflush(stdout);
}

int main (int argc, const char * argv[]) {

  CFRunLoopTimerRef timer;
  printf("begin initialize\n");
  CPhidgetManager_initialize(&phidlist);
  printf("end initialize\n");

return 0;
}


-bash-3.00$ gcc -v -o main main.cpp -framework Cocoa -framework CoreFoundation -
framework Phidget20 -L/usr/lib -lobjc
Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs
Thread model: posix
gcc version 3.3 20030304 (Apple Computer, Inc. build 1671)
/usr/libexec/gcc/darwin/ppc/3.3/cc1plus -quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=3
 -D__GNUC_PATCHLEVEL__=0 -D__APPLE_CC__=1671 -D__DYNAMIC__ main.cpp -D__GNUG__=3
 -fPIC -quiet -dumpbase main.cpp -auxbase main -version 
 -D__private_extern__=extern -o /var/tmp//ccYaOKOZ.s
GNU C++ version 3.3 20030304 (Apple Computer, Inc. build 1671) (ppc-darwin)
compiled by GNU C version 3.3 20030304 (Apple Computer, Inc. build 1671).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/ppc-darwin/include"
ignoring nonexistent directory "/Local/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/gcc/darwin/3.3/c++
/usr/include/gcc/darwin/3.3/c++/ppc-darwin
/usr/include/gcc/darwin/3.3/c++/backward
/usr/local/include
/usr/include/gcc/darwin/3.3
/usr/include
End of search list.
Framework search starts here:
/System/Library/Frameworks
/Library/Frameworks
End of framework search list.
/usr/libexec/gcc/darwin/ppc/as -arch ppc -o /var/tmp//ccjV8RO3.o /var/tmp//ccYaOKOZ.s
ld -arch ppc -dynamic -o main -lcrt1.o -lcrt2.o -L/usr/lib -L/usr/lib/gcc/darwin/3.3
 -L/usr/lib/gcc/darwin -L/usr/libexec/gcc/darwin/ppc/3.3/../../.. /var/tmp//ccjV8RO3.o 
-framework Cocoa -framework CoreFoundation -framework Phidget20 -lobjc -lgcc -lSystem |
c++filt
ld: Undefined symbols:
___gxx_personality_v0

_________________
----
UKnet, Inc.
A chief of RFID depertment.
Satoshi Okita

E-mail:s-okita@uknet.co.jp
http://www.uknet.co.jp

最後の部分にコンパイルエラーが表示されています。具体的にはリンケージの時にエラーが発生しています。


ld: Undefined symbols:
___gxx_personality_v0

解決

解決方法は単純で、コンパイル時に-lオプションでstdc++を加えることでC++の標準ライブラリを指定 すればよいだけです。標準ライブラリなのでデフォルトで指定されていると思っていたのが盲点だったようで、解決に結構時間がかかってしまいました。

-bash-3.00$ gcc -o main main.cpp -framework Cocoa -framework CoreFoundation -framework Phidget20 -L/usr/lib -lobjc -lstdc++
-bash-3.00$ ./main
begin initialize
end initialize


イバラキングへのリンク Get Firefox Valid XHTML 1.1 Apple Darwinへのリンク