compiling /usr/bin/ld undefined reference to XMapSubwindows and DSO missing from command line - c

I'm trying to compile my patched dwm on Debian.
This is my config.mk file, it's mostly the one from apt source dwm but the patches added some extra libraries, and I had to add the two -Ifreetype2 links myself:
# dwm version
VERSION = 6.1
# Customize below to fit your system
# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
# Xinerama, comment if you don't want it
XINERAMALIBS = -lXinerama
XINERAMAFLAGS = -DXINERAMA
# freetype
FREETYPELIBS = -lfontconfig -lXft
FREETYPEINC = /usr/include/freetype2
# OpenBSD (uncomment)
#FREETYPEINC = ${X11INC}/freetype2
# includes and libs
INCS = -I${X11INC} -I${FREETYPEINC} -I/usr/include/freetype2 -I/usr/include/libpng16
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender -lX11-xcb -lxcb -lxcb-res
# flags
CPPFLAGS += -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
#CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
CFLAGS += -std=c99 -pedantic -Wall -Wno-deprecated-declarations ${INCS} ${CPPFLAGS}
LDFLAGS += -s ${LIBS}
# Solaris
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
#LDFLAGS = ${LIBS}
# compiler and linker
CC = cc
This is the error I get when running make clean install
cc -o dwm drw.o dwm.o util.o -s -L -lX11 -lXinerama -lfontconfig -lXft -lXrender -lX11-xcb -lxcb -lxcb-res
/usr/bin/ld: dwm.o: undefined reference to symbol 'XMapSubwindows'
/usr/bin/ld: //lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [Makefile:29: dwm] Error 1
But I have no idea how to fix this. Do I need a library installed? do I need to add somthing to the libs variable? please help!
I have tried looking at this, but I have no idea what a "DSO" is, nor how to fix the linkage.

Not sure if it's the only problem but your link line...
cc -o dwm drw.o dwm.o util.o -s -L -lX11 -lXinerama -lfontconfig -lXft -lXrender -lX11-xcb -lxcb -lxcb-res
appears to have a -L option with no parameter. Or, perhaps more correctly, it will assume that its parameter is -lX11. I'm assuming this is because the variable X11LIB is unspecified in your makefile. Not sure exactly how X11LIB is supposed to be specified with the makefile you're using but you could try setting it explicitly...
X11LIB := /usr/lib64 # Assumes the path to libX11.so is /usr/lib64/libX11.so

-L -lX11
This means "add a directory named -lX11 to the library search path". This is unlikely to have any effect as such directory probably does nit exist.
Remove -L or add a non-empty directory argument after it.

Related

