c++ - 如何在 Arch 中安装 libx11-dev? (以下为原标题)

标签 c++ linker g++ turtle-graphics archlinux

原标题:“在C++中使用C-Turtle库时出现链接器错误”

所以,我决定尝试使用 C-turtle 库来制作 pacman 游戏。但是,为了测试该库是否有效,我编写了一个小程序:

// All the custom headers
#include "../Headers/C-Turtle/CTurtle.hpp"

//Namespaces
namespace ct = cturtle;

// Main function
int main() {
    ct::TurtleScreen scr;
    ct::Turtle turtle(scr);
    turtle.forward(50);
    return 0;
}

但是,在尝试实现它时,我遇到了这个巨大的错误:

[ksp-atlas@ksp-arch PacmanGame]$ make
g++ Sources/main.cpp -o Bin/Pacgame
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::cimg::Mutex_info::trylock(unsigned int)':
main.cpp:(.text._ZN12cimg_library4cimg10Mutex_info7trylockEj[_ZN12cimg_library4cimg10Mutex_info7trylockEj]+0x2b): undefined reference to `pthread_mutex_trylock'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::screen_width()':
main.cpp:(.text._ZN12cimg_library11CImgDisplay12screen_widthEv[_ZN12cimg_library11CImgDisplay12screen_widthEv]+0x2c): undefined reference to `XOpenDisplay'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay12screen_widthEv[_ZN12cimg_library11CImgDisplay12screen_widthEv]+0x9e): undefined reference to `XCloseDisplay'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::screen_height()':
main.cpp:(.text._ZN12cimg_library11CImgDisplay13screen_heightEv[_ZN12cimg_library11CImgDisplay13screen_heightEv]+0x2c): undefined reference to `XOpenDisplay'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay13screen_heightEv[_ZN12cimg_library11CImgDisplay13screen_heightEv]+0x9e): undefined reference to `XCloseDisplay'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::_handle_events(_XEvent const*)':
main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x1d4): undefined reference to `XUnmapWindow'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x236): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x326): undefined reference to `XResizeWindow'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x401): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x45a): undefined reference to `XGetWindowAttributes'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x479): undefined reference to `XSync'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x4a2): undefined reference to `XSetInputFocus'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x5e7): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x77a): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x7be): undefined reference to `XLookupString'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x7f8): undefined reference to `XQueryKeymap'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x89e): undefined reference to `XLookupString'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x8ee): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x9d6): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0xa50): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::_events_thread(void*)':
main.cpp:(.text._ZN12cimg_library11CImgDisplay14_events_threadEPv[_ZN12cimg_library11CImgDisplay14_events_threadEPv]+0x84): undefined reference to `XCheckTypedEvent'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_events_threadEPv[_ZN12cimg_library11CImgDisplay14_events_threadEPv]+0xb8): undefined reference to `XCheckMaskEvent'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay14_events_threadEPv[_ZN12cimg_library11CImgDisplay14_events_threadEPv]+0x19d): undefined reference to `pthread_testcancel'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::_set_colormap(unsigned long&, unsigned int)':
main.cpp:(.text._ZN12cimg_library11CImgDisplay13_set_colormapERmj[_ZN12cimg_library11CImgDisplay13_set_colormapERmj]+0x2a6): undefined reference to `XStoreColors'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::_map_window()':
main.cpp:(.text._ZN12cimg_library11CImgDisplay11_map_windowEv[_ZN12cimg_library11CImgDisplay11_map_windowEv]+0x5b): undefined reference to `XMapRaised'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay11_map_windowEv[_ZN12cimg_library11CImgDisplay11_map_windowEv]+0x87): undefined reference to `XWindowEvent'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay11_map_windowEv[_ZN12cimg_library11CImgDisplay11_map_windowEv]+0xe3): undefined reference to `XGetWindowAttributes'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay11_map_windowEv[_ZN12cimg_library11CImgDisplay11_map_windowEv]+0x102): undefined reference to `XSync'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::_paint(bool)':
main.cpp:(.text._ZN12cimg_library11CImgDisplay6_paintEb[_ZN12cimg_library11CImgDisplay6_paintEb]+0x127): undefined reference to `XSendEvent'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay6_paintEb[_ZN12cimg_library11CImgDisplay6_paintEb]+0x1b5): undefined reference to `XPutImage'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::_init_fullscreen()':
main.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x119): undefined reference to `XCreateWindow'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x20d): undefined reference to `XCreateImage'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x23d): undefined reference to `XSelectInput'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x25d): undefined reference to `XMapRaised'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x289): undefined reference to `XWindowEvent'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x30e): undefined reference to `XPutImage'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x339): undefined reference to `XGetWindowAttributes'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x358): undefined reference to `XSync'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::_desinit_fullscreen()':
main.cpp:(.text._ZN12cimg_library11CImgDisplay19_desinit_fullscreenEv[_ZN12cimg_library11CImgDisplay19_desinit_fullscreenEv]+0x35): undefined reference to `XUngrabKeyboard'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay19_desinit_fullscreenEv[_ZN12cimg_library11CImgDisplay19_desinit_fullscreenEv]+0x5f): undefined reference to `XDestroyWindow'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)':
main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x135): undefined reference to `XOpenDisplay'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x392): undefined reference to `XVisualIDFromVisual'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x3be): undefined reference to `XGetVisualInfo'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x41c): undefined reference to `XFree'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x463): undefined reference to `pthread_create'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x64c): undefined reference to `XCreateWindow'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x6d1): undefined reference to `XCreateSimpleWindow'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x70b): undefined reference to `XSelectInput'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x752): undefined reference to `XStoreName'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x7bb): undefined reference to `XCreateColormap'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x81f): undefined reference to `XSetWindowColormap'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x824): undefined reference to `XAllocClassHint'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x878): undefined reference to `XSetClassHint'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x887): undefined reference to `XFree'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x9a6): undefined reference to `XCreateImage'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x9d6): undefined reference to `XInternAtom'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0xa02): undefined reference to `XInternAtom'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0xa43): undefined reference to `XSetWMProtocols'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0xa88): undefined reference to `XGrabKeyboard'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::assign()':
main.cpp:(.text._ZN12cimg_library11CImgDisplay6assignEv[_ZN12cimg_library11CImgDisplay6assignEv]+0x124): undefined reference to `XDestroyWindow'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay6assignEv[_ZN12cimg_library11CImgDisplay6assignEv]+0x19c): undefined reference to `XFreeColormap'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay6assignEv[_ZN12cimg_library11CImgDisplay6assignEv]+0x1bc): undefined reference to `XSync'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::resize(int, int, bool)':
main.cpp:(.text._ZN12cimg_library11CImgDisplay6resizeEiib[_ZN12cimg_library11CImgDisplay6resizeEiib]+0x28f): undefined reference to `XResizeWindow'
/usr/bin/ld: main.cpp:(.text._ZN12cimg_library11CImgDisplay6resizeEiib[_ZN12cimg_library11CImgDisplay6resizeEiib]+0x2b6): undefined reference to `XGetWindowAttributes'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::close()':
main.cpp:(.text._ZN12cimg_library11CImgDisplay5closeEv[_ZN12cimg_library11CImgDisplay5closeEv]+0x8b): undefined reference to `XUnmapWindow'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `cimg_library::CImgDisplay::move(int, int)':
main.cpp:(.text._ZN12cimg_library11CImgDisplay4moveEii[_ZN12cimg_library11CImgDisplay4moveEii]+0x84): undefined reference to `XMoveWindow'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `void cimg_library::CImgDisplay::_resize<unsigned char>(unsigned char, unsigned int, unsigned int, bool)':
main.cpp:(.text._ZN12cimg_library11CImgDisplay7_resizeIhEEvT_jjb[_ZN12cimg_library11CImgDisplay7_resizeIhEEvT_jjb]+0x12d): undefined reference to `XCreateImage'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `void cimg_library::CImgDisplay::_resize<unsigned short>(unsigned short, unsigned int, unsigned int, bool)':
main.cpp:(.text._ZN12cimg_library11CImgDisplay7_resizeItEEvT_jjb[_ZN12cimg_library11CImgDisplay7_resizeItEEvT_jjb]+0x135): undefined reference to `XCreateImage'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `void cimg_library::CImgDisplay::_resize<unsigned int>(unsigned int, unsigned int, unsigned int, bool)':
main.cpp:(.text._ZN12cimg_library11CImgDisplay7_resizeIjEEvT_jjb[_ZN12cimg_library11CImgDisplay7_resizeIjEEvT_jjb]+0x135): undefined reference to `XCreateImage'
/usr/bin/ld: /tmp/ccXl1Nkp.o: in function `std::thread::thread<cturtle::InteractiveTurtleScreen::initEventThread()::{lambda()#1}, , void>(cturtle::InteractiveTurtleScreen::initEventThread()::{lambda()#1}&&)':
main.cpp:(.text._ZNSt6threadC2IZN7cturtle23InteractiveTurtleScreen15initEventThreadEvEUlvE_JEvEEOT_DpOT0_[_ZNSt6threadC5IZN7cturtle23InteractiveTurtleScreen15initEventThreadEvEUlvE_JEvEEOT_DpOT0_]+0x2f): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
make: *** [makefile:5: startmake] Error 1

如果有人能看懂的话,这里到底发生了什么事? ‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌ ‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌ ‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌

编辑

我将问题定位为没有 libx11-dev 包。我找不到 Arch,只有基于 Debian 的发行版。我该如何安装这个?

最佳答案

I localised my issue to not having the package libx11-dev. I can't find it for Arch, only Debian based distros. How do I install this?

Arch 仅在少数情况下拆分 header ,而 x11 不是其中之一。 x11 header 只是 libx11 的一部分:

# pacman -S libx11

关于c++ - 如何在 Arch 中安装 libx11-dev? (以下为原标题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66266541/

相关文章:

c++ - 在函数中间更改变量名

gcc - 为什么丢失的共享库会致命?

gcc - g++、静态初始化和 -nostdlib

c++ - 为什么我的 vector 迭代器没有显示 operator=?

c++ - 运算符删除标准行为

c++ - 使用 STL 映射时出现链接器错误

c++ - VS2010 无法链接它应该构建的库

c++ - 使用gcc在C中链接C++静态库

c++ - 哪个编译器是对的?需要模板化返回类型之前的 'template'?

c++ - boost "no such file or directory"