Closed halkeye closed 10 years ago
The invocation in the makefile is:
$(EXECUTABLE): $(OBJECTS)
$(CC) $(shell pkg-config --libs x11) -o $@ $^ $(CFLAGS)
I would really suspect that -lX11
is included in --libs x11
. What does it print out for you?
[ 2:41PM ] [ halkeye@barkdog:~/git/hhpc(master✗) ]
$ pkg-config --libs x11
-lX11
$ make
cc -c hhpc.c -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
cc -lX11 -o hhpc hhpc.o -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
hhpc.o: In function `waitForMotion':
hhpc.c:(.text+0xd1): undefined reference to `XCreateBitmapFromData'
hhpc.c:(.text+0xf2): undefined reference to `XCreatePixmapCursor'
hhpc.c:(.text+0x100): undefined reference to `XFreePixmap'
hhpc.c:(.text+0x204): undefined reference to `XGrabPointer'
hhpc.c:(.text+0x23e): undefined reference to `XUngrabPointer'
hhpc.c:(.text+0x249): undefined reference to `XFreeCursor'
hhpc.c:(.text+0x2d9): undefined reference to `XAllowEvents'
hhpc.c:(.text+0x2e3): undefined reference to `XSync'
hhpc.c:(.text+0x340): undefined reference to `XAllowEvents'
hhpc.c:(.text+0x34a): undefined reference to `XUngrabPointer'
hhpc.c:(.text+0x361): undefined reference to `XMaskEvent'
hhpc.c:(.text+0x373): undefined reference to `XPending'
hhpc.o: In function `main':
hhpc.c:(.text.startup+0x85): undefined reference to `XOpenDisplay'
hhpc.c:(.text.startup+0xc7): undefined reference to `XCloseDisplay'
collect2: error: ld returned 1 exit status
make: *** [hhpc] Error 1
After adding it to CFLAGS_COMMON
$ make
cc -lX11 -o hhpc hhpc.o -lX11 -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
So adding it twice fixes it for you? Or is it because it's added in front of the -o
? I didn't know those arguments were positional.
Does it work if you just use this target?
$(EXECUTABLE): $(OBJECTS)
$(CC) -o $@ $^ $(shell pkg-config --libs x11) $(CFLAGS)
(I just moved the pkg-config
incantation more to the end).
Looks happy to me. Maybe cc suddenly started to care?
$ cc --version
cc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ make clean
rm -f hhpc hhpc.o
[ 10:54AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$ make
cc -c hhpc.c -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
cc -o hhpc hhpc.o -lX11 -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
Looks happy to me. Maybe cc suddenly started to care?
While possible, it seems strange. I know some arch linux users have been using hhpc
over the past year and they've been on gcc 4.8 and now gcc 4.9 for quite some time.
Anyway, I'll make this change quickly so you can continue compiling it without worries :).
Hmm, I tried verifying the change on a system I have here before committing, and I can't for the life of me understand what's going wrong.
Can you verify that doing this doesn't work:
$ make clean
$ cc -c hhpc.c -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
$ cc -lX11 -o hhpc hhpc.o -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
And this does:
$ make clean
$ cc -c hhpc.c -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
$ cc -o hhpc hhpc.o -lX11 -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
With your system as it is right now?
For my part, I'm going to use linuxbrew to install gcc 4.8.2 and try to reproduce what you're seeing.
8:00AM ] [ halkeye@barkdog:~(ruby-2.0.0-p353) ]
$ cd git/hhpc/
[ 8:00AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$ make clean
rm -f hhpc hhpc.o
[ 8:00AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$ cc -c hhpc.c -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
[ 8:00AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$ cc -lX11 -o hhpc hhpc.o -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
hhpc.o: In function `waitForMotion':
hhpc.c:(.text+0xd1): undefined reference to `XCreateBitmapFromData'
hhpc.c:(.text+0xf2): undefined reference to `XCreatePixmapCursor'
hhpc.c:(.text+0x100): undefined reference to `XFreePixmap'
hhpc.c:(.text+0x204): undefined reference to `XGrabPointer'
hhpc.c:(.text+0x23e): undefined reference to `XUngrabPointer'
hhpc.c:(.text+0x249): undefined reference to `XFreeCursor'
hhpc.c:(.text+0x2d9): undefined reference to `XAllowEvents'
hhpc.c:(.text+0x2e3): undefined reference to `XSync'
hhpc.c:(.text+0x340): undefined reference to `XAllowEvents'
hhpc.c:(.text+0x34a): undefined reference to `XUngrabPointer'
hhpc.c:(.text+0x361): undefined reference to `XMaskEvent'
hhpc.c:(.text+0x373): undefined reference to `XPending'
hhpc.o: In function `main':
hhpc.c:(.text.startup+0x85): undefined reference to `XOpenDisplay'
hhpc.c:(.text.startup+0xc7): undefined reference to `XCloseDisplay'
collect2: error: ld returned 1 exit status
[ 8:00AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$ make clean
rm -f hhpc hhpc.o
[ 8:00AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$ cc -c hhpc.c -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
[ 8:01AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$ cc -c hhpc.c -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
[ 8:01AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$
Verified.
If i'm reading that right (and its early) then skippnig the lib line allows it to work?
Verified.
Alright, there does seem to be some issue. I can't reproduce it because my debian system is having trouble compiling a more recent gcc than 4.7.1.
If i'm reading that right (and its early) then skippnig the lib line allows it to work?
Which line exactly do you mean? In your last paste, you're not creating the executable as far as I can see:
[ 8:00AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$ cc -c hhpc.c -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
[ 8:01AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$ cc -c hhpc.c -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
<--- this seems to be the same line twice.
heh. Sorry. Thats what I get trying to do this before I'm awake / have glasses on.
[ 8:29AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$ make clean
rm -f hhpc hhpc.o
[ 8:29AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$ cc -c hhpc.c -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
[ 8:29AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$ cc -o hhpc hhpc.o -lX11 -D_XOPEN_SOURCE -D_POSIX_C_SOURCE=200809L -pedantic -std=c99 -s -O2 -DNDEBUG
[ 8:30AM ] [ halkeye@barkdog:~/git/hhpc(master✗)(ruby-2.0.0-p353) ]
$
I hope this fixes the issue :).
Needs -lX11 included on CFLAGS_COMMON
Do you want a patch for this? I don't know how portable it is, could also use pkg-config