symbol(s) not found for architecture x86_64 os x lion

徘徊边缘 提交于 2019-12-07 09:01:20

问题


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.

回答1:


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;
}



回答2:


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
)


来源:https://stackoverflow.com/questions/10725339/symbols-not-found-for-architecture-x86-64-os-x-lion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!