OBS build does not find pcre library references

I am building a simple tool to be used in openSUSE Leap 15.4. It’s build via OBS as a rpm package.

Locally it works fine, but when build via OBS the linker cannot resolv the pcre library. I’ve tried to change the compiler. Found out about my working local build which PCRE library was chosen exactly, tried a different library and even checked via objdump if the missing pcre_compile symbol is available in the libpcre1.so (it is). I’ve changed the compiler from gcc-7 to gcc-11.

This is the error on a OBS build for openSUSE Leap 15.4:

[    3s] gcc-11 -O2 -D_GNU_SOURCE -DNDEBUG -c -Wall -o built.o built.c
[    3s] gcc-11 -Wall -lpcre -o tck104328 tck104328.o manageblocklist.o built.o
[    3s] /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: tck104328.o: in function `main':
[    3s] tck104328.c:(.text.startup+0xa1): undefined reference to `pcre_compile'
[    3s] /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: tck104328.c:(.text.startup+0x201): undefined reference to `pcre_exec'
[    3s] /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: tck104328.c:(.text.startup+0x232): undefined reference to `pcre_copy_substring'
[    3s] /usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: tck104328.c:(.text.startup+0x258): undefined reference to `pcre_copy_substring'
[    3s] collect2: error: ld returned 1 exit status

this is the according rpm package:

Name: tck104328
Version: 1.0.0
Release: 1
License: GPL-3.0
Summary: Some tool
Group: System/Tools
Source: %{name}-%{version}-%{release}.tar.gz
BuildRequires: make
BuildRequires: gcc11
BuildRequires: pcre-devel
BuildRequires: libpcre1
BuildRequires: hostname
Requires: libpcre1
BuildRoot: %{_tmppath}/%{name}-%{version}-build

some text

%autosetup -n tck104328


mkdir -p %{buildroot}/usr/bin/
install -m 755 %{name} %{buildroot}/usr/bin/%{name}

Now I am out of ideas. Hopefully anyone here can hint me on some path.

You forgot to post link to your project.

Library reference must come after object modules using this library.

This could be a possibility, indeed. Didn’t came to my mind as the makefile works locally - but not in OBS. Will try that soon (im on travel atm).

Despite working on so many other machines, this tipp was exactly right. It works in OBS now. Thank you @arvidjaar!