【问题标题】:I can't link static library with cmake我无法将静态库与 cmake 链接
【发布时间】:2011-08-22 01:46:27
【问题描述】:

我尝试将 X11、giblib 作为静态库与 cmake 链接。

所以我将此代码附加到 CMakeLists.txt 中

set(BUILD_SHARED_LIBS FALSE)
set(CMAKE_EXE_LINKER_FLAGS '-static')

target_link_libraries(Printmade2 Imlib2)
target_link_libraries(Printmade2 /usr/lib/i386-linux-gnu/libX11.a)
target_link_libraries(Printmade2 /usr/lib/libgiblib.a)

执行'make'后,出现此消息。

/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../libX11.a(OpenDis.o): In function `OutOfMemory':
(.text+0x459): undefined reference to `xcb_disconnect'
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../libX11.a(OpenDis.o): In function `XOpenDisplay':
(.text+0x8f5): undefined reference to `xcb_get_setup'
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../libX11.a(OpenDis.o): In function `XOpenDisplay':
(.text+0xedb): undefined reference to `xcb_get_maximum_request_length'
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../libX11.a(xcb_disp.o): In function `_XConnectXCB':
(.text+0x176): undefined reference to `xcb_parse_display'
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../libX11.a(xcb_disp.o): In function `_XConnectXCB':
(.text+0x1d7): undefined reference to `xcb_connect_to_display_with_auth_info'
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../libX11.a(xcb_disp.o): In function `_XConnectXCB':
(.text+0x1f5): undefined reference to `xcb_get_file_descriptor'
...
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../libX11.a(ClDisplay.o): In function `XCloseDisplay':
(.text+0xbd): undefined reference to `xcb_disconnect'
collect2: ld returned 1 exit status

我猜有些东西遗漏了,所以我应该链接更多的东西

但我在我的文件系统中找不到 .o 文件。

(例如,OpenDis.o、xcb_disp.o、ClDisplay.o)

我应该怎么做才能解决这个问题?

【问题讨论】:

    标签: c++ linux cmake static-linking


    【解决方案1】:

    您似乎缺少 libxcb 静态库。 http://xcb.freedesktop.org/

    【讨论】:

    • 当我链接 libxcb 库时,错误消息被更改。 '/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../libxcb.a(xcb_auth.o): 在函数_xcb_get_auth_info': (.text+0x68a): undefined reference to XdmcpWrap''也许 libxcb.a 需要其他一些库。有什么方法可以知道相关库吗?
    • 我找到了所有相关的库。非常感谢您的回答。
    • 仅供参考,很多库项目会创建类似 /usr/lib/pkgconfig/libname.pc 的文件,该文件包含链接器查找内容的提示。不知道 Xorg 的东西是否会创建这些文件,但是当您尝试推断静态链接依赖项时,它们可以作为有用的提示
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    • 2013-10-09
    • 2015-02-09
    • 1970-01-01
    • 2023-03-05
    • 2019-01-31
    相关资源
    最近更新 更多