0

I have built a static opencv library based on this post, and after that I want to invoke the static opencv library for my application. However, it seems that the application program cannot link the static opencv library, and it gives me the following warnings:

ld: warning: ignoring file /usr/local/lib/libopencv_core.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/libopencv_core.a
ld: warning: ignoring file /usr/local/lib/libopencv_highgui.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/libopencv_highgui.a
ld: warning: ignoring file /usr/local/lib/libopencv_imgproc.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/libopencv_imgproc.a
ld: warning: ignoring file /usr/local/lib/liblibjasper.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/liblibjasper.a
ld: warning: ignoring file /usr/local/lib/liblibjpeg.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/liblibjpeg.a
ld: warning: ignoring file /usr/local/lib/liblibpng.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/liblibpng.a
ld: warning: ignoring file /usr/local/lib/liblibtiff.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/liblibtiff.a
ld: warning: ignoring file /usr/local/lib/libzlib.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/libzlib.a
ld: warning: ignoring file /usr/local/lib/libIlmImf.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/libIlmImf.a

It seems to me that the application program is trying to invoke the dynamic opencv library, and a simple application program that just invokes cv::Mat test will give me the following errors:

Undefined symbols for architecture i386:
  "cv::Mat::deallocate()", referenced from:
      cv::Mat::release() in main.o
  "cv::fastFree(void*)", referenced from:
      cv::Mat::~Mat() in main.o

EDIT: As the answers suggest it is not the link problem rather it is a problem of linking libraries built for different architecture. Besides that, two other important things you should pay attention to when building and using a static OpenCV library are:

  1. Make sure it builds Active Architecture Only (yes).

  2. Also you should link framework Cocoa;general;-framework QTKit;general;-framework QuartzCore;general;-framework AppKit; that opencv_highgui.a uses.

4

3 回答 3

2

This is not about unsuccessful linking this is about unsuccessful building. 'file was built for archive which is not the architecture being linked (i386)'. You need to build it correctly, so to say, build it for correct architecture.

于 2013-10-21T16:31:35.107 回答
1

I believe that by passing no option to cmake command line it did build the libs for the native architecture of your machine (which is the default option), most presumably x86_64. However, for some reason, you're trying to build here a 32 bits i386 application. Thus, you don't have the correct static libraries for your architecture.

You can solve it either by building OpenCV in 32 bits (-Darch=i386) in cmake) or by building your app 64 bits (native arch, or x86_64, depending on your build system).

If you feel brave, you can also build both 32 and 64 bits static libraries, assemble them into a universal binary, and link against that universal lib.

于 2013-10-21T17:42:50.487 回答
0

You should build your local application using:

cmake .. -DOpenCV_DIR=/path/to/opencv-3.0.0-beta/build/ -DCMAKE_OSX_ARCHITECTURES=x86_64

ie. Force local build to be x86_64, which is what the opencv version is

于 2015-01-10T09:52:12.100 回答