当我编译使用OpenCV和caffe的代码时,我收到以下链接器错误:
static LRESULT WINAPI CallWndProcHook(int nHookCode, WPARAM wParam, LPARAM lParam)
{
std::ofstream DEBUG_STRM;
DEBUG_STRM.open (FILE, std::fstream::app);
DEBUG_STRM << "\n CallWndProcHook entered";
return CallNextHookEx(g_hHook, nHookCode, wParam, lParam);
}
extern "C" __declspec( dllexport ) int _stdcall Start(long handle)
{
HWND objectHWND = (HWND)handle;
DWORD processId;
DWORD threadId;
std::ofstream DEBUG_STRM;
DEBUG_STRM.open (FILE, std::fstream::app);
DEBUG_STRM << "\n Start hooking";
threadId = GetWindowThreadProcessId(objectHWND, &processId);
HINSTANCE hInst = GetModuleHandle("textlocator.dll");
g_hHook = SetWindowsHookEx(WH_CALLWNDPROC, CallWndProcHook, hInst, threadId);
if(g_hHook == NULL){
DEBUG_STRM << "\n Hook unsuccessful";
}else{
DEBUG_STRM << "\n Hook successful";
}
if (g_hHook == 0) {
return 0;
} else {
return 1;
}
DEBUG_STRM.close();
}
这是我的g +命令:
../libs/libopencv_highgui.so: undefined reference to `g_mutex_lock'
../libs/libgstbase-0.10.so.0: undefined reference to `g_cond_init'
../libs/libopencv_highgui.so: undefined reference to `g_mutex_unlock'
../libs/libopencv_highgui.so: undefined reference to `g_cond_broadcast'
../libs/libgstreamer-0.10.so.0: undefined reference to `g_cond_wait_until'
../libs/libopencv_highgui.so: undefined reference to `g_mutex_new'
...
collect2: ld returned 1 exit status
我错过了什么?
答案 0 :(得分:1)
是的,这是一个不与glib链接的简单案例。
一般来说,为了解决这类问题,谷歌中的一个符号名称(例如g_mutex_lock)来确定它来自哪个库。在这种情况下,它是油嘴滑舌。然后,查看他们的文档以获取有关编译使用其库的应用程序的帮助(如果您无法自行解决)。在这种情况下,您最终会here。
一旦确定已安装所有必需的软件包,就可以根据需要扩充编译器选项。
在您的情况下,请尝试g++ -DCPU_ONLY=1 test.cpp -o test `pkg-config --cflags glib-2.0` -I../include -I../include/openblas `pkconfig --libs glib-2.0` -L../libs -Wl,-rpath=../libs -lcaffe -lglog -lboost_system -lopencv_core -lopencv_highgui -lopencv_imgproc
注意使用pkg-config。作为参考,编译仅使用glib的示例应用程序可能如下所示:gcc hello.c `pkg-config --cflags --libs glib-2.0`