Missing -fPIC leads to the build failure: ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
ld: error: relocation R_X86_64_PC32 cannot be used against symbol '__stack_chk_guard'; recompile with -fPIC
>>> defined in /lib/libc.so.7
>>> referenced by ceed-identity.c
>>> build/gallery/identity/ceed-identity.o:(CeedQFunctionInit_Identity)
ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in build/interface/ceed-basis.o
>>> referenced by ceed-basis.c
>>> build/interface/ceed-basis.o:(CeedBasisGetCollocatedGrad)
ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in build/gallery/ceed-gallery-weak.o
>>> referenced by ceed-gallery-weak.c
>>> build/gallery/ceed-gallery-weak.o:(.text+0x3E)
FreeBSD 14.1
Could you use make V=1 or make print-CFLAGS and also make print-CC_VENDOR? I suspect we are not correctly identifying vendor for your default C compiler and thus CFLAGS is not getting a suitable default. You can see in the makefile that -fPIC should be added unless STATIC is defined. You can always make CFLAGS='-fPIC -O -march=generic -MMD -MP' manually to supplant the vendor defaults.
With V=1 it prints this:
make: 'lib' with optional backends:
cc -I./include -DUNDERSCORE -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -c -o build/interface/ceed-fortran.o /usr/ports/math/libceed/work/libCEED-0.12.0-763-ge3ae47f6/interface/ceed-fortran.c
cc -I./include -DCEED_JIT_SOURCE_ROOT_DEFAULT="\"/usr/local/include/\"" -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -c -o build/interface/ceed-jit-source-root-install.o /usr/ports/math/libceed/work/libCEED-0.12.0-763-ge3ae47f6/interface/ceed-jit-source-root-install.c
cc -I./include -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -c -o build/interface/ceed-jit-tools.o /usr/ports/math/libceed/work/libCEED-0.12.0-763-ge3ae47f6/interface/ceed-jit-tools.c
cc -I./include -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -c -o build/interface/ceed-operator.o /usr/ports/math/libceed/work/libCEED-0.12.0-763-ge3ae47f6/interface/ceed-operator.c
cc -I./include -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -c -o build/interface/ceed-preconditioning.o /usr/ports/math/libceed/work/libCEED-0.12.0-763-ge3ae47f6/interface/ceed-preconditioning.c
...
...
Uh, the output you first pasted had the -fPIC, but then you edited to remove it. What is the difference between those two outputs? Please check the other suggestions in my last comment.
Uh, the output you first pasted had the -fPIC, but then you edited to remove it. What is the difference between those two outputs? Please check the other suggestions in my last comment.
Sorry, the first one was the patched up version to have -fPIC in the port in order to build it. The edited version is what is being used by default, wich fails. Sorry again for the confusion.
I suspect CC_VENDOR is not being detected/supported; please check what is found and see the makefile line to determine what it should be. Also, it would be easier for us if you paste the command you issue rather than only a snippet of the output.
The C compiler is conventionally passed to the Makefile as a CC variable.
You should just use $(CC) which in my case evaluates to cc.
Different vendors use different flags, even for "standard" things like -fPIC (which IBM XL compilers insist on calling -qpic). Vendor detection is used to set default flags. You are welcome to provide the correct flags for your system using CFLAGS, or you can check what we determined as your vendor by checking make print-CC_VENDOR and cc --version. It's likely that we just need to map a FreeBSD-specific string to clang or whatever.
https://github.com/CEED/libCEED/blob/main/Makefile#L104-L145
make print-CC_VENDOR prints this:
[ variable name]: CC_VENDOR
[ origin]: file
[ flavor]: simple
[ value]: clang
[expanded value]: clang
Is CFLAGS being set by you?
Is CFLAGS being set by you?
Yes.
Then you are overriding our CFLAGS detection, in which case, please supply -fPIC when you are building a shared library.
The supplied CFLAGS=-O2 -pipe -fstack-protector-strong -fno-strict-aliasing are general CFLAGS. Normally projects should only append to them.
The port does add -fPIC to build successfully.
We wanted libCEED to be usable with unusual toolchains and with more user control, but without needing to edit files. CMake requires platform/toolchain files for this purpose, and both it and autotools run lots of checks at configure time. You could set OPT=$(CFLAGS) and unset CFLAGS if you want the convenience of not specifying -fPIC.
Even if you set your own CFLAGS, with the clang compiler they should always contain -fPIC when you are building a shared library.