Xcodeでのエラーについて

このQ&Aのポイント
  • MacでOpenCVを利用してKinectを扱おうとしている際に、エラーが発生しました。
  • 特にcvCreateImage、cvCvtColor、cvReleaseImage、cvShowImage、cvWaitKeyの関数が見つからないというエラーが出ています。
  • 解決策をご教授いただければと思います。
回答を見る
  • ベストアンサー

Xcodeでのエラーについて

MacでOpenCVを利用してKinectを扱おうとしているのですが、以下のようなエラーが出ました。 ちょっと自分には解決できないのですが、どうすればいいか教えてください。 言語はC++です。 Undefined symbols for architecture x86_64: "_cvCreateImage", referenced from: _main in main.o "_cvCvtColor", referenced from: _main in main.o "_cvReleaseImage", referenced from: _main in main.o "_cvShowImage", referenced from: _main in main.o "_cvWaitKey", referenced from: _main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

質問者が選んだベストアンサー

  • ベストアンサー
  • chie65535
  • ベストアンサー率43% (8519/19367)
回答No.1

cvCreateImageなど、OpenCVのライブラリ関数が入っているライブラリファイルを、リンクするプロジェクトに追加して下さい。 OpenCVのライブラリ関数が入っているライブラリファイルを指定していないので「そんな関数はどこにも無い」って怒ってるんです。

ytasasada
質問者

お礼

ありがとうございます。 解決しました!

