4

I had a opencv project which was working fine. Today I have upgraded my OS X lion to Maverick and I get following error for the imwrite function:

Undefined symbols for architecture x86_64:
  "cv::imwrite(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
      _main in Hello.o
ld: symbol(s) not found for architecture x86_64

I have to say that other opencv functions are still working (e.g. cvWaitKey(), cvShowImage, etc) but imwrite and imread do not work anymore.

You can see the makefile which I use below:

CXX = g++
CXXFLAGS = -O2 -g -Wall -fmessage-length=0 
CPPFLAGS = -I/usr/local/Cellar/opencv/2.4.6.1/include

OBJS =      Hello.o

LDFLAGS = -L/usr/local/Cellar/opencv/2.4.6.1/lib
LDLIBS =  -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video \
          -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect \
          -lopencv_contrib -lopencv_legacy -lopencv_gpu

TARGET =    Hello

.PHONY: all
all: $(TARGET)
$(TARGET):  $(OBJS)
         $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@

.PHONY: clean
clean:
        rm -f $(OBJS) $(TARGET)

Solution: I've solved the problem by installing opencv 2.4.3. You might find more detail in the answer, which I've added.

balazs630
  • 3,421
  • 29
  • 46
csuo
  • 820
  • 3
  • 16
  • 31
  • @DuncanJones, it has nothing to do with the one you have linked. That one is a problem of upgrading xcode. – csuo Oct 30 '13 at 00:03

3 Answers3

3

I solved this by using the -mmacosx-version-min=10.8 option when compiling with g++. It might not be a permanent solution, but at least my code compiles again.

  • Thanks for your answer. Although I have solved the problem , but I tried this one as well and it does not work. I am going to add my solution in the answer for those who have same problem. – csuo Oct 30 '13 at 00:00
0

My bet is that you have your libraries wrong. Make sure that you are using 64 bit libs for a 64 bit build, debug libs for a debug build, etc. Another common reason is your opencv version is an old one? 2.3? If you have the latest, then its most likely the library problem

Also just to clarify, imread and imwrite doesn't work only in debug or both debug and release?

Hope my answers helped you. Do let me know if there is still problems.

rockinfresh
  • 2,068
  • 4
  • 28
  • 46
  • Thanks for your answer. I am using opencv 2.4.6.1. the library Opencv was compiled on my computer OS X (10.8) and right now I am using OS X 10.9. I have added the makefile which compiles my code in the question as well. – csuo Oct 24 '13 at 09:39
  • I got the same problem, and the same environments to you. I installed opencv using macbrew, 2.4.6.1 got the problem, switched 2.4.5 it fixed, so I think it's a problem of 2.4.6.1. – Yang Oct 24 '13 at 11:53
  • @Yang, thanks for your comment. Did you install opencv 2.4.5 using homebrew? – csuo Oct 24 '13 at 14:18
  • yes, my 2.4.5 installed early time, simply brew switch to it. So if you newly install 2.4.5 can compile successful, it proves that problem is only on 2.4.6.1. – Yang Oct 24 '13 at 14:29
  • Because I am trying and homebrew fails to make opencv 2.4.5 in my case and it does not suggest anything. – csuo Oct 24 '13 at 14:33
  • Usually it might be the version's fault or library, but I doubt it from what I been reading so far. I am not an expert when it comes to Mac, have you tried updating to Xcode 5.0.1 and downloading the Command-line Tools for Mavericks from the developer site? Try clearing your makefiles cache? If it still doesn't work, I ran out of ideas, and suggest you try your luck at http://answers.opencv.org/questions/. The forum is not as active as stackoverflow, but it's worth a shot, just to double your chance of fixing it asap. Good Luck!! (: – rockinfresh Oct 25 '13 at 03:59
0

As Yang mentioned in one of the comments, the problem comes from opencv 2.4.6.1. I have installed opencv 2.4.3 using Cmake installer by running the following, and it works:

tar -xf opencv-2.4.3.tar.gz
cd opencv-2.4.3
echo "#define GTEST_USE_OWN_TR1_TUPLE 1" | cat > temp1
cat modules/ts/include/opencv2/ts/ts_gtest.h > temp2
cat temp1 temp2 > modules/ts/include/opencv2/ts/ts_gtest.h
mkdir build
cd build
cmake .. -Wno-dev
make -j8 && sudo make install

P.S: I could not install any old version of opencv using homebrew, you can see here

Community
  • 1
  • 1
csuo
  • 820
  • 3
  • 16
  • 31