Good evening! In general, I will describe the situation: There is a set of .c and .h files. There is a makefile script. However, when trying to execute "make", the following list of messages appears in the terminal:

jack@jack:~/debug_tools$ make cc -fshort-enums -Wno-unused-result -lX11 -lm -pthread -ggdb -O0 -Wall -MD -MP -MF .dep/ui.od -c -o ui.o ui.c cc -fshort-enums -Wno-unused-result -lX11 -lm -pthread -ggdb -O0 -Wall -MD -MP -MF .dep/protocol.od -c -o protocol.o protocol.c cc -fshort-enums -Wno-unused-result -lX11 -lm -pthread -ggdb -O0 -Wall -MD -MP -MF .dep/graph.od -c -o graph.o graph.c cc -fshort-enums -Wno-unused-result -lX11 -lm -pthread -ggdb -O0 -Wall -MD -MP -MF .dep/gps.od -c -o gps.o gps.c cc -fshort-enums -Wno-unused-result -lX11 -lm -pthread -ggdb -O0 -Wall -MD -MP -MF .dep/ui.d ui.o fix.o protocol.o graph.o gps.o gnuplot_i.o -o ui graph.o: In function 'graph_draw': /home/jack/debug_tools/graph.c:53: undefined reference to 'XSetForeground' /home/jack/debug_tools/graph.c:56: undefined reference to 'XDrawLine' graph.o: In function 'path_draw_point': /home/jack/debug_tools/graph.c:90: undefined reference to 'cos' /home/jack/debug_tools/graph.c:91: undefined reference to 'sin' graph.o: In function 'ui_func': /home/jack/debug_tools/graph.c:242: undefined reference to 'XFlush' graph.o: In function 'process_events': /home/jack/debug_tools/graph.c:256: undefined reference to 'XPending' /home/jack/debug_tools/graph.c:258: undefined reference to 'XNextEvent' /home/jack/debug_tools/graph.c:261: undefined reference to 'XKeycodeToKeysym' graph.o: In function 'ui_init': /home/jack/debug_tools/graph.c:383: undefined reference to 'XOpenDisplay' /home/jack/debug_tools/graph.c:384: undefined reference to 'XDisplayName' /home/jack/debug_tools/graph.c:391: undefined reference to 'XCreateSimpleWindow' /home/jack/debug_tools/graph.c:395: undefined reference to 'XSetStandardProperties' /home/jack/debug_tools/graph.c:397: undefined reference to 'XCreateGC' /home/jack/debug_tools/graph.c:398: undefined reference to 'XSetBackground' /home/jack/debug_tools/graph.c:399: undefined reference to 'XSetForeground' /home/jack/debug_tools/graph.c:401: undefined reference to 'XSelectInput' /home/jack/debug_tools/graph.c:403: undefined reference to 'XMapRaised' /home/jack/debug_tools/graph.c:405: undefined reference to 'XClearWindow' /home/jack/debug_tools/graph.c:406: undefined reference to 'XSync' graph.o: In function 'showtext': /home/jack/debug_tools/graph.c:445: undefined reference to 'XSetForeground' /home/jack/debug_tools/graph.c:450: undefined reference to 'XDrawImageString' graph.o: In function 'clear_wnd': /home/jack/debug_tools/graph.c:454: undefined reference to 'XSetForeground' /home/jack/debug_tools/graph.c:455: undefined reference to 'XFillRectangle' /home/jack/debug_tools/graph.c:456: undefined reference to 'XSetForeground' /home/jack/debug_tools/graph.c:458: undefined reference to 'XDrawLine' /home/jack/debug_tools/graph.c:463: undefined reference to 'XDrawLine' /home/jack/debug_tools/graph.c:468: undefined reference to 'XDrawLine' /home/jack/debug_tools/graph.c:472: undefined reference to 'XDrawLine' graph.o: In function 'setstat': /home/jack/debug_tools/graph.c:480: undefined reference to 'XSetForeground' /home/jack/debug_tools/graph.c:481: undefined reference to 'XFillRectangle' collect2: выполнение ld завершилось с кодом возврата 1 make: *** [ui] Ошибка 1 jack@jack:~/debug_tools$

The fact is that programming with Linux has not come across before. All raws were written by another person who disappeared without a trace. In the end, I'm stuck on these errors here. Question: which way to dig and what to do with them (I mean "undefined reference to")?

Added from comment .

Here is the content of the makefile:

 CFLAGS += -fshort-enums -Wno-unused-result -lX11 -lm -pthread -ggdb -O0 -Wall LDFLAGS = ${CFLAGS} all: ui calib_edit uart_9bit ui: ui.o fix.o protocol.o graph.o gps.o gnuplot_i.o calib_edit: calib_edit.o protocol.o uart_9bit: uart_9bit.o DEPDIR = .dep CFLAGS += -MD -MP -MF $(DEPDIR)/$( @F ).d -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) .PHONY: clean clean: rm -f *.o rm -rf .dep rm -f ui calib_edit uart_9bit 

uart_9bit and calib_edit are collected without problems, but ui in any way. make clean does nothing.

  • try compiling it yourself - sudo97
  • thanks for the advice. but, alas, did not help. the same effect. - Johnny_Stray
  • Strange. The keys -lX11 -lm cost, and the functions of them (mostly X11, but sin / cos - libm) are not connected. Do you start with make clean (if, of course, this is in your Makefile)? - alexlz
  • Moved to the question. - Johnny_Stray

2 answers 2

more of the common tricks: try adding the -v option to CFLAGS; then gcc will write a list of directories for searching for libraries and libraries. It may be worth walking through these directories, to see what lies there.

  • thanks for the advice. I will try) - Johnny_Stray

Check in the graph.c file if math.h and Xlib.h are included

  • math.h is included in the graph.c file, and Xlib.h in the graph.h file is included in Johnny_Stray
  • one
    And with? Ld swears, and on names which in X11. @Johnny_Stray package libx11-dev, of course, installed? - alexlz
  • libx11-dev is installed. while trying to overcome mistakes, in general everything that could have been set. - Johnny_Stray
  • one
    From shamanism: add gcc -fshort-enums -Wno-unused-result -lX11 -lm -pthread -ggdb -O0 -Wall -MD -MP -MF .dep/ui.d ui.o fix.o protocol.o graph.o gps.o gnuplot_i.o -ou in the tail -lX11 -m (second time) and see if something changes? (it will not eliminate mistakes, but suddenly the picture will be different) - alexlz
  • one
    Rave. I'm going with libm.so (libm-2.11.1.so) and libX11.so. Try replacing -lX11 -m with -l: libX11.so -l: libm.so. My result is the same. There is naturally nothing on the port, but ./ui --help displays a window :) Well, locate libX11.so. I'm afraid that something in the system is tricked with the settings, so ld gets confused. - alexlz