Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Cannot compile c program - D11 [SOLVED]

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
User avatar
Scorpion
Posts: 389
Joined: 2018-10-17 11:38
Has thanked: 5 times

Cannot compile c program - D11 [SOLVED]

#1 Post by Scorpion »

I have this error on D11:

Code: Select all

make "CFLAGS=$(pkg-config --cflags --libs xcb xcb-randr)" bspwmxzoomrule
cc -lxcb -lxcb-randr    bspwmxzoomrule.c   -o bspwmxzoomrule
/usr/bin/ld: /tmp/ccFprU6F.o: in function `main':
bspwmxzoomrule.c:(.text+0xd7): undefined reference to `xcb_connect'
/usr/bin/ld: bspwmxzoomrule.c:(.text+0xe7): undefined reference to `xcb_connection_has_error'
/usr/bin/ld: bspwmxzoomrule.c:(.text+0x147): undefined reference to `xcb_get_property'
/usr/bin/ld: bspwmxzoomrule.c:(.text+0x164): undefined reference to `xcb_get_property_reply'
/usr/bin/ld: bspwmxzoomrule.c:(.text+0x1ac): undefined reference to `xcb_get_property_value_length'
/usr/bin/ld: bspwmxzoomrule.c:(.text+0x1c8): undefined reference to `xcb_get_property_value'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: bspwmxzoomrule] Error 1
When compiling this:

Code: Select all

#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>

#include <xcb/xproto.h>

/* make "CFLAGS=$(pkg-config --cflags --libs xcb)" bspwmxzoomrule
cc -lxcb    bspwmxzoomrule.c   -o bspwmxzoomrule
*/

int main(const int argc, const char *const argv[])
{
    if (argc < 2) {
        if (fputs("No arguments given.\n", stderr) == EOF)
            perror("fputs");
        return EXIT_FAILURE;
    }

    char *end;
    const union {
        unsigned long as_ulong;
        xcb_window_t as_xcb_window_t;
    } wid = {
        .as_ulong = strtoul(argv[1], &end, 0),
    };
    if (wid.as_ulong == ULONG_MAX) {
        perror("strtoul");
        return EXIT_FAILURE;
    }
    if (*end != '\0' || wid.as_xcb_window_t == XCB_NONE) {
        if (fputs("Invalid argument.\n", stderr) == EOF)
            perror("fputs");
        return EXIT_FAILURE;
    }

    xcb_connection_t *const xcb = xcb_connect(NULL, NULL);
    if (xcb_connection_has_error(xcb)) {
        if (fputs("xcb_connect() failed.\n", stderr) == EOF)
            perror("fputs");
        return EXIT_FAILURE;
    }

    static const char xzoom_str[] = "xzoom";

    const xcb_get_property_cookie_t cookie =
        xcb_get_property(xcb, 0, wid.as_xcb_window_t,
                         XCB_ATOM_WM_ICON_NAME, XCB_ATOM_STRING, 0,
                         sizeof xzoom_str
                             ? 1 + (sizeof xzoom_str - 1) / 4
                             : 0);
    xcb_get_property_reply_t *const reply =
        xcb_get_property_reply(xcb, cookie, NULL);
    if (reply == NULL) {
        if (EOF == fputs("xcb_get_property(WM_ICON_NAME) failed.\n",
                         stderr)) {
            perror("fputs");
        }
        return EXIT_FAILURE;
    }

    const int length = xcb_get_property_value_length(reply);
    if (length != sizeof xzoom_str - 1)
        return EXIT_FAILURE;

    const char *const value = xcb_get_property_value(reply);
    if (strncmp(value, xzoom_str, sizeof xzoom_str - 1) != 0)
        return EXIT_FAILURE;

    free(reply);

    if (puts("state=floating sticky=on") == EOF) {
        perror("puts");
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}
I was told to report about "XCB library and why the behavior is different apart from most of the other linux distros".

Is this a Debian 11 problem?
Last edited by Scorpion on 2022-12-07 08:54, edited 1 time in total.

LE_746F6D617A7A69
Posts: 932
Joined: 2020-05-03 14:16
Has thanked: 7 times
Been thanked: 65 times

Re: Cannot compile c program - D11

#2 Post by LE_746F6D617A7A69 »

Hi,

Your program and build command looks OK.
Apparently, for some strange reason the linker can't find the libxcb.so library.

The library should be located at: /usr/lib/x86_64-linux-gnu/libxcb.so (assuming that You have 64bit OS).
Also You should check the output of ldconfig -v:

Code: Select all

>sudo ldconfig -v | grep libxcb.so
(...)
	libxcb.so.1 -> libxcb.so.1.1.0  // <-- THIS
(...)
Scorpion wrote: 2022-12-05 17:14 I was told to report about "XCB library and why the behavior is different apart from most of the other linux distros".
Nope, there's nothing unusual in the behavior of libxcb under Debian ;)
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed

User avatar
Scorpion
Posts: 389
Joined: 2018-10-17 11:38
Has thanked: 5 times

Re: Cannot compile c program - D11

#3 Post by Scorpion »

Code: Select all

ldconfig -v | grep libxcb.so
ldconfig: Can't stat /usr/local/lib/i386-linux-gnu: No such file or directory
ldconfig: Path `/usr/lib/i386-linux-gnu' given more than once
ldconfig: Can't stat /usr/local/lib/i686-linux-gnu: No such file or directory
ldconfig: Can't stat /lib/i686-linux-gnu: No such file or directory
ldconfig: Can't stat /usr/lib/i686-linux-gnu: No such file or directory
ldconfig: Can't stat /usr/local/lib/x86_64-linux-gnu: No such file or directory
ldconfig: Path `/usr/lib/x86_64-linux-gnu' given more than once
ldconfig: Path `/lib/x86_64-linux-gnu' given more than once
ldconfig: Path `/usr/lib/x86_64-linux-gnu' given more than once
ldconfig: Path `/usr/lib' given more than once
	libxcb.so.1 -> libxcb.so.1.1.0