関連するQ&A

  • Xcodeでコンパイルエラーが出たときの調べ方

    iPhone向けのメーラーを作ってみようと思い、LibEtPan というライブラリをGitHubから ダウンロードして、以下のURLにある pop-sample.c のサンプルコードを使ってみたところ エラーが出ました。 結論からいうとエラーメッセージをそのままネットで調べて、とりあえずコンパイルエラーは 発生しなくなり、無事、ライブラリを使う事はできたのですが、なぜ動くようになったのか、 今のコンパイルエラーが出ていない状態がはたして正しいのかがわかっておりません。 以下、エラー発生までのプロセスです。 1、新規でiPhone向けプロジェクトを作成 2、libEtPanをサブプロジェクトとして追加 3、libetpan-ios.a をLinkに追加 4、Other Linker Flagsに -lsasl2 を設定 5、pop-sample.cのサンプルコードをコピー (サンプルコード内にあるファイル書き込みの処理はコンソールにメール内容を表示する処理に置き換えた) 手順3と4は以下GitHubのREADMEに書いてある手順です。 https://github.com/dinhviethoa/libetpan この状態でビルドすると、以下のようなエラーが発生しました。 Undefined symbols for architecture i386: "_SecCertificateCopyData", referenced from: _mailstream_low_cfstream_get_certificate_chain in libetpan-ios.a(mailstream_cfstream.o) "_deflate", referenced from: _mailstream_low_compress_write in libetpan-ios.a(mailstream_compress.o) "_deflateEnd", referenced from: _mailstream_low_compress_open in libetpan-ios.a(mailstream_compress.o) _mailstream_low_compress_free in libetpan-ios.a(mailstream_compress.o) "_deflateInit2_", referenced from: _mailstream_low_compress_open in libetpan-ios.a(mailstream_compress.o) "_inflate", referenced from: _mailstream_low_compress_read in libetpan-ios.a(mailstream_compress.o) "_inflateEnd", referenced from: _mailstream_low_compress_open in libetpan-ios.a(mailstream_compress.o) _mailstream_low_compress_free in libetpan-ios.a(mailstream_compress.o) "_inflateInit2_", referenced from: _mailstream_low_compress_open in libetpan-ios.a(mailstream_compress.o) "_kCFStreamPropertySSLPeerCertificates", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) _mailstream_low_cfstream_get_certificate_chain in libetpan-ios.a(mailstream_cfstream.o) "_kCFStreamPropertySSLSettings", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) "_kCFStreamSSLAllowsAnyRoot", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) "_kCFStreamSSLAllowsExpiredCertificates", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) "_kCFStreamSSLAllowsExpiredRoots", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) "_kCFStreamSSLLevel", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) "_kCFStreamSSLValidatesCertificateChain", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) そこで、上記のエラーメッセージをネットで検索し、結果的には以下のことをすることで、コンパイルエラーが 解消しました。 ・CFNetwork.framework と Security.framework のLink追加 ・Other Linker Flags に -lz の追加 そこで、質問ですが、熟練したプログラマは、上記のようなエラーが出たとき、 そのエラーメッセージからどういう情報を読み取り、どのようなプロセスで問題を 解決するのでしょうか? 私は、上記のエラーメッセージを見ても「Undefined symbols」というメッセージから 何かライブラリが足りないのかな?程度しか情報を読み取る事ができませんでした。 以上、よろしくお願いします。

  • Xcodeでのcのコンパイルエラーについて。

    Xcodeでc言語のコンパイル #include <stdio.h> int main(void) { printf("%d", 15 + 37); return(0); } をコンパイルすると ld: 2 duplicate symbols for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) となります。 いろいろ検索してみたのですが、こんな簡単なプログラムのエラーはのっていませんでした。 なにが問題なのでしょうか。 あと use -v ってのもどうやって使うのでしょうか。 よろしくおねがいします。

  • Mac C Undefined x86_64

    C言語の勉強中です。 大学にいたころにLinuxで作ったプログラミングを自分のMacで動かしてみようと思い、コンパイルをかけると、Undefined symbols for architecture x86_64とでました。これを解決したいです。MacOSX LionのIntel Core 2 duo です。僕の試したことを一通り書きます。 僕の動かしたいプログラムのソースの#includeに <FTGL/ftgl.h><GL/glfw.h> とか見慣れないのがあったので、 FTGLをmacportで入れて、glfwをダウンロードし、GLをGLUTに変えてコンパイル cc -I /opt/local/include project.c -o project -framework OpenGL -framework GLUT -lobjc (-I /opt/local/includehはFTGLの入っている場所です) project.c:10:23: error: GLUT/glfw.h: No such file or directory うん?glfw.hをGLUTの中にコピーしたのになぁ?とりあえず現在のディレクトリにglfw.hをコピーし#include "glfw.h"に変更し再びコンパイル Undefined symbols for architecture x86_64: "_ftglRenderFont", referenced from: _outtextxy in ccvINkhN.o "_glfwInit", referenced from: _main in ccvINkhN.o "_glfwOpenWindow", referenced from: _main in ccvINkhN.o "_ftglCreateExtrudeFont", referenced from: _main in ccvINkhN.o "_ftglSetFontFaceSize", referenced from: _main in ccvINkhN.o "_ftglSetFontDepth", referenced from: _main in ccvINkhN.o "_ftglSetFontOutset", referenced from: _main in ccvINkhN.o "_ftglSetFontCharMap", referenced from: _main in ccvINkhN.o "_glfwGetWindowParam", referenced from: _main in ccvINkhN.o "_glfwGetWindowSize", referenced from: _main in ccvINkhN.o "_glfwGetMouseButton", referenced from: _main in ccvINkhN.o "_glfwSwapBuffers", referenced from: _main in ccvINkhN.o "_glfwTerminate", referenced from: _main in ccvINkhN.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status x86_64はたしか64-bitとかそんな感じの意味だった気が?学校のパソコン古かったしなんか違うのかなー?と思い -m32 -I /opt/local/include project.c -o project -framework OpenGL -framework GLUT -lobjc としてコンパイルを試みると Undefined symbols for architecture i386: "_ftglRenderFont", referenced from: _outtextxy in ccePdBJk.o "_glfwInit", referenced from: _main in ccePdBJk.o "_glfwOpenWindow", referenced from: _main in ccePdBJk.o "_glfwGetKey", referenced from: _main in ccePdBJk.o "_ftglCreateExtrudeFont", referenced from: _main in ccePdBJk.o "_ftglSetFontFaceSize", referenced from: _main in ccePdBJk.o "_ftglSetFontDepth", referenced from: _main in ccePdBJk.o "_ftglSetFontOutset", referenced from: _main in ccePdBJk.o "_ftglSetFontCharMap", referenced from: _main in ccePdBJk.o "_glfwGetWindowParam", referenced from: _main in ccePdBJk.o "_glfwGetWindowSize", referenced from: _main in ccePdBJk.o "_glfwGetMouseButton", referenced from: _main in ccePdBJk.o "_glfwSwapBuffers", referenced from: _main in ccePdBJk.o "_glfwTerminate", referenced from: _main in ccePdBJk.o ld: symbol(s) not found for architecture i386 うん?よく分からないがたしかi386は32-bitの意??どっちでやってもダメ??? うる覚えの知識を乱用し 再起動時に「2と3」を押しっぱなしにして(32-bitになる?)からのコンパイル→失敗 「6と4」を押しっぱなしにしてみる→失敗 sudo systemsetup -setkernelbootarchitecture x86_64 →失敗 sudo systemsetup -setkernelbootarchitecture i386 →失敗 sudo systemsetup -setkernelbootarchitecture default →失敗(そりゃそうですよね) うーん、ためしに gcc -vと打ってみると Target: i686-apple-darwin11とか Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.1~22/src/configure --disable-checking --enable-werror --prefix=/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.1~22/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1 Thread model: posix とでてる よく分からないがi686とx86_64ばかりあるところからターゲットは64-bitで作っている? 試しにコンパイルの通った実行ファイルに file test と打ってみる test: Mach-O 64-bit executable x86_64 おお確かにdefaultは64-bitのようだ!今度は同じファイルに対して-m32をつけてコンパイルして、file test test: Mach-O executable i386 うむ。-m32も仕事をしているよう。 これはbitの違いではなく、ダウンロードしたやつのせいとか、僕の置き場所が悪いとか、あるいは別の原因なのでしょうか?レベルの低い質問ですいません。回答お待ちしております。

  • mysql/rubyのインストールが出来ません。

    OS:MacOSX10.5.1 ruby:1.8.6 rails:2.0.2 macにmysql/rubyをインストールしようとしているのですがmakeすることが出来ず困っています。エラー内容は以下の通りです Macintosh:mysql-ruby-2.7.3 atsuhiroteshima$ make cc -arch ppc -arch i386 -pipe -bundle -o mysql.bundle mysql.o -L"." -L"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib" -L. -arch ppc -arch i386 -lruby -L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -lpthread -ldl -lm ld: warning in /usr/local/mysql/lib/mysql/libmysqlclient.dylib, file is not of required architecture Undefined symbols for architecture ppc: "_mysql_store_result", referenced from: _store_result in mysql.o _query in mysql.o "_mysql_stmt_errno", referenced from: _mysql_stmt_raise in mysql.o _stmt_prepare in mysql.o _stmt_result_metadata in mysql.o "_mysql_stmt_error", referenced from: _mysql_stmt_raise in mysql.o "_mysql_options", referenced from: _options in mysql.o      (中略) "_mysql_fetch_field", referenced from: _fetch_field in mysql.o "_mysql_get_proto_info", referenced from: _proto_info in mysql.o "_mysql_errno", referenced from: _mysql_raise in mysql.o _my_errno in mysql.o "_mysql_error", referenced from: _mysql_raise in mysql.o _my_error in mysql.o "_mysql_escape_string", referenced from: _escape_string in mysql.o ld: symbol(s) not found for architecture ppc collect2: ld returned 1 exit status lipo: can't open input file: /var/folders/+b/+b2BrDwnESy62VzzTJy9k++++TI/-Tmp-//cc8ile28.out (No such file or directory) make: *** [mysql.bundle] Error 1 どなたかこのエラーの解決方法を教えていただけないでしょうか。 お願いします。

  • mailを打つアプリを作っているんですけど。

    バグが全然消えずエラー内容見ても何が原因かわかりません。 Undefined symbols for architecture i386: "_OBJC_CLASS_$_MFMailComposeViewController", referenced from: objc-class-ref in InstaEmail.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status エラー内容がわかる人すいませんけど教えてください。

  • Xcodeでのc言語のプログクムについて。

    Xcodeでのc言語のプログクムについて。 ルンゲークッタ法のプログラムを書いているのですがビルドエラーになってしまい、原因が分かりません。  ビルド結果は、 "_func",referenced from: _main in main.o "_dvector",referenced from: _main in main.o _rk4 in main.o symbol(s) not found collect2: ld returned 1 exit status  プログラムは、 #include <stdio.h> #include <stdlib.h> double *dvector(long i, long j); /* ベクトル量領域の確保*/ void free_dvector(double *a, long i); /* 領域の解放*/ double func(double x, double y); /* 関数の定義 */ /* ルンゲークッタ法 */ double *rk4( double y0, double a, double b, int n, double (*f)()); int main (void) { double *y, h, a=0.0, b=1.0, y0=1.0 ; int i, n; printf("分割式を入力してください-->"); scanf("%d",&n); y = dvector( 0, n ); /*領域の確保*/ y = rk4( y0, a, b, n, func ); /*ルンゲクッタ法*/ /* 結果の表示 */ h = (b-a)/n ; /* 刻み幅 */ for (i = 0 ; i <= n ; i++) { printf("x=%f \t y=%f \n", a+i*h, y[i] ); } return 0; } /* ルンゲクッタ法 */ double *rk4( double y0, double a, double b, int n, double (*f)() ) { double k1, k2, k3, k4, h, *y, x; int i; y = dvector( 0, n ); /* y[0,1,....,n]の確保 */ h = (b-a)/n ; /* 初期値の設定 */ y[0] = y0; x = a; /* ルンゲクッタ法 */ for ( i = 0 ; i < n ; i++) { k1 = f(x,y[i]); k2 = f(x+h/2.0, y[i]+h*k1/2.0); k3 = f(x+h/2.0, y[i]+h*k2/2.0); k4 = f(x+h, y[i]+h*k3); y[i+1] = y[i] + h/6.0 * ( k1 + 2.0*k2 + 2.0*k3 + k4 ); x += y[i]; } return y; free_dvector(y, 0); /* 領域の解放 */ }

  • 【OpenCV】BGRからHSVへの画像変換

    OpenCVを使って任意の画像データをBGR表色系からHSV表色系に変換するプログラムです。 コンパイルして実行してみたところ、添付画像のように元画像とは色味が異なった画像が出力されてしまいます。 他の画像ファイルを使ってみましたが結果は同じでした。 HSVへの変換がうまくいってないのでしょうが、調べても原因は分かりませんでした。 どなたか分かる方がいらっしゃいましたらご指摘お願いします。 以下にコードを載せます。 #include <cv.h> #include <highgui.h> int main (int argc, char **argv){ IplImage *src_img=0; // 入力画像 IplImage *hsv_img=0; // hsvに変換された画像 // (1)画像を読み込む src_img = cvLoadImage (argv[1], CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR); // (2)読み込んだ画像をhsvに変換する hsv_img = cvCreateImage (cvGetSize (src_img), IPL_DEPTH_8U, 3); cvCvtColor (src_img, hsv_img, CV_BGR2HSV); // (3)画像を表示,キーが押されたときに終了 cvNamedWindow ("Source_Image", CV_WINDOW_AUTOSIZE); cvNamedWindow ("HSV_Image", CV_WINDOW_AUTOSIZE); cvShowImage ("Source_Image", src_img); cvShowImage ("HSV_Image", hsv_img); cvWaitKey (0); // (4)メモリ解放 cvDestroyWindow ("Source_Image"); cvDestroyWindow ("HSV_Image"); cvReleaseImage (&src_img); cvReleaseImage (&hsv_img); return 0; } OS:Windows7 OpenCVのバージョン:2.1 添付画像で用いた画像の形式:png

  • openCVの動画書き込みのプログラムを作っているのですが・・・

    openCVの動画書き込みのプログラムを作っているのですが・・・ openCVで、読み込んだ動画(元動画)を背景差分法で2値化処理して出来た動画を保存する、というプログラムを作っています。 しかし、保存された動画を見ると、上手く書き込まれていません。というのも、元動画は15秒あるのですが、保存された動画を見ると、わずか2秒ほどで再生が終わってしまいます。 以下がプログラムのソースです。 #include <stdio.h> #include <cv.h> #include <cxcore.h> #include <highgui.h> #define THRESHOLD_MAX_VALUE 255 #define THRESHOLD 45 #define WIDTH 960 #define HEIGHT 540 int main( int argc, char **argv ){ int key; CvCapture *capture = NULL; IplImage *frameImage; IplImage *backgroundImage = cvCreateImage( cvSize(WIDTH, HEIGHT), IPL_DEPTH_8U, 1 ); IplImage *grayImage = cvCreateImage( cvSize(WIDTH, HEIGHT), IPL_DEPTH_8U, 1 ); IplImage *differenceImage = cvCreateImage( cvSize(WIDTH, HEIGHT), IPL_DEPTH_8U, 1 ); IplImage *binaryImage = cvCreateImage( cvSize(WIDTH, HEIGHT), IPL_DEPTH_8U, 1 ); double fps = 30.0; CvVideoWriter* VideoWriter = cvCreateVideoWriter("binary.avi", CV_FOURCC('F','L','V','1'), fps, cvSize(WIDTH, HEIGHT), 0 ); if ( ( capture = cvCreateFileCapture( "00011.avi" ) ) == NULL ) { printf( "File Not Found\n" ); return -1; } frameImage = cvLoadImage("haikei.bmp"); if(frameImage == NULL){ printf("Can't Get\n"); return -1; } cvCvtColor( frameImage, backgroundImage, CV_BGR2GRAY ); while ( 1 ) { frameImage = cvQueryFrame( capture ); if ( frameImage == NULL ){ break; } cvCvtColor( frameImage, grayImage, CV_BGR2GRAY ); cvAbsDiff( grayImage, backgroundImage, differenceImage ); cvThreshold( differenceImage, binaryImage, THRESHOLD, THRESHOLD_MAX_VALUE, CV_THRESH_BINARY ); cvWriteFrame(VideoWriter, binaryImage); key = cvWaitKey( 10 ); if ( key == 'q' ) { break; } } cvReleaseCapture( &capture ); cvReleaseVideoWriter( &VideoWriter ); cvReleaseImage( &backgroundImage ); cvReleaseImage( &grayImage ); cvReleaseImage( &differenceImage ); cvReleaseImage( &binaryImage ); return 0; } 抽出している際に、プロンプト画面に Compiler did not align stack variables.~ と出てきます。 また、非圧縮などでやると再生が出来ません。 PC環境はWindowsXPです。 助けてください!!

  • gfortranによるサブルーチンの実行

    初めて投稿させていただきます。 MacOS X 10.5上でgfortranを使用しているのですが、サブルーチンが実行できなくて困っています。メインプログラム(main.f90)とサブルーチン(fast.f90)を同一フォルダ内に置き、ターミナル上でコマンド $ gfortran main.f90 によってコンパイルを実行したところ、 Undefined symbols: "_fast_", referenced from: _MAIN__ in ccz2x6RV.o _MAIN__ in ccz2x6RV.o ld: symbol(s) not found というメッセージが出てコンパイルが失敗してしまいます。サブルーチンが認識されていないということは分かるのですが、それ以上のことはさっぱり分かりません。ご助力願います。 なお、プログラムの内容は高速フーリエ変換です。また、サブルーチンを用いないプログラムに関しては既に正常に動作することを確認しています。

  • 箱庭諸島2+でコンパイルエラー

    Windows XP SP3 + GCC4.4.0を使っています。 「箱庭諸島の保管庫」というサイトから箱庭諸島2+をダウンロードしてきて、コマンドプロンプトから、解凍したディレクトリに移動し、makeを実行しました。すると、 g++ -c -O2 -Wall main.c In file included from main.c:1: main.h:5:21: error: iostream.h: No such file or directory In file included from main.h:6, from main.c:1: hako_io.h:5:20: error: fstream.h: No such file or directory In file included from info.h:7, from hako_io.h:12, from main.h:6, from main.c:1: value.h:30: error: 'ifstream' has not been declared In file included from hako_io.h:12, from main.h:6, from main.c:1: info.h:30: error: 'ifstream' has not been declared info.h:33: error: 'ofstream' has not been declared info.h:101: error: 'ifstream' has not been declared info.h:104: error: 'ofstream' has not been declared In file included from hako_io.h:14, from main.h:6, from main.c:1: map.h:32: error: 'ofstream' has not been declared map.h:35: error: 'ifstream' has not been declared map.h:185: error: 'ofstream' has not been declared map.h:188: error: 'ifstream' has not been declared In file included from hako_io.h:15, from main.h:6, from main.c:1: command.h:20: error: 'ifstream' has not been declared command.h:21: error: 'ofstream' has not been declared command.h:74: error: 'ifstream' has not been declared command.h:75: error: 'ofstream' has not been declared In file included from main.h:6, from main.c:1: hako_io.h:29: error: ISO C++ forbids declaration of 'ofstream' with no type hako_io.h:29: error: expected ';' before '*' token main.c: In function 'int main()': main.c:5: error: 'srandom' was not declared in this scope make: *** [main.o] Error 1 というエラーが出て、コンパイルされません。 原因はいったいどこにあるのでしょうか。 「ifstream」や「ofstream」といった単語が多く見られるので、そこがエラーの元だとは思うのですが… どなたか、知恵をお貸しいただけないでしょうか。

専門家に質問してみよう