4

When trying to compile a simple c++ test.cpp code with opencv 2.3.1 as as third library, I get the following error message:

Undefined symbols for architecture x86_64:

"_cvLoadImage", referenced from: _main in test.cpp.o ld: symbol(s) not found for architecture x86_64

For info, am using CMake for linking, and gcc 4.2.1 i686-apple-darwin11 obtained from Xcode 4.2. OpenCV had been installed using CMake:

ccmake ../sourcecode

Note please that I get a similar message when trying to compile SoQt (coin3D), after commands ./configure & sudo make:

. . .

"typeinfo for QWidget", referenced from: typeinfo for SoQtThumbWheelin SoQtThumbWheel.o "QWidget::staticMetaObject", referenced from: SoQtThumbWheel::staticMetaObject in SoQtThumbWheel.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status

The CMakeLists.txt of the main project is:

cmake_minimum_required(VERSION 2.8)    
PROJECT(TOTO )

FIND_PACKAGE(OpenCV)

INCLUDE_DIRECTORIES(${TOTO_SOURCE_DIR}/src/control)

SET(ALL_LIB_RAF  ${OPENCV_LIBRARIES}             
         Hello
          )

# FILEs to consider
ADD_SUBDIRECTORY(main) 
ADD_SUBDIRECTORY( src )

While the CMakeLists.txt for test.cpp is:

ADD_EXECUTABLE(helloWorld test)
TARGET_LINK_LIBRARIES(helloWorld ${ALL_LIB_RAF} )

Perhaps the issue consists in the fact that OpenCV needs to be compiled in 64-bit (?). I found an interesting link. But am wondering how that mights be applied to CMake.

Any help please?

Thanks.
Community
  • 1
  • 1
Courier
  • 920
  • 2
  • 11
  • 36

2 Answers2

4

This looks like you are not linking against the library correctly. There are at least two similar questions on stackoverflow that deal with this issue, namely this one and that one. Did you take a look at them? Furthermore, please supply more information about how you are compiling. Can you compile a simple OpenCV test program such as this one (taken from their wiki):

#include <cv.h>
#include <highgui.h>

int main ( int argc, char **argv )
{
  cvNamedWindow( "My Window", 1 );
  IplImage *img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 1 );
  CvFont font;
  double hScale = 1.0;
  double vScale = 1.0;
  int lineWidth = 1;
  cvInitFont( &font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC,
              hScale, vScale, 0, lineWidth );
  cvPutText( img, "Hello World!", cvPoint( 200, 400 ), &font,
             cvScalar( 255, 255, 0 ) );
  cvShowImage( "My Window", img );
  cvWaitKey();
  return 0;
}
Community
  • 1
  • 1
Gnosophilon
  • 1,340
  • 7
  • 24
  • Thanks for your reply. <\p> Your code does not compile either. I saw the two links. The issue is that am linking with CMake. <\p> I think I need to recompile opencv with 64-bit. Please do you know how can we do it with CMake? I.e., which flags to specify? – Courier May 23 '12 at 18:59
  • I found this useful link (http://stackoverflow.com/questions/5781198/compiling-opencv-code-on-a-64-bit-mac) But I did not find how to apply it to CMake – Courier May 23 '12 at 19:01
  • @polar Please add some more details to your original question. How did you try to compile the example code? stackoverflow needs more details in order to help you. – Gnosophilon May 23 '12 at 19:01
  • To compile and create the build: ccmake ../project-source. I did not touch any flag. – Courier May 23 '12 at 19:06
  • @polar How do you want to compile the example above with this command? There's no `CMakeLists.txt`... – Gnosophilon May 23 '12 at 19:07
  • @polar I way implying that you did not specify all relevant information here ;) Did you do a `FIND_PACKAGE(OpenCV REQUIRED)` and added `${OpenCV_LIBS}` to your application via `TARGET_LINK_LIBRARIES`? – Gnosophilon May 23 '12 at 19:10
  • The first CMakeList.txt concerns test.cpp, while the second corresponds to the main project. – Courier May 23 '12 at 19:11
  • @polar Could you please add this information to your original question? This really badly formatted here and will not help others. – Gnosophilon May 23 '12 at 19:15
  • @polar Not really. Do you *want* to read any code that is formatted like that? Please take your time to update the original question. – Gnosophilon May 23 '12 at 19:16
1

I generated this error when I accidentally combined separate target_link_libraries() in my CMakeLists.txt file when compiling with cmake.

Specifically, I took the correct:

target_link_libraries(
GradientComputer
)

target_link_libraries(
Overlap
PointAreaComputer
)

and combined them to create the incorrect:

target_link_libraries(
GradientComputer
Overlap
PointAreaComputer
)
Arno Klein
  • 11
  • 2