ldconfig: /lib/i386-linux-gnu/ld-2.31.so is the dynamic linker, ignoring

ldconfig: /lib/x86_64-linux-gnu/ld-2.31.so is the dynamic linker, ignoring

	libxcb.so.1 -> libxcb.so.1.1.0

Code: Select all

file /usr/lib/x86_64-linux-gnu/libxcb.so
/usr/lib/x86_64-linux-gnu/libxcb.so: symbolic link to libxcb.so.1.1.0

LE_746F6D617A7A69
Posts: 932
Joined: 2020-05-03 14:16
Has thanked: 7 times
Been thanked: 65 times

Re: Cannot compile c program - D11

#4 Post by LE_746F6D617A7A69 »

Arghh, apparently I getting blind - the order of arguments for cc is incorrect, try:

Code: Select all

cc bspwmxzoomrule.c -o bspwmxzoomrule -lxcb -lxcb-randr 
;)
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed

User avatar
Scorpion
Posts: 389
Joined: 2018-10-17 11:38
Has thanked: 5 times

Re: Cannot compile c program - D11

#5 Post by Scorpion »

Can you post the full command?

LE_746F6D617A7A69
Posts: 932
Joined: 2020-05-03 14:16
Has thanked: 7 times
Been thanked: 65 times

Re: Cannot compile c program - D11

#6 Post by LE_746F6D617A7A69 »

Scorpion wrote: 2022-12-06 20:51 Can you post the full command?
What do You mean by "full command"? -> the command from my previous post is correct - it correctly compiles Your example code, so .. ?
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed

User avatar
Scorpion
Posts: 389
Joined: 2018-10-17 11:38
Has thanked: 5 times

Re: Cannot compile c program - D11

#7 Post by Scorpion »

I thought that it was just a part of the code, I am not familiar with the commands to compile yet.
It works thanks.

Post Reply