Can't compile Jabcode on M1 (ARM) - gcc

I'am trying to compile jab code (cf. https://jabcode.org/create) on my MacBook with M1 ARM. I do succeed with the first step of compiling jabcode with the given Makefile:
gcc -c -I. -I./include -O2 -std=c11 binarizer.c -o binarizer.o
gcc -c -I. -I./include -O2 -std=c11 decoder.c -o decoder.o
gcc -c -I. -I./include -O2 -std=c11 detector.c -o detector.o
detector.c:51:7: warning: using floating point absolute value function 'fabs' when argument is of integer type [-Wabsolute-value]
fabs(state_count[1] - state_count[3]) < layer_tolerance; //layer 1 and layer 3 shall be of the same size
^
detector.c:51:7: note: use function 'abs' instead
fabs(state_count[1] - state_count[3]) < layer_tolerance; //layer 1 and layer 3 shall be of the same size
^~~~
abs
1 warning generated.
gcc -c -I. -I./include -O2 -std=c11 encoder.c -o encoder.o
gcc -c -I. -I./include -O2 -std=c11 image.c -o image.o
gcc -c -I. -I./include -O2 -std=c11 interleave.c -o interleave.o
gcc -c -I. -I./include -O2 -std=c11 ldpc.c -o ldpc.o
gcc -c -I. -I./include -O2 -std=c11 mask.c -o mask.o
gcc -c -I. -I./include -O2 -std=c11 pseudo_random.c -o pseudo_random.o
gcc -c -I. -I./include -O2 -std=c11 sample.c -o sample.o
gcc -c -I. -I./include -O2 -std=c11 transform.c -o transform.o
ar cru build/libjabcode.a binarizer.o decoder.o detector.o encoder.o image.o interleave.o ldpc.o mask.o pseudo_random.o sample.o transform.o
ranlib build/libjabcode.a
However, when trying to compile the Reader or Writer, I end up with:
gcc -c -I. -I../jabcode -I../jabcode/include -O2 -std=c11 jabwriter.c -o jabwriter.o
gcc jabwriter.o -L../jabcode/build -ljabcode -L../jabcode/lib -ltiff -lpng16 -lz -lm -O2 -std=c11 -o bin/jabcodeWriter
ld: warning: ignoring file ../jabcode/lib/libpng16.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
ld: warning: ignoring file ../jabcode/lib/libtiff.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
ld: warning: ignoring file ../jabcode/lib/libz.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
Undefined symbols for architecture arm64:
"\_TIFFClose", referenced from:
\_saveImageCMYK in libjabcode.a(image.o)
"\_TIFFDefaultStripSize", referenced from:
\_saveImageCMYK in libjabcode.a(image.o)
"\_TIFFOpen", referenced from:
\_saveImageCMYK in libjabcode.a(image.o)
"\_TIFFSetField", referenced from:
\_saveImageCMYK in libjabcode.a(image.o)
"\_TIFFWriteScanline", referenced from:
\_saveImageCMYK in libjabcode.a(image.o)
"\_png_image_begin_read_from_file", referenced from:
\_readImage in libjabcode.a(image.o)
"\_png_image_finish_read", referenced from:
\_readImage in libjabcode.a(image.o)
"\_png_image_free", referenced from:
\_readImage in libjabcode.a(image.o)
"\_png_image_write_to_file", referenced from:
\_saveImage in libjabcode.a(image.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: \*\*\* \[bin/jabcodeWriter\] Error 1
I already tried to add -lstdc++ to CFLAGS in all Makefiles, as suggested here, which generates warnings of "'linker' input unused" for jabcode and does not resolve the problems when trying to compile jacbodeReader of jabcodeWriter.
Also I tried to compile as x86_64, following this question, by adding -arch x86_64 to CFLAGS in each Makefile. The error remained as above Undefined symbols for architecture x86_64 and
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Sorry if the answer is obvious, I'm no expert in C/C++ and Makefiles and could not find any solution here.

I've checked the sources on github and I've checked the flags that you pass to g++ and the answer is quite simple.
You are linking against a static tiff library that wasn't build for your architecture. Look at the folder to which you point with the -L flag.
The author states that he tested it on his ubuntu machine so presumably it is build for the amd64 architecture.
To solve this you need to get the dependencies that you link (tiff is one of them) for your machine and link against it. On MacOS that is usually done using the homebrew package manager.

Related

Cannot build xv6-x86_64 on MacOS: "error: unexpected token in '.section' directive"

I'm using xv6 for learning OS kernel development. So far, it's easily buildable on MacOS, once you have i386-elf-gcc installed.
Then I found someone ported it to 64-bit: xv6-x86_64, and wanted to give it a try.
Running make (using gcc provided by MacOS Monterey, which is an alias to clang 14) gives this:
gcc -o obj/boot/stage_1.o -fno-pic -static -fno-builtin -fno-strict-aliasing -MD -ggdb -fno-omit-frame-pointer -O1 -std=c11 -Wall -Wextra -Wno-format -Wno-unused -Wno-address-of-packed-member -Werror -fno-stack-protector -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -mfpmath=387 -m32 -fno-pic -nostdinc -I. -c boot/stage_1.S
boot/stage_1.S:8:15: error: unexpected token in '.section' directive
.section .boot-first-stage, "awx"
^
make: *** [obj/boot/stage_1.o] Error 1
Then I edited the Makefile, changing CC=gcc to CC=gcc-12 (GCC 12 provided by Homebrew). Same error:
gcc-12 -o obj/boot/stage_1.o -fno-pic -static -fno-builtin -fno-strict-aliasing -MD -ggdb -fno-omit-frame-pointer -O1 -std=c11 -Wall -Wextra -Wno-format -Wno-unused -Wno-address-of-packed-member -Werror -fno-stack-protector -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -mfpmath=387 -fno-pie -no-pie -m32 -fno-pic -nostdinc -I. -c boot/stage_1.S
boot/stage_1.S:8:15: error: unexpected token in '.section' directive
.section .boot-first-stage, "awx"
^
make: *** [obj/boot/stage_1.o] Error 1
Here's the first 22 lines of boot/stage_1.S:
#include "mmu.h"
# Start the first CPU: switch to 32-bit protected mode, jump into C.
# The BIOS loads this code from the first sector of the hard disk into
# memory at physical address 0x7c00 and starts executing in real mode
# with %cs=0 %ip=7c00.
.section .boot-first-stage, "awx"
.code16 # Assemble for 16-bit mode
.globl start
start:
cli # BIOS enabled interrupts; disable
# Zero data segment registers DS, ES, and SS.
xorw %ax,%ax # Set %ax to zero
movw %ax,%ds # -> Data Segment
movw %ax,%es # -> Extra Segment
movw %ax,%ss # -> Stack Segment
# clear the direction flag (e.g. go forward in memory when using
# instructions like lodsb)
cld
Unfortunately I'm not versed in assembly. How to fix this?

"ld: library not found for -lc" in mac big sur

I try to writed a redis module by clone the git project https://github.com/RedisLabs/RedisModulesSDK.git
and type the "Make" command in my mac with big sur version, below message display in the console.
But there is a error "ld: library not found for -lc".
How to fix it. I try the same command in a linux os, it works find.
gcc -g -fPIC -O3 -std=gnu99 -Wall -Wno-unused-function -I../ -c -o util.o util.c
gcc -g -fPIC -O3 -std=gnu99 -Wall -Wno-unused-function -I../ -c -o strings.o strings.c
gcc -g -fPIC -O3 -std=gnu99 -Wall -Wno-unused-function -I../ -c -o sds.o sds.c
gcc -g -fPIC -O3 -std=gnu99 -Wall -Wno-unused-function -I../ -c -o vector.o vector.c
gcc -g -fPIC -O3 -std=gnu99 -Wall -Wno-unused-function -I../ -c -o alloc.o alloc.c
gcc -g -fPIC -O3 -std=gnu99 -Wall -Wno-unused-function -I../ -c -o periodic.o periodic.c
ar rcs librmutil.a util.o strings.o sds.o vector.o alloc.o periodic.o
gcc -I../ -Wall -g -fPIC -lc -lm -std=gnu99 -c -o module.o module.c
clang: warning: -lc: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
ld -o module.so module.o -bundle -undefined dynamic_lookup -v -L../rmutil -lrmutil -lc
#(#)PROGRAM:ld PROJECT:ld64-609.8
BUILD 15:07:46 Dec 18 2020
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
Library search paths:
../rmutil
/usr/lib
/usr/local/lib
Framework search paths:
/Library/Frameworks/
/System/Library/Frameworks/
ld: library not found for -lc
make[1]: *** [module.so] Error 1
make: *** [module.so] Error 2
To prevent this error on 11.x+: ld: library not found for -lc
the path /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib needs to be added with -L
https://github.com/macports/macports-ports/commit/0a780d32e0ae3997ed2f2d611cee604d1476cdb5

LTO and overriding stdlib functions in static libraries

I have an embedded platform that brings its own stdlib functions like malloc and printf in a static library. I need to compile this library with LTO. Unfortunately in this combination (-flto + -nostdlib + linking with stdlib replacements from an .a) the linker cannot find the functions.
I have prepared a MWE that should run on most Unix machines but since it contains multiple files I have put it into a repo:
https://github.com/stefanct/lto_static_libs
The included makefile allows to switch on some features on and off for testing:
nostdlib=y: add -nostdlib to the linking stage
nolto=y: disable LTO
libfunc=y: enable a call to a non-standard function within the library (you will see why at the end!)
The gist is to have one module containing a standard function, e.g.:
int puts(const char *s) {
return 2;
}
Compiling that into an object file with -flto, putting it into a static library with gcc-ar and eventually using that when linking with an application.
In my setup (GCC 11 branch built from source and GNU ld 2.31.1 from Debian Buster) I get the following results:
No options set: OK - the printf from the library gets overridden(?) by the standard function:
$ make -B
Using GCC 11.0.0
gcc -Wall -Wextra -Wno-unused-parameter -flto -ffat-lto-objects -c -o libtest.o libtest.c
lto-dump -list libtest.o
Type Visibility Size Name
function default 4 lib_func
function default 4 puts
function default 4 printf
gcc-nm libtest.o
00000000 T lib_func
00000000 T printf
00000000 T puts
rm -f libtest.a
gcc-ar -cvq libtest.a libtest.o
a - libtest.o
gcc -Wall -Wextra -Wno-unused-parameter -flto -ffat-lto-objects -c -o main.o main.c
gcc -Wall -Wextra -Wno-unused-parameter -flto -ffat-lto-objects -o exe main.o -L. -ltest
$ ./exe
hurga
No stdlib but also without LTO: OK - linking works fine(ish - running segfaults but that's to be expected I guess and could be worked around with -nodefaultlibs but I don't care here)
$ make -B nostdlib=y nolto=y
Using GCC 11.0.0
gcc -Wall -Wextra -Wno-unused-parameter -c -o libtest.o libtest.c
gcc-nm libtest.o
0000000000000074 T lib_func
0000000000000000 T printf
0000000000000065 T puts
rm -f libtest.a
gcc-ar -cvq libtest.a libtest.o
a - libtest.o
gcc -Wall -Wextra -Wno-unused-parameter -c -o main.o main.c
gcc -Wall -Wextra -Wno-unused-parameter -o exe main.o -L. -ltest -nostdlib
/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000
No stdlib but leaving LTO enabled: suddenly puts is no longer found.
However, as you can see, the object file that gets put into the library contains the function just fine (and evengcc-mn libtest.a shows the same).
This is the case I would like to fix. Why is this breaking?
$ make -B nostdlib=y
Using GCC 11.0.0
gcc -Wall -Wextra -Wno-unused-parameter -flto -ffat-lto-objects -c -o libtest.o libtest.c
lto-dump -list libtest.o
Type Visibility Size Name
function default 4 lib_func
function default 4 puts
function default 4 printf
gcc-nm libtest.o
00000000 T lib_func
00000000 T printf
00000000 T puts
rm -f libtest.a
gcc-ar -cvq libtest.a libtest.o
a - libtest.o
gcc -Wall -Wextra -Wno-unused-parameter -flto -ffat-lto-objects -c -o main.o main.c
gcc -Wall -Wextra -Wno-unused-parameter -flto -ffat-lto-objects -o exe main.o -L. -ltest -nostdlib
/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000
/usr/bin/ld: /tmp/cczvyrrg.ltrans0.ltrans.o: in function `main':
<artificial>:(.text+0xe): undefined reference to `puts'
collect2: error: ld returned 1 exit status
make: *** [makefile:39: exe] Error 1
Interestingly enough, if we call another unrelated (non-standard) function in the same library things start to work again!?
$ make -B nostdlib=y libfunc=y
Using GCC 11.0.0
gcc -Wall -Wextra -Wno-unused-parameter -flto -ffat-lto-objects -D LIB_FUNC -c -o libtest.o libtest.c
lto-dump -list libtest.o
Type Visibility Size Name
function default 4 lib_func
function default 4 puts
function default 4 printf
gcc-nm libtest.o
00000000 T lib_func
00000000 T printf
00000000 T puts
rm -f libtest.a
gcc-ar -cvq libtest.a libtest.o
a - libtest.o
gcc -Wall -Wextra -Wno-unused-parameter -flto -ffat-lto-objects -D LIB_FUNC -c -o main.o main.c
gcc -Wall -Wextra -Wno-unused-parameter -flto -ffat-lto-objects -D LIB_FUNC -o exe main.o -L. -ltest -nostdlib
/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000
Do I see a bug in binutils/ld? Is this fixed upstream?

Problems compiling Qt with OCI sql plugin on Linux

I am having serious trouble compiling Qt with the OCI plugin.
The Qt version is 5.6.1, and the Oracle instant client version is 12.1.0.2.0. I have installed both the basic and SDK versions, as the Qt online manual asks.
I then try to run the following command:
./configure -I /usr/include/oracle/12.1/client64/ -L /usr/lib/oracle/12.1/client64/lib -prefix /online/daq/antonin/qt_build -plugin-sql-oci -qt-xcb -v
Which produces this output:
+ cd qtbase
+ /online/daq/antonin/qt_source/5.6/Src/qtbase/configure -top-level -I /usr/include/oracle/12.1/client64/ -L /usr/lib/oracle/12.1/client64/lib -prefix /online/daq/antonin/qt_build -plugin-sql-oci -qt-xcb -v
Which edition of Qt do you want to use ?
Type 'c' if you want to use the Commercial Edition.
Type 'o' if you want to use the Open Source Edition.
o
This is the Qt Open Source Edition.
You are licensed to use this software under the terms of
the Lesser GNU General Public License (LGPL) versions 2.1.
You are also licensed to use this software under the terms of
the GNU Lesser General Public License (LGPL) versions 3.
Type '3' to view the GNU Lesser General Public License version 3.
Type 'L' to view the Lesser GNU General Public License version 2.1.
Type 'yes' to accept this license offer.
Type 'no' to decline this license offer.
Do you accept the terms of either license? yes
Running configuration tests (phase 1)...
Precompiled-headers support enabled.
g++ -c -fvisibility=hidden fvisibility.c
Symbol visibility control enabled.
cc1plus: error: unrecognized command line option "-fuse-ld=gold"
g++ -o libtest.so -shared -Wl,-Bsymbolic-functions -fPIC bsymbolic_functions.c
Symbolic function binding enabled.
DEFAULT_INCDIRS="/usr/include/c++/4.4.7
/usr/include/c++/4.4.7/x86_64-redhat-linux
/usr/include/c++/4.4.7/backward
/usr/local/include
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include
/usr/include
"
DEFAULT_LIBDIRS="/lib64
/usr/lib64
/online/daq/lib
/usr/lib
/lib
/usr/lib/gcc/x86_64-redhat-linux/4.4.7
"
Done running configuration tests.
Creating qmake...
gmake: Nothing to be done for `first'.
Running configuration tests (phase 2)...
Found pkg-config from $PATH: /usr/bin/pkg-config
Determining architecture... ()
g++ -c -pipe -g -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../mkspecs/linux-g++ -o arch.o arch.cpp
g++ -o arch arch.o -L/usr/lib/oracle/12.1/client64/lib
Found architecture in binary
CFG_ARCH="x86_64"
CFG_CPUFEATURES=" mmx sse sse2"
System architecture: 'x86_64'
Host architecture: 'x86_64'
C++11 auto-detection... ()
g++ -c -pipe -O2 -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o c++11.o c++11.cpp
g++ -Wl,-O1 -o c++11 c++11.o -L/usr/lib/oracle/12.1/client64/lib
C++11 enabled.
C++14 auto-detection... ()
g++ -c -pipe -O2 -std=gnu++1y -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o c++14.o c++14.cpp
cc1plus: error: unrecognized command line option "-std=gnu++1y"
gmake: *** [c++14.o] Error 1
C++14 disabled.
default C++ standard edition auto-detection... ()
g++ -pipe -O2 -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o c++default.ii -E c++default.cpp
default C++ standard edition enabled.
64-bit std::atomic auto-detection... ()
g++ -c -pipe -O2 -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o atomic64.o atomic64.cpp
atomic64.cpp:34:18: error: atomic: No such file or directory
atomic64.cpp:37: error: expected unqualified-id before '<' token
atomic64.cpp:37: error: expected ')' before '<' token
atomic64.cpp:37: error: expected initializer before '<' token
gmake: *** [atomic64.o] Error 1
64-bit std::atomic disabled.
64-bit std::atomic in -latomic auto-detection... ()
g++ -c -pipe -O2 -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o atomic64.o atomic64.cpp
atomic64.cpp:34:18: error: atomic: No such file or directory
atomic64.cpp:37: error: expected unqualified-id before '<' token
atomic64.cpp:37: error: expected ')' before '<' token
atomic64.cpp:37: error: expected initializer before '<' token
gmake: *** [atomic64.o] Error 1
64-bit std::atomic in -latomic disabled.
sse2 auto-detection... ()
g++ -c -pipe -msse2 -g -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o sse2.o sse2.cpp
g++ -o sse2 sse2.o -L/usr/lib/oracle/12.1/client64/lib
sse2 enabled.
sse3 auto-detection... ()
g++ -c -pipe -msse3 -g -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o sse3.o sse3.cpp
g++ -o sse3 sse3.o -L/usr/lib/oracle/12.1/client64/lib
sse3 enabled.
ssse3 auto-detection... ()
g++ -c -pipe -mssse3 -g -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o ssse3.o ssse3.cpp
g++ -o ssse3 ssse3.o -L/usr/lib/oracle/12.1/client64/lib
ssse3 enabled.
sse4_1 auto-detection... ()
g++ -c -pipe -msse4.1 -g -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o sse4_1.o sse4_1.cpp
g++ -o sse4_1 sse4_1.o -L/usr/lib/oracle/12.1/client64/lib
sse4_1 enabled.
sse4_2 auto-detection... ()
g++ -c -pipe -msse4.2 -g -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o sse4_2.o sse4_2.cpp
g++ -o sse4_2 sse4_2.o -L/usr/lib/oracle/12.1/client64/lib
sse4_2 enabled.
avx auto-detection... ()
g++ -c -pipe -mavx -g -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o avx.o avx.cpp
g++ -o avx avx.o -L/usr/lib/oracle/12.1/client64/lib
avx enabled.
avx2 auto-detection... ()
g++ -c -pipe -mavx2 -g -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o avx2.o avx2.cpp
cc1plus: error: unrecognized command line option "-mavx2"
gmake: *** [avx2.o] Error 1
avx2 disabled.
ipc_sysv auto-detection... ()
g++ -c -pipe -O2 -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o ipc.o ipc.cpp
g++ -Wl,-O1 -o ipc_sysv ipc.o -L/usr/lib/oracle/12.1/client64/lib
ipc_sysv enabled.
zlib auto-detection... ()
g++ -c -pipe -O2 -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o zlib.o zlib.cpp
g++ -Wl,-O1 -o zlib zlib.o -L/usr/lib/oracle/12.1/client64/lib -lz
zlib enabled.
mtdev auto-detection... ()
Project ERROR: mtdev development package not found
mtdev disabled.
libjpeg auto-detection... ()
g++ -c -pipe -O2 -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o libjpeg.o libjpeg.cpp
libjpeg.cpp: In function 'int main(int, char**)':
libjpeg.cpp:43: warning: 'cinfo' is used uninitialized in this function
g++ -Wl,-O1 -o libjpeg libjpeg.o -L/usr/lib/oracle/12.1/client64/lib -ljpeg
libjpeg enabled.
libpng auto-detection... ()
g++ -c -pipe -O2 -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o libpng.o libpng.cpp
g++ -Wl,-O1 -o libpng libpng.o -L/usr/lib/oracle/12.1/client64/lib -lpng
libpng enabled.
libdl auto-detection... ()
g++ -c -pipe -O2 -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o libdl.o libdl.cpp
g++ -Wl,-O1 -o libdl libdl.o -L/usr/lib/oracle/12.1/client64/lib -ldl
libdl enabled.
DB2 auto-detection... ()
g++ -c -pipe -O2 -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o db2.o db2.cpp
db2.cpp:34:20: error: sqlcli.h: No such file or directory
db2.cpp:35:21: error: sqlcli1.h: No such file or directory
gmake: *** [db2.o] Error 1
DB2 disabled.
InterBase auto-detection... ()
g++ -c -pipe -O2 -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o ibase.o ibase.cpp
ibase.cpp:34:19: error: ibase.h: No such file or directory
gmake: *** [ibase.o] Error 1
InterBase disabled.
MySQL (thread-safe) auto-detection... ()
g++ -c -pipe -O2 -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -isystem /usr/include/mysql -I../../../mkspecs/linux-g++ -o mysql.o ../mysql/mysql.cpp
g++ -Wl,-O1 -o mysql_r mysql.o -L/usr/lib/oracle/12.1/client64/lib -L/usr/lib64/mysql -lz -lcrypt -lnsl -lm -lpthread -lssl -lcrypto -lmysqlclient_r
MySQL (thread-safe) enabled.
OCI auto-detection... ()
g++ -c -pipe -O2 -std=gnu++0x -Wall -W -fPIC -I. -isystem /usr/include/oracle/12.1/client64 -I../../../mkspecs/linux-g++ -o oci.o oci.cpp
g++ -Wl,-O1 -o oci oci.o -L/usr/lib/oracle/12.1/client64/lib -lclntsh
/usr/lib/oracle/12.1/client64/lib/libclntsh.so: undefined reference to `lxXmlCvEsc0'
/usr/lib/oracle/12.1/client64/lib/libclntsh.so: undefined reference to `lxXmlGEntEscImpl'
/usr/lib/oracle/12.1/client64/lib/libclntsh.so: undefined reference to `slnxmul'
/usr/lib/oracle/12.1/client64/lib/libclntsh.so: undefined reference to `zt_init'
/usr/lib/oracle/12.1/client64/lib/libclntsh.so: undefined reference to `slnxadd'
/usr/lib/oracle/12.1/client64/lib/libclntsh.so: undefined reference to `slnxsub'
collect2: ld returned 1 exit status
gmake: *** [oci] Error 1
OCI disabled.
Oracle (OCI) support cannot be enabled due to functionality tests!
Turn on verbose messaging (-v) to /online/daq/antonin/qt_source/5.6/Src/qtbase/configure to see the final report.
If you believe this message is in error you may use the continue
switch (-continue) to /online/daq/antonin/qt_source/5.6/Src/qtbase/configure to continue.
As you can see, there are several undefined references for one of the the OCI .so files. I have tried checking online, but I have found barely any references to these symbols.
Any idea what could be causing this? A missing .so file? Wrong version of the library?

GCC Static Linking And Separate Loader

I'm trying to understand the process of static linking, loading of GCC:
I have the following toy program
#include "stdio.h"
int main() {
fprintf(stdout, "Hello World \n");
return 0 ;
}
I can compile it and run file as follows:
gcc -static -std=gnu99 -Wall -Wno-unused -g test.c -o test;
But as soon as I try to separate out the compile and linking process as follows:
gcc -static -std=gnu99 -Wall -Wno-unused -g test.c -c;
ld -o test -T link.lds test.o
where the link.lds is
SECTIONS
{
. = 0x10000;
.text : { *(.text) }
. = 0x8000000;
.data : { *(.data) }
.bss : { *(.bss) }
}
I get the error "undefined reference to stdouttest.o: In function `main':
test.c:(.text+0x7): undefined reference to `stdout'
test.c:(.text+0x1e): undefined reference to `fwrite'
If I try adding the flag -lc to ld, it tells me that it is not found. I've tried running gcc with -lc
and/or -static-libgcc but I have the same problem.
What am I doing wrong?
Do
gcc -v -static -std=gnu99 -Wall -Wno-unused -g test.c
and look for the collect2 tag.
In my case it is
collect2 --sysroot=/ --build-id -m elf_x86_64 --hash-style=gnu --as-needed -static -z relro -o test /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbeginT.o -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. /tmp/ccoR98Xr.o --start-group -lgcc -lgcc_eh -lc --end-group /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
You have to replace the temporary object file. In my case I replaced /tmp/ccoR98Xr.o with test.o. Then do
gcc -c -std=gnu99 -Wall -Wno-unused -g test.c
ld --sysroot=/ --build-id -m elf_x86_64 --hash-style=gnu --as-needed -static -z relro -o test /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbeginT.o -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. test.o --start-group -lgcc -lgcc_eh -lc --end-group /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
It links to the object files : crt1.o, crti.o, crtbeginT.o, crtend.o, and crtn.o.
It links to the libraires: libgcc.a, libgcc_eh.a, and libc.a.
You can replace --start-group -lgcc -lgcc_eh -lc --end-group with -lgcc -lc -lgcc_eh -lc if you like.
Knowing this we can simply this to
ln -s `gcc -print-file-name=crt1.o`
ln -s `gcc -print-file-name=crti.o`
ln -s `gcc -print-file-name=crtn.o`
ln -s `gcc -print-file-name=libgcc_eh.a`
ln -s `gcc -print-file-name=libc.a`
gcc -c -std=gnu99 -Wall -Wno-unused -g test.c
ld -m elf_x86_64 -o test crt1.o crti.o test.o libc.a libgcc_eh.a libc.a crtn.o
I did not use crtbeginT.o, crtend.o, and libgcc.a because it worked without them.
Take a look at this, strace does the job (show you the secrets) but you will soon realize there are tons of options in it... You need to link a few stuff together (from GNU C lib) to get your executable, not only your object... You can add grep 'exec' in the end to make it cleaner.
Uhhh, also you need to do this:
as obj.s -o obj.o
Use GNU assembler to convert your .s to .o then link with ld.

Resources