C++ 找不到架构 x86_64 os x lion 的符号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10725339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:23:06  来源:igfitidea点击:

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

c++macoscompilationlinkercmake

提问by Courier

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:

当尝试使用 opencv 2.3.1 作为第三个库编译一个简单的 c++ test.cpp 代码时,我收到以下错误消息:

Undefined symbols for architecture x86_64:

"_cvLoadImage", referenced from:

_main in test.cpp.o

ld: symbol(s) not found for architecture x86_64

体系结构 x86_64 的未定义符号:

“_cvLoadImage”,引用自:

_main 在 test.cpp.o

ld:找不到架构 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:

有关信息,我使用 CMake 进行链接,以及从 Xcode 4.2 获得的 gcc 4.2.1 i686-apple-darwin11。已经使用 CMake 安装了 OpenCV:

ccmake ../源代码

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

请注意,在尝试编译 SoQt (coin3D) 时,在命令 ./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

. . .

“QWidget 的类型信息”,引用自:SoQtThumbWheelin SoQtThumbWheel.o 的类型信息“QWidget::staticMetaObject”,引用自:SoQtThumbWheel.o 中的 SoQtThumbWheel::staticMetaObject

ld:找不到架构 x86_64 的符号

collect2: ld 返回 1 个退出状态

The CMakeLists.txt of the main project is:

主项目的 CMakeLists.txt 是:

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:

而 test.cpp 的 CMakeLists.txt 是:

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.

也许问题在于 OpenCV 需要以 64 位 (?) 编译。我发现了一个有趣的链接。但我想知道如何将其应用于 CMake。

Any help please?

请问有什么帮助吗?

谢谢。

回答by Gnosophilon

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 oneand that one. Did you take a look at them? Furthermore, please supply more information about howyou are compiling. Can you compile a simple OpenCV test program such as this one (taken from their wiki):

这看起来您没有正确链接库。stackoverflow 上至少有两个类似的问题可以解决这个问题,即this onethat one。你看他们了吗?此外,请提供有关您如何编译的更多信息。你能编译一个简单的 OpenCV 测试程序,比如这个(取自他们的维基):

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

回答by Arno Klein

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

当我在使用 cmake 编译时不小心在我的 CMakeLists.txt 文件中组合了单独的 target_link_libraries() 时,我产生了这个错误。

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
)