Why does the same command work differently in Makefile than it does when ran manually? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
here's my problem : for an assignement, I'm supposed to have a Makefile that compiles a program. Easy enough. However, it doesn't work.
Here's the Makefile :
SRCS = gnl/get_next_line.c \
$(wildcard parsing/*.c) \
$(wildcard libft/*.c) \
$(wildcard *.c) \
OBJS = ${SRCS:.c=.o}
FLAGS = -Wall -Wextra -Werror
NAME = cub3d
LIBS = -lX11 -lXext -std=gnu99 mlx/libmlx.a mlx/libmlx_Linux.a -lm
RM = rm -rf
all : ${NAME}
cub3d.a : ${OBJS}
ar rcs cub3d.a ${OBJS}
ranlib cub3d.a
$(NAME) : cub3d.a
gcc -o ${NAME} ${FLAGS} cub3d.c cub3d.a -I. -g ${LIBS}
When I run make, it returns a whole list of undefined references in libmlx.a. The source of my confusion is that when I just run
make cub3d.a && gcc -o cub3d -Wall -Wextra -Werror cub3d.c cub3d.a -I. -g -lX11 -lXext -std=gnu99 mlx/libmlx.a mlx/libmlx_Linux.a -lm
it works no problem.
To me it seems that the same exact line of command runs differently when executed through a Makefile than when ran manually. Why is that ? What am I doing wrong ?
EDIT : this is the command line run by the Makefile : gcc -o cub3d -Wall -Wextra -Werror cub3d.c cub3d.a -I. -g -lX11 -lXext -std=gnu99 mlx/libmlx.a mlx/libmlx_Linux.a -lm
Wildcarding in the shell is [may be] different from wildcard in make.
The shell will sort them but make may not [probably true because the makefile isn't working whereas the shell version is].
To see if that's the case do the following in both the shell and the makefile:
echo mlx/*.a
You probably have a symbol that is defined in (e.g.) y.a and referenced in x.a but the wildcard [in the makefile] produces the order: y.a x.a
The shell wildcard would produce the [sorted] order: x.a y.a, so the symbol would get resolved.
That's because the linker only scans the *.a in the order given it by the wildcard once.
So, for example, if the symbol in question was foo, the linker will scan y.a and see that foo is defined but is not needed/wanted [yet], so it will not include it.
The linker will, then, scan x.a and see that foo is wanted [a reference] and scan x.a and all remaining whatever.a but will not rescan y.a for it. Hence, foo is undefined [as far as the linker is concerned].
You may have more complex symbol interactions, so you probably want a "linker group" that forces all the *.a to be scanned/rescanned as a group. See man ld
So, you want:
ld ... --start-group mlx/*.a --end-group -lm ...
For gcc, this would be:
gcc ... -Wl,--start-group mlx/*.a -Wl,--end-group -lm ...
Note that I put -lm after the wildcard for your libraries. Although not your main issue, that will help a bit.

Native and cross compile using GNU make, embedded C

I'm working on a Makefile to make me able to native and cross-compile. choosing wether to compile for host linux or ti MSP432 should be done from command line:
$ make build PLATFORM=MSP432
$ make build PLATFORM=HOST
here's my Makefile that I tried to do it in:
include sources.mk
ifeq ($(PLATFORM),MSP432)
# Platform Overrides
# Architectures Specific Flags
LINKER_FILE = msp432p401r.lds
CPU = cortex-m4
ARCH = thumb
SPECS = nosys.specs
# Compiler Flags and Defines
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
endif
ifeq ($(PLATFORM),HOST)
CC = gcc
endif
TARGET = c1m1
LDFLAGS = -Wl,-Map=$(TARGET).map -T $(LINKER_FILE)
CFLAGS = -mcpu=$(CPU) -m$(ARCH) --specs=$(SPECS) -Wall -Werror -g -O0
-std=c99
CPPFLAGs =
.PHONY: build
build: $(TARGET).out
.PHONY: clean
clean:
rm -f $(OBJS) $(TARGET).out $(TARGET).map
%.o : %.c
$(CC) -c $< $(CFLAGS) -o $#
OBJS = $(SOURCES:.c=.o)
$(TARGET).out: $(OBJS)
$(CC) $(OBJS) $(CFLAGS) $(LDFLAGS) -o $#
is this the right way to do that?
there's also another weird error happening when I compile using:
$ make main.o PLATFORM=MSP432
I get this error:
arm-none-eabi-gcc -c main.c -mcpu=cortex-m4 -mthumb --
specs=nosys.specs -Wall -Werror -g -O0 -std=c99 -o main.o
main.c:23:22: fatal error: platform.h: No such file or directory
#include "platform.h"
^
compilation terminated.
Makefile:64: recipe for target 'main.o' failed
make: *** [main.o] Error 1
and when I compile using this:
$ make main.o PLATFORM=HOST
I get this error, they are 2 different errors and I can't understand the reason behind this.
gcc -c main.c -mcpu= -m --specs= -Wall -Werror -g -O0 -std=c99 -o
main.o
gcc: warning: ‘-mcpu=’ is deprecated; use ‘-mtune=’ or ‘-march=’
instead
gcc: error: missing argument to ‘-mcpu=’
gcc: error: missing argument to ‘--specs=’
gcc: error: unrecognized command line option ‘-m’
Makefile:64: recipe for target 'main.o' failed
make: *** [main.o] Error 1
I posted those apparently different questions in 1 question, because I think they are affecting eachother.
this is also another headerfile that is called platform.h that has some conditionals to include some directives, which after the answer I think might be needed for compile time switches
#ifndef __PLATFORM_H__
#define __PLATFORM_H__
#if defined (MSP432)
#include "msp432p401r.h"
#define PRINTF(...)
#elif defined (HOST)
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#else
#error "Platform provided is not supported in this Build System"
#endif
#endif /* __PLATFORM_H__ */
First, I will answer the case when PLATFORM and HOST are the same:
$ make main.o PLATFORM=HOST
I get this error, they are 2 different errors and I can't understand the reason behind this.
gcc -c main.c -mcpu= -m --specs= -Wall -Werror -g -O0 -std=c99 -o
main.o
gcc: warning: ‘-mcpu=’ is deprecated; use ‘-mtune=’ or ‘-march=’
instead
gcc: error: missing argument to ‘-mcpu=’
gcc: error: missing argument to ‘--specs=’
gcc: error: unrecognized command line option ‘-m’
Makefile:64: recipe for target 'main.o' failed
make: *** [main.o] Error 1
This is due to your makefile: CPU, ARCH and SPECS are only set when
PLATFORM is MSP432
So the line CFLAGS = -mcpu=$(CPU) -m$(ARCH) --specs=$(SPECS) -Wall -Werror -g -O0 -std=c99
is evalued as CFLAGS = -mcpu= -m --specs= -Wall -Werror -g -O0 -std=c99
When gcc is invoked with CFLAGS as argument, which is incorrect.
To correct this, you can make theses little changes in your makefile:
include sources.mk
ifeq ($(PLATFORM),MSP432)
# Platform Overrides
# Architectures Specific Flags
LINKER_FILE = msp432p401r.lds
CPU = cortex-m4
ARCH = thumb
SPECS = nosys.specs
LDFLAGS_ARCH = -T $(LINKER_FILE)
CFLAGS_ARCH = -mcpu=$(CPU) -m$(ARCH) --specs=$(SPECS)
# Compiler Flags and Defines
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
endif
ifeq ($(PLATFORM),HOST)
CC = gcc
endif
TARGET = c1m1
LDFLAGS = -Wl,-Map=$(TARGET).map $(LDFLAGS_ARCH)
CFLAGS = $(CFLAGS_ARCH) -Wall -Werror -g -O0
-std=c99
CPPFLAGs =
Now, for the main.c:23:22: fatal error: platform.h: No such file or directory
You have to find where this file is locatted and eventually add it as a gcc option.
For instance, if the file platform.h is in /some/directory, you can add this
option to gcc to help it to find it:
-I/some/directory
So in makefile, you can have this line:
CFLAGS_ARCH = -mcpu=$(CPU) -m$(ARCH) --specs=$(SPECS) -I/some/directory
EDIT
In comments, you add this problem for your question:
that solved it the errors are consistent now, and here it is
In file included from main.c:23:0: ./include/common/platform.h:30:2: error:
#error "Platform provided is not supported in this Build System" #error "... *** [main.o] Error 1
Regarding the platform.h file, macro MSP432 or HOST must be defined in order to run.
To define such macro, the -D option must be passed to gcc.
So the idea is to add some line to the makefile to define MSP432 or HOST when necessary:
...
ifeq ($(PLATFORM),MSP432)
# Platform Overrides
# Architectures Specific Flags
LINKER_FILE = msp432p401r.lds
CPU = cortex-m4
ARCH = thumb
SPECS = nosys.specs
LDFLAGS_ARCH = -T $(LINKER_FILE)
CFLAGS_ARCH = -mcpu=$(CPU) -m$(ARCH) --specs=$(SPECS) -DMSP432
# Compiler Flags and Defines
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
endif
ifeq ($(PLATFORM),HOST)
CFLAGS_ARCH = -DHOST
CC = gcc
endif
...

error linking to LibPng library

I am having trouble linking to the libpng library.
The build seems unable to define references to Libpng calls.
I think the problem is in my Libpng install.
I am runing in the Mingw environment on a Win7 laptop
My build environment is as follows:
My path starts with C:\MinGW\bin;C:\MinGW\msys\1.0\bin;C:\MinGW\git\cmd;C:\Program Files
C:\Users\Bob\Home\png23d>g++ --version
g++ (GCC) 5.3.0
I have built and installed libpng-1.6.28 which creates the following:
C:\MinGW\bin>
libpng-config
libpng16-config
libpng16.dll
C:\MinGW\include\libpng
png.h
pngconf.h
pnglibconf.h
C:\MinGW\include\libpng16
png.h
pngconf.h
pnglibconf.h
C:\MinGW\lib\pkgconfig
C:\MinGW\lib>
libpng.a
libpng.dll.a
libpng16.a
libpng16.dll.a
a symbolic link `libpng' to `libpng16'
a symbolic link `libpng.pc' to `libpng16.pc'
a symbolic link `libpng.a' to `libpng16.a'
a symbolic link `libpng-config' to `libpng16-config
when I try to build a program "png23d" I get the following
C:\Users\Bob\Home\png23d>make
g++ -DUSE_LIBPNG -lpng png23d.o option.o bitmap.o mesh.o mesh_gen.o mesh_index.o mesh_simplify.o out_pgm.o out_rscad.o out_pscad.o out_stl.o -o png23d
bitmap.o:bitmap.c:(.text+0x102): undefined reference to `png_sig_cmp'
bitmap.o:bitmap.c:(.text+0x142): undefined reference to `png_create_read_struct'
.
.
.
bitmap.o:bitmap.c:(.text+0x418): undefined reference to `png_read_end'
bitmap.o:bitmap.c:(.text+0x466): undefined reference to `png_destroy_read_struct'
collect2.exe: error: ld returned 1 exit status
<builtin>: recipe for target 'png23d' failed
make: *** [png23d] Error 1
I am almost sure its the -lpng that is not working.... I am just don't know how to fix it.
I am guessing that it is a symbolic link problem and I know I did not create one during the libpng build.
If I am right what do I need to link it to.
I tried changing -lpng to -llpng16. It made no difference.
Thanks from the command prompt that work fine.
just have to figure out how to change the make file.
#!/usr/bin/make
#
# png23d is a program to convert png images into 3d files
#
# Copyright 2011 Vincent Sanders <vince#kyllikki.org>
#
# Released under the MIT License,
# http://www.opensource.org/licenses/mit-license.php
CC = g++
VERSION=100
PREFIX =
WARNFLAGS = -W -Wall -Wundef -Wpointer-arith \
-Wcast-align -Wwrite-strings -Wstrict-prototypes \
-Wmissing-prototypes -Wmissing-declarations -Wredundant-decls \
-Wnested-externs
ifneq ($(GCCVER),2)
WARNFLAGS += -Wno-unused-parameter
endif
OPTFLAGS=-O2
#OPTFLAGS=-O0
CFLAGS+=$(WARNFLAGS) -MMD -DVERSION=$(VERSION) $(OPTFLAGS) -g
LDFLAGS+= -DUSE_LIBPNG -lpng
PNG23D_OBJ=png23d.o option.o bitmap.o mesh.o mesh_gen.o mesh_index.o mesh_simplify.o out_pgm.o out_rscad.o out_pscad.o out_stl.o
.PHONY : all clean
all:png23d
png23d:$(PNG23D_OBJ)
-include $(PNG23D_OBJ:.o=.d)
-include test/Makefile.sub
clean: testclean
${RM} png23d $(PNG23D_OBJ) *.d *~ png23d.png
install:png23d
install -D png23d $(DESTDIR)$(PREFIX)/bin
install-man:png23d.1
install -D png23d.1 $(DESTDIR)$(PREFIX)/share/man/man1
# logo creation
png23d.png:png23d.pov
povray +L/usr/share/povray/include/ -D +Q11 +O$# +UV +UL +A0.2 +FP8 +W400 +H300 $<
Move -lpng to after the object files.

CentOS 6.5, mod_wsgi, Apache Cannot load mod_wsgi.so into server, undefined symbol: PyExc_StopIteration

The problem:
I can't start apache server with mod_wsgi. apachectl -t says:
httpd: Syntax error on line 202 of /etc/httpd/conf/httpd.conf: Cannot load /etc/httpd/modules/mod_wsgi.so into server: /etc/httpd/modules/mod_wsgi.so: undefined symbol: PyExc_StopIteration
Here's what I got so far:
Server version: Apache/2.2.15 (Unix)
Python 3.3.5
mod_wsgi-3.4 (latest)
python compilation:
wget http://python.org/ftp/python/3.3.5/Python-3.3.5.tar.xz
tar xf Python-3.3.5.tar.xz
cd Python-3.3.5
./configure --prefix=/usr/local --enable-shared --with-threads
make && make altinstall
mod_wsgi compilation:
./configure --with-python=/usr/local/bin/python3.3
checking for apxs2... no
checking for apxs... /usr/sbin/apxs
checking Apache version... 2.2.15
configure: creating ./config.status
config.status: creating Makefile
then I edit Makefile - replace:
LDLIBS = -lpython3.3 -lpthread -ldl -lutil -lm
with
LDLIBS = -python3.3 -lpthread -ldl -lutil -lm
(sorry, I can't remember where I've read this, but it helps me last time I sucessfully install mod_wsgi on same system configuration)
make
---plenty of warnings---
make install
SOLUTION:
since I can't answer my own question "till 8 reputation", I gonna edit my own post.
Being familiar with compilation process not too much, I've started looking into parameters... and there were no folder "/usr/local/lib/python3.3/config"! With a wild guess, I made next changes to generated Makefile, and now it works!
< LDFLAGS = -L/usr/local/lib -L/usr/local/lib/python3.3/config
< LDLIBS = -lpython3.3 -lpthread -ldl -lutil -lm
------------
> LDFLAGS = -L/usr/local/lib -L/usr/local/lib/python3.3/config-3.3m
> LDLIBS = -lpython3.3m -lpthread -ldl -lutil -lm
Being familiar with compilation process not too much, I've started looking into parameters... and there were no folder "/usr/local/lib/python3.3/config"! With a wild guess, I made next changes to generated Makefile, and now it works!
< LDFLAGS = -L/usr/local/lib -L/usr/local/lib/python3.3/config
< LDLIBS = -lpython3.3 -lpthread -ldl -lutil -lm
------------
> LDFLAGS = -L/usr/local/lib -L/usr/local/lib/python3.3/config-3.3m
> LDLIBS = -lpython3.3m -lpthread -ldl -lutil -lm

CS107 Assignment file couldn't compile, missing expat.h and thread_107.h files

I was auditing cs107 at stanford online
The problem I ran into is with assignment 6, when I type "make" in terminal, the error message pops up. Basically, I miss two header files, which I guess can be got from the pre-compiled .lib file. But somehow it just doesn't work.
Here's part of the original make file:
CFLAGS = -D_REENTRANT -g -Wall -D__ostype_is_$(OSTYPE)__ -std=gnu99 -I/usr/class/cs107/include/ -Wno-unused-function $(DFLAG)
LDFLAGS = -L/usr/class/cs107/assignments/assn-6-rss-news-search-lib/$(OSTYPE) -L/usr/class/cs107/lib -lexpat -lrssnews $(PLATFORM_LIBS) $(THREAD_LIBS)
PFLAGS= -linker=/usr/pubsw/bin/ld -best-effort -threads=yes -max-threads=1000
Edit:
When I said "This is supposed to compile even without threading implementation", I meant that it should compile without FURTHER threading implementation by students.
So here's the error message with thread:
gcc -D_REENTRANT -g -Wall -D__ostype_is_linux__ -std=gnu99 -I/usr/class/cs107/include/ -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
rss-news-search.c: In function ‘main’:
rss-news-search.c:109:3: warning: implicit declaration of function ‘InitThreadPackage’ [-Wimplicit-function-declaration]
gcc rss-news-search.o -D_REENTRANT -g -Wall -D__ostype_is_linux__ -std=gnu99 -I/usr/class/cs107/include/ -Wno-unused-function -L/home/h/cs107/assn-6-rss-news-search-lib/linux -L/usr/class/cs107/lib -L. -lexpat -lrssnews -lnsl -lpthread -lthread_107_linux -o rss-news-search
/usr/bin/ld: cannot find -lthread_107_linux
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1
here's the error message without $(THREAD_LIBS):
gcc -D_REENTRANT -g -Wall -D__ostype_is_linux__ -std=gnu99 -I/usr/class/cs107/include/ -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
rss-news-search.c: In function ‘main’:
rss-news-search.c:109:3: warning: implicit declaration of function ‘InitThreadPackage’ [-Wimplicit-function-declaration]
gcc rss-news-search.o -D_REENTRANT -g -Wall -D__ostype_is_linux__ -std=gnu99 -I/usr/class/cs107/include/ -Wno-unused-function -L/home/h/cs107/assn-6-rss-news-search-lib/linux -L/usr/class/cs107/lib -L. -lexpat -lrssnews -lnsl -lpthread -o rss-news-search
rss-news-search.o: In function `main':
/home/h/cs107/assn-6-rss-news-search/rss-news-search.c:109: undefined reference to `InitThreadPackage'
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1
In the later case, if I comment out "InitThreadPackage", it compiles just fine.
This is the procedure to compile your project:
Create a file assn-6-rss-news-search/thread_107.h, and put this inside:
/* Empty header file */
Copy the library librssnews.a from assn-6-rss-news-search-lib/linux/ to assn-6-rss-news-search/
Modify the file rss-news-search.c by commenting the call to the function : InitThreadPackage on line 109:
//InitThreadPackage(false);
Modify the Makefile to include the path to the current directory (to be able to link to the library you've copied earlier librssnews.a):
The line 27 should look like this:
LDFLAGS = -L/usr/class/cs107/assignments/assn-6-rss-news-search-lib/$(OSTYPE) -L/usr/class/cs107/lib -L. -lexpat -lrssnews $(PLATFORM_LIBS) $(THREAD_LIBS)
Then:
make clean
make
EDIT :
When you got this error cannot find lthread_107_linux, Edit your Makefile to remove this $(THREAD_LIBS) on line 27:
LDFLAGS = -L/usr/class/cs107/assignments/assn-6-rss-news-search-lib/$(OSTYPE) -L/usr/class/cs107/lib -L. -lexpat -lrssnews $(PLATFORM_LIBS)
The class-specific header files, like thread_107.h are found in /usr/class/cs107/include/ on whatever machine the instructor is expecting the students to use. If you're not using that machine, you'll have to copy those include files or make your own.
The expat.h file is from an open source library. You'll need to install the appropriate package on the system you're compiling on. On Ubuntu, that's sudo apt-get install libexpat1-dev, but the package name should be similar on other distributions.

Resources