I upgraded my Linux distro from Pop OS 19.10 to 20.04, and it naturally included upgrades to glibc & co. Since then, I started getting linker errors for libm symbols like __pow_finite.
Unfortunately, the code that references these symbols is a static library (libWithPowFiniteRef.a in the redacted snippet below) with third-party proprietary code. I don't have access to source.
I checked /lib/x86_64-linux-gnu/libm.so.6 using nm. The symbol is there:
nm -gD /lib/x86_64-linux-gnu/libm.so.6
...
0000000000010e00 W powf64x
00000000000471f0 i __powf_finite
000000000002ed90 i __pow_finite
0000000000010e00 W powl
0000000000019860 T __powl_finite
...
So I can't explain the errors:
g++ -o ./media_tests -Wl,--verbose -Wl,--start-group #"./media_tests.rsp" -ldl -lpthread -lrt ../../third_party/other.so ../../third_party/redacted/lib/Linux/x64/libWithPowFiniteRef.a -Wl,--end-group
...
attempt to open /usr/lib/gcc/x86_64-linux-gnu/9/libm.so failed
attempt to open /usr/lib/gcc/x86_64-linux-gnu/9/libm.a failed
attempt to open /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libm.so succeeded
...
attempt to open /usr/lib/gcc/x86_64-linux-gnu/9/libm.so failed
attempt to open /usr/lib/gcc/x86_64-linux-gnu/9/libm.a failed
attempt to open /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libm.so succeeded
opened script file /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libm.so
/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libm.so
opened script file /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libm.so
attempt to open /lib/x86_64-linux-gnu/libm.so.6 succeeded
/lib/x86_64-linux-gnu/libm.so.6
...
/usr/bin/ld:../../third_party/redacted/lib/Linux/x64/redacted.a(redacted.o): in function `RedactedX':
redacted1.c:(.text+0xbb0): undefined reference to `__pow_finite'
/usr/bin/ld: ../../third_party/redacted/lib/Linux/x64/redacted.a(redacted.o): in function `RedactedY':
redacted2.c:(.text+0x7ad9): undefined reference to `__pow_finite'
/usr/bin/ld: redacted.c:(.text+0x8c74): undefined reference to `__pow_finite'
/usr/bin/ld: link errors found, deleting executable `./media_tests'
Maybe we the solution is to request a new static lib from the vendor, but I would like to understand why.
Related
I'm experimenting with my first foray into libraries. I am trying to compile the Unity testing framework to a static library using gcc -c -fPIC -std=c99 -Wall -Wextra -pedantic -Werror -Wmissing-declarations -DUNITY_SUPPORT_64 test-framework/unity.c -o bin/libunity.o
This runs just fine.
However when I then try to use that object file:
$ gcc test_hello_world.c -Lbin -lunity -o test
/usr/bin/ld: cannot find -lunity
collect2: error: ld returned 1 exit status
Checking what ld is doing
$ ld -Lbin -luinty --verbose
GNU ld (GNU Binutils for Ubuntu) 2.34
Supported emulations:
elf_x86_64
elf32_x86_64
#
# ... script waffle
#
==================================================
ld: mode elf_x86_64
attempt to open bin/libuinty.so failed
attempt to open bin/libuinty.a failed
attempt to open /usr/local/lib/x86_64-linux-gnu/libuinty.so failed
attempt to open /usr/local/lib/x86_64-linux-gnu/libuinty.a failed
attempt to open /lib/x86_64-linux-gnu/libuinty.so failed
attempt to open /lib/x86_64-linux-gnu/libuinty.a failed
attempt to open /usr/lib/x86_64-linux-gnu/libuinty.so failed
attempt to open /usr/lib/x86_64-linux-gnu/libuinty.a failed
attempt to open /usr/lib/x86_64-linux-gnu64/libuinty.so failed
attempt to open /usr/lib/x86_64-linux-gnu64/libuinty.a failed
attempt to open /usr/local/lib64/libuinty.so failed
attempt to open /usr/local/lib64/libuinty.a failed
attempt to open /lib64/libuinty.so failed
attempt to open /lib64/libuinty.a failed
attempt to open /usr/lib64/libuinty.so failed
attempt to open /usr/lib64/libuinty.a failed
attempt to open /usr/local/lib/libuinty.so failed
attempt to open /usr/local/lib/libuinty.a failed
attempt to open /lib/libuinty.so failed
attempt to open /lib/libuinty.a failed
attempt to open /usr/lib/libuinty.so failed
attempt to open /usr/lib/libuinty.a failed
attempt to open /usr/x86_64-linux-gnu/lib64/libuinty.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/libuinty.a failed
attempt to open /usr/x86_64-linux-gnu/lib/libuinty.so failed
attempt to open /usr/x86_64-linux-gnu/lib/libuinty.a failed
ld: cannot find -luinty
So it looks for bin/libunity.so and bin/libunity.a, but no bin/libunity.o... every internet page I've looked at this evening seems to assume that ld should pick up ".o" files just the same as ".so" or ".a" no questions asked (man pages seem to either similarly expect it or don't mention ".o" at all)... but it's not...
Am I misunderstanding something? Missing some argument?
EDIT: I've now run ar rcs bin/libunity.a bin/unity.o and then the gcc command from above. This seems to work (there are other errors). But I still thought ld should work with .o files, am I, and half the web, wrong?
This should work:
$ gcc test_hello_world.c bin/libunity.o -o test
Possibly shouldn't even really use the word "library" to describe a *.o file.
Never heard of lib*.o files being suitable for lib*.so/lib*.a files.
*.o files are linked directly without any libfoo.o ==> -lfoo magic.
Or if you want to turn .o into a .a, then use $ ar -crs libunity.a libunity.o, (see also: https://www.howtogeek.com/427086/how-to-use-linuxs-ar-command-to-create-static-libraries/).
A static library is an ar archive containing one or more object files.
When trying to install the latest glibc into my machine provided I executed the "config" executable with flags: ../configure CFLAGS="-O3 -fPIC" --disable-sanity-checks it generates the makefile correctly, although I think disable-sanity-checks will give some errors.
But whenever I try to execute the generated Makefile using make, the console prints the following error:
make[3]: Leaving directory '/mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/elf'
gcc -nostdlib -nostartfiles -shared -o /mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/glibc-build/elf/ld.so.new \
-Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs \
/mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/glibc-build/elf/librtld.os -Wl,--version-script=/mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/glibc-build/ld.map
\
-Wl,-soname=ld-linux-x86-64.so.2 \
-Wl,-defsym=_begin=0
/mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/glibc-build/elf/librtld.os: In function `process_envvars':
/mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/elf/rtld.c:2686: undefined reference to `__GI___open64_nocancel'
/usr/bin/ld: /mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/glibc-build/elf/librtld.os: relocation R_X86_64_PC32 against undefined symbol `__GI___open64_nocancel' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
As I said, I tried to add the -fPIC flag but still didn't catch it. And I'm kind of new to .os, .map and other extensions such as those. Am I doing it completely wrong? Or else, how could I compile just that file using gcc instead of passing the flag to the whole make command?
Your file system is not set up correctly. By default, NTFS is case-preserving, but case-insensitive. As far as I understand it, current versions of WSL set up only part of the file system tree in case-sensitive mode. (A previous system-wide configuration is now disregarded.)
Building glibc requires a case-sensitive file system. Please also note that WSL is not a proper development environment for glibc because there are so many test failures due to bugs in the WSL kernel emulation.
I'm trying to use methods contained in a shared library (libscplugin.so).
I have satisfied all of the libraries requirements:
libc.so with a symlink to libc.so.6
libz.so with a symlink to libz.so.1.2.8
libstdc++.so with a symlink to libstdc++.so.6.0.20
Upon compilation I get the following error message:
$ gcc test.c -o test -L/usr/lib/arm-linux-gnueabihf/ -lscplugin
/usr/bin/ld: test: hidden symbol `stat' in /usr/lib/arm-linux-gnueabihf/libc_nonshared.a(stat.oS) is referenced by DSO
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
The only reference I could find to libc_nonshared.a is in /usr/lib/arm-linux-gnueabihf/libc.so:
$ cat libc.so
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( /lib/arm-linux-gnueabihf/libc.so.6 /usr/lib/arm-linux-gnueabihf/libc_nonshared.a AS_NEEDED ( /lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 ) )
In test.c I'm attempting to use two functions of the shared library (totally unrelated to stat). What can I do to get this to compile ?
Your problem is here:
I have satisfied all of the libraries requirements:
libc.so with a symlink to libc.so.6
That is not a valid setup for glibc. libc.so is supposed to be a text file (linker script) as you saw at the end of your answer. You're doing something weird and unnecessary if you're making symlinks to shared libraries like this yourself. Use the libc.so that's provided (and you need to do this when building your other shared libraries -- your problem right now is that they were mis-linked) and everything will work fine.
I need to use the R package Rglpk in a project and need to modify the package - in particular, I need to add a time limit control parameter option to the interface (it is a option in GLPK v4.5.2 itself, but Rglpk 0.5-2 does not support this parameter). This will allow R to call GLPK and limit the search time to be user specified (i.e., search time <= t).
I have modified Rglpk code and have successfully compiled the package on Mac OS X v10.9.2 and verified that it worked as expected. My project needs to run on Windows and I have not been able to compile the modified Rglpk package, or for that matter the unmodified package (Rglpk 0.5-2), on Windows. I have tried uploading the original package to Win Builder (http://win-builder.r-project.org/), but I have received the same errors.
The following is a summary of what I have done on Windows 7 (my machine):
(1) Download the Rglpk 0.5-2 package source from http://cran.r-project.org/web/packages/Rglpk/index.html
(2) Unzip the file to a directory. All the code is in a directory called Rglpk.
(3) Start RStudio v0.98.490. I have devtools v1.4.1 installed, Rtools v3.1 installed, and R v3.0.2
(4) Open a new project and select the Rglpk directory mentioned in (2).
(5) Under the 'Build' menu, select 'Build and Reload'. The result of this is that the package compiles and is loaded:
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (Rglpk)
(6) Under the 'Build' menu, select 'Check Package'. The result is that the installation fails. The log file is shown below.
I have tried to compile another package that has C code and have not been able to compile it either. The package I tried to compile is devtools v1.5 The error that came back in that case is 'LoadLibrary failure: %1 is not a valid Win32 application.'
Does anyone have any experience compiling R packages on Windows that include C code? I have been able to compile packages that involve only R code, but it seems C code is troublesome.
Any help would be appreciated.
Log File
* using R version 3.0.2 (2013-09-25)
* using platform: x86_64-w64-mingw32 (64-bit)
* using session charset: ISO8859-1
* checking for file 'Rglpk/DESCRIPTION' ... OK
* this is package 'Rglpk' version '0.5-2'
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... NOTE
Found the following apparent object files/libraries:
src/GLPK/alloc.o src/GLPK/amd/amd_1.o src/GLPK/amd/amd_2.o
src/GLPK/amd/amd_aat.o src/GLPK/amd/amd_control.o
src/GLPK/amd/amd_defaults.o src/GLPK/amd/amd_dump.o
src/GLPK/amd/amd_info.o src/GLPK/amd/amd_order.o
src/GLPK/amd/amd_post_tree.o src/GLPK/amd/amd_postorder.o
src/GLPK/amd/amd_preprocess.o src/GLPK/amd/amd_valid.o
src/GLPK/bignum.o src/GLPK/cfg.o src/GLPK/cfg1.o
src/GLPK/colamd/colamd.o src/GLPK/dmp.o src/GLPK/env.o
src/GLPK/error.o src/GLPK/ffalg.o src/GLPK/fhv.o src/GLPK/fhvint.o
src/GLPK/glpapi01.o src/GLPK/glpapi02.o src/GLPK/glpapi03.o
src/GLPK/glpapi04.o src/GLPK/glpapi05.o src/GLPK/glpapi06.o
src/GLPK/glpapi07.o src/GLPK/glpapi08.o src/GLPK/glpapi09.o
src/GLPK/glpapi10.o src/GLPK/glpapi11.o src/GLPK/glpapi12.o
..... (more lines are here, I have removed them for brevity)
src/GLPK/triang.o src/GLPK/wclique.o src/GLPK/wclique1.o
src/GLPK/zlib/adler32.o src/GLPK/zlib/compress.o
src/GLPK/zlib/crc32.o src/GLPK/zlib/deflate.o src/GLPK/zlib/gzclose.o
src/GLPK/zlib/gzlib.o src/GLPK/zlib/gzread.o src/GLPK/zlib/gzwrite.o
src/GLPK/zlib/inffast.o src/GLPK/zlib/inflate.o
src/GLPK/zlib/inftrees.o src/GLPK/zlib/trees.o
src/GLPK/zlib/uncompr.o src/GLPK/zlib/zio.o src/GLPK/zlib/zutil.o
Object files/libraries should not be included in a source package.
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking whether package 'Rglpk' can be installed ... ERROR
Installation failed.
The contents of the 00install.out file are:
* installing *source* package 'Rglpk' ...
** libs
*** arch - i386
gcc -m32 -I"C:/PROGRA~1/R/R-30~1.2/include" -DNDEBUG -IGLPK -IGLPK/amd -IGLPK/colamd -IGLPK/minisat -IGLPK/proxy -IGLPK/zlib -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 -mtune=core2 -c Rglpk_initialize.c -o Rglpk_initialize.o
gcc -m32 -I"C:/PROGRA~1/R/R-30~1.2/include" -DNDEBUG -IGLPK -IGLPK/amd -IGLPK/colamd -IGLPK/minisat -IGLPK/proxy -IGLPK/zlib -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 -mtune=core2 -c Rglpk_read_file.c -o Rglpk_read_file.o
Rglpk_read_file.c: In function 'Rglpk_read_file':
Rglpk_read_file.c:84:6: warning: 'status' may be used uninitialized in this function [-Wuninitialized]
Rglpk_read_file.c: In function 'Rglpk_retrieve_MP_from_file':
Rglpk_read_file.c:192:6: warning: 'status' may be used uninitialized in this function [-Wuninitialized]
gcc -m32 -I"C:/PROGRA~1/R/R-30~1.2/include" -DNDEBUG -IGLPK -IGLPK/amd -IGLPK/colamd -IGLPK/minisat -IGLPK/proxy -IGLPK/zlib -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 -mtune=core2 -c Rglpk_solve.c -o Rglpk_solve.o
Rglpk_solve.c: In function 'R_glp_solve':
Rglpk_solve.c:25:10: warning: variable 'kl' set but not used [-Wunused-but-set-variable]
gcc -m32 -shared -s -static-libgcc -o Rglpk.dll tmp.def Rglpk_initialize.o Rglpk_read_file.o Rglpk_solve.o GLPK/libglpk.a -Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/PROGRA~1/R/R-30~1.2/bin/i386 -lR
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(glpmpl04.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(error.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(glpmpl03.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(alloc.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(glpenv07.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe:
.....
Error: 64-bit reloc in dll
Error: 64-bit reloc in dll
Error: 64-bit reloc in dll
.....
Rglpk_initialize.o:Rglpk_initialize.c:(.text+0x33): undefined reference to `glp_term_hook'
Rglpk_initialize.o:Rglpk_initialize.c:(.text+0x44): undefined reference to `glp_version'
Rglpk_read_file.o:Rglpk_read_file.c:(.text+0x10): undefined reference to `glp_delete_prob'
Rglpk_read_file.o:Rglpk_read_file.c:(.text+0x4f): undefined reference to `glp_term_out'
Rglpk_read_file.o:Rglpk_read_file.c:(.text+0x60): undefined reference to `glp_delete_prob'
Rglpk_read_file.o:Rglpk_read_file.c:(.text+0x65): undefined reference to `glp_create_prob'
.....
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4326): undefined reference to `strcpy'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4d39): undefined reference to `strcpy'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4dc5): undefined reference to `strcpy'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4e05): undefined reference to `floor'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4e16): undefined reference to `floor'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x502e): undefined reference to `floor'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x50e2): undefined reference to `sprintf'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x5111): undefined reference to `sprintf'
.....
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x990): undefined reference to `exp'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x9e0): undefined reference to `log'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xa30): undefined reference to `log10'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xaee): undefined reference to `sin'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xb4e): undefined reference to `cos'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xb65): undefined reference to `atan'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xb79): undefined reference to `atan2'
.....
GLPK/libglpk.a(deflate.o):deflate.c:(.text+0x2ec0): undefined reference to `memcpy'
GLPK/libglpk.a(deflate.o):deflate.c:(.text+0x2ed5): undefined reference to `memcpy'
GLPK/libglpk.a(deflate.o):deflate.c:(.text+0x2ee7): undefined reference to `memcpy'
GLPK/libglpk.a(zutil.o):zutil.c:(.text+0x47): undefined reference to `malloc'
GLPK/libglpk.a(zutil.o):zutil.c:(.text+0x54): undefined reference to `free'
collect2: ld returned 1 exit status
ERROR: compilation failed for package 'Rglpk'
It looks like a couple things are going wrong:
Object files are getting pre-compiled, but not cleaned out.
Because these object files are being pre-compiled, and it looks like they were compiled for 64-bit architecture, when you try to use these in a 32-bit build, the installation process barfs.
The fix here is going to be deleting all of those *.o files (they need to be compiled as part of the R CMD build step, I imagine), and the resulting tarball can then be R CMD checked.
You should consider installing a more up-to-date version of RStudio and devtools, and ensure you use devtools to handle the build process -- it might be able to help you out here.
I'm trying to compile a program (not written by me) in Kubuntu 12.04 and it fails with the following:
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libwx_baseu_xml-2.8.so: undefined reference to symbol 'XML_SetUserData'
/usr/bin/ld: note: 'XML_SetUserData' is defined in DSO /usr/lib/x86_64-linux-gnu/libexpat.so so try adding it to the linker command line
/usr/lib/x86_64-linux-gnu/libexpat.so: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
I fixed a couple of mistakes in the Makefile, but I still don't understand what's the problem here, as the command line does include -lexpat, and apparently at the correct location:
g++ [...] -L/usr/lib/x86_64-linux-gnu [...] -lwx_baseu_xml-2.8 [...] -lm -lexpat [...]
How could I fix/debug this?
Adding -v -Wl,-v to the flags allowed me to see the command lines for collect2 and ld.
For some reason, the original Makefile was putting the libraries (-L and -l options) before most of the object files. I put the libraries at the end of the command line and now it compiles.