blugon icon indicating copy to clipboard operation
blugon copied to clipboard

undefined reference to `XOpenDisplay'

Open varkey98 opened this issue 5 years ago • 2 comments

Whenever I run the make file in the directory, I am encountering this issue : undefined reference to `XOpenDisplay' for the file scg.c. I tried manually linking lX11, still the issue persists. I am running Ubuntu 20.04.

varkey98 avatar Oct 11 '20 11:10 varkey98

(Python3.6) appleyuchi@Desktop:~/桌面/護眼軟件/blugon$ make
sed "s|MAKE_INSTALL_PREFIX = '.*'|MAKE_INSTALL_PREFIX = '/usr'|g" blugon.py > blugon
sed "s|MAKE_INSTALL_PREFIX|/usr|g" systemd/user/blugon.service > blugon.service
gzip --best --force --keep blugon.1
cd backends/scg && make build
make[1]: Entering directory '/home/appleyuchi/桌面/護眼軟件/blugon/backends/scg'
cc -O2 -std=c11 -D_POSIX_C_SOURCE=200809L -Wall -Wextra -Wpedantic -I/usr/X11R6/include -L/usr/X11R6/lib -lX11 -lXrandr -o scg scg.c
/usr/bin/ld: /tmp/cczPlEGM.o: in function `main':
scg.c:(.text.startup+0x4e): undefined reference to `XOpenDisplay'
/usr/bin/ld: scg.c:(.text.startup+0x64): undefined reference to `XDefaultRootWindow'
/usr/bin/ld: scg.c:(.text.startup+0x6f): undefined reference to `XRRGetScreenResourcesCurrent'
/usr/bin/ld: scg.c:(.text.startup+0xb9): undefined reference to `XRRGetCrtcGammaSize'
/usr/bin/ld: scg.c:(.text.startup+0xc3): undefined reference to `XRRAllocGamma'
/usr/bin/ld: scg.c:(.text.startup+0x171): undefined reference to `XRRSetCrtcGamma'
/usr/bin/ld: scg.c:(.text.startup+0x179): undefined reference to `XRRFreeGamma'
/usr/bin/ld: scg.c:(.text.startup+0x19c): undefined reference to `XRRFreeScreenResources'
/usr/bin/ld: scg.c:(.text.startup+0x1a4): undefined reference to `XCloseDisplay'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:7: build] Error 1
make[1]: Leaving directory '/home/appleyuchi/桌面/護眼軟件/blugon/backends/scg'
make: *** [Makefile:8: build] Error 2

appleyuchi avatar Jan 06 '21 02:01 appleyuchi

@appleyuchi

From 5813099030eadd442ee431ad456451cfb2b47f81 Mon Sep 17 00:00:00 2001
From: Emil Hammarstrom <[email protected]>
Date: Tue, 8 Jun 2021 22:17:48 +0200
Subject: [PATCH] scg: move linker flags

link libs after scg such that ld may resolve undefined symbols

Signed-off-by: Emil Hammarstrom <[email protected]>
---
 backends/scg/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/backends/scg/Makefile b/backends/scg/Makefile
index 01c9c2e..d032937 100644
--- a/backends/scg/Makefile
+++ b/backends/scg/Makefile
@@ -4,7 +4,7 @@ LDFLAGS = -L/usr/X11R6/lib
 LDLIBS = -lX11 -lXrandr
 
 build:
-	$(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o scg scg.c
+	$(CC) $(CFLAGS) $(LDFLAGS) -o scg scg.c $(LDLIBS)
 
 clean:
 	rm -f scg
-- 
2.30.2

eHammarstrom avatar Jun 08 '21 20:06 eHammarstrom