在linux下,编译链接的时候,经常会遇到这样一个问题,undefined reference to.....,引起这个问题的原因在于在链接的时候缺少选项。下面举几个例子,并给出解决办法。
1、 undefined reference to `dlerror'
undefined reference to `dlopen'
undefined reference to `dlerror';;解决方法:在makefile的CMAKE_EXE_LINKER_FLAGS后面把选项 -ldl添加上即可
2、undefined reference to `main';;解决方法:在makefile的 ldflags 后面添加 -nostartfiles 选项
3、undefined reference to `pthread_setspecific'
undefined reference to `pthread_key_delete'
undefined reference to `pthread_key_create'::解决办法:在makefile的LDFLAGS后面添加 -lpthread 选项。
最后::如果undefined reference to后面的内容是在自己的文件中声明或定义的东西,就不能用这种方法来解决了。这时就需要检查一下自己的makefile涉及到源文件、头文件的地方是否出错了,也有可能是其他的原因。
4. Linking CXX executable../../bin/opencv_test_calib3d
../../lib/libopencv_core.so:undefined reference to `pthread_key_create'
../../lib/libopencv_core.so:undefined reference to `pthread_getspecific'
../../lib/libopencv_ts.so:undefined reference to `pthread_key_delete'
../../lib/libopencv_core.so:undefined reference to `pthread_once'
../../lib/libopencv_core.so:undefined reference to `clock_gettime'
../../lib/libopencv_core.so:undefined reference to `pthread_setspecific'
collect2: ld returned 1exit status
make[2]: ***[bin/opencv_test_calib3d] Error 1
make[1]: ***[modules/calib3d/CMakeFiles/opencv_test_calib3d.dir/all] Error 2
make: *** [all] Error 2
解决方案:修改release-hisiv200目录下的CMakeCache.txt,CMAKE_EXE_LINKER_FLAGS原来为空,加上-lpthread -lrt
5. how_to_scan_images/how_to_scan_images.cpp.obj] 错误 1
该原因是例程中的TUTORIAL下的gpu-basics-similarity有错误。cmake时只有启用build examples时才会跑这些东东。为让cmake成功,只能将该选项取消掉了哦。