Skip to content

Linker errors on Centos 7 build #14

Open
zetasyanthis opened this issue Mar 19, 2021 · 2 comments
Open

Linker errors on Centos 7 build #14

zetasyanthis opened this issue Mar 19, 2021 · 2 comments

Comments

@zetasyanthis
Copy link

zetasyanthis commented Mar 19, 2021

Was trying to build an RPM of version 1.3 for Centos 7, but got stuck on a linker error before I could even get that far. Any idea what might be causing this?

Starting with the cmake output.

[root@centos7-worker01-aus ~]# cmake3 --version
cmake3 version 3.17.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).
[root@centos7-worker01-aus frugen]# cmake3 .
CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  The top-level CMakeLists.txt file must
  contain a literal, direct call to the project() command.  Add a line of
  code such as

    project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Using JSON Library found at /usr/lib64/libjson-c.so
-- Configuring done
-- Generating done
-- Build files have been written to: /root/frugen

And the errors from make:

[root@centos7-worker01-aus frugen]# make VERBOSE=1
/usr/bin/cmake3 -S/root/frugen -B/root/frugen --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake3 -E cmake_progress_start /root/frugen/CMakeFiles /root/frugen/CMakeFiles/progre
ss.marks
make  -f CMakeFiles/Makefile2 all   
make[1]: Entering directory `/root/frugen'
make  -f CMakeFiles/fru-shared.dir/build.make CMakeFiles/fru-shared.dir/depend
make[2]: Entering directory `/root/frugen'
cd /root/frugen && /usr/bin/cmake3 -E cmake_depends "Unix Makefiles" /root/frugen /root/frugen
 /root/frugen /root/frugen /root/frugen/CMakeFiles/fru-shared.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/root/frugen'
make  -f CMakeFiles/fru-shared.dir/build.make CMakeFiles/fru-shared.dir/build
make[2]: Entering directory `/root/frugen'
[ 12%] Building C object CMakeFiles/fru-shared.dir/fru.c.o
/usr/bin/cc -DVERSION=\"v1.2.4.g3bad90e.dirty\" -D__HAS_JSON__ -Dfru_shared_EXPORTS  -fPIC   -o CMakeFiles/fru-shared.dir/fru.c.o   -c /root/frugen/fru.c
/root/frugen/fru.c:25:0: warning: "_BSD_SOURCE" redefined [enabled by default]
 #define _BSD_SOURCE
 ^
In file included from /usr/include/stdint.h:25:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/stdint.h:9,
                 from /root/frugen/fru.h:12,
                 from /root/frugen/fru.c:8:
/usr/include/features.h:188:0: note: this is the location of the previous definition
 # define _BSD_SOURCE 1
 ^
[ 25%] Linking C shared library libfru.so
/usr/bin/cmake3 -E cmake_link_script CMakeFiles/fru-shared.dir/link.txt --verbose=1
/usr/bin/cc -fPIC    -shared -Wl,-soname,libfru.so -o libfru.so CMakeFiles/fru-shared.dir/fru.c.o
make[2]: Leaving directory `/root/frugen'
[ 25%] Built target fru-shared
make  -f CMakeFiles/fru-static.dir/build.make CMakeFiles/fru-static.dir/depend
make[2]: Entering directory `/root/frugen'
cd /root/frugen && /usr/bin/cmake3 -E cmake_depends "Unix Makefiles" /root/frugen /root/frugen /root/frugen /root/frugen /root/frugen/CMakeFiles/fru-static.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/root/frugen'
make  -f CMakeFiles/fru-static.dir/build.make CMakeFiles/fru-static.dir/build
make[2]: Entering directory `/root/frugen'
[ 37%] Building C object CMakeFiles/fru-static.dir/fru.c.o
/usr/bin/cc -DVERSION=\"v1.2.4.g3bad90e.dirty\" -D__HAS_JSON__   -o CMakeFiles/fru-static.dir/fru.c.o   -c /root/frugen/fru.c
/root/frugen/fru.c:25:0: warning: "_BSD_SOURCE" redefined [enabled by default]
 #define _BSD_SOURCE
 ^
In file included from /usr/include/stdint.h:25:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/stdint.h:9,
                 from /root/frugen/fru.h:12,
                 from /root/frugen/fru.c:8:
/usr/include/features.h:188:0: note: this is the location of the previous definition
 # define _BSD_SOURCE 1
 ^
[ 50%] Linking C static library libfru.a
/usr/bin/cmake3 -P CMakeFiles/fru-static.dir/cmake_clean_target.cmake
/usr/bin/cmake3 -E cmake_link_script CMakeFiles/fru-static.dir/link.txt --verbose=1
/usr/bin/ar qc libfru.a  CMakeFiles/fru-static.dir/fru.c.o
/usr/bin/ranlib libfru.a
make[2]: Leaving directory `/root/frugen'
[ 50%] Built target fru-static
make  -f CMakeFiles/frugen-static.dir/build.make CMakeFiles/frugen-static.dir/depend
make[2]: Entering directory `/root/frugen'
cd /root/frugen && /usr/bin/cmake3 -E cmake_depends "Unix Makefiles" /root/frugen /root/frugen /root/frugen /root/frugen /root/frugen/CMakeFiles/frugen-static.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/root/frugen'
make  -f CMakeFiles/frugen-static.dir/build.make CMakeFiles/frugen-static.dir/build
make[2]: Entering directory `/root/frugen'
[ 62%] Building C object CMakeFiles/frugen-static.dir/frugen.c.o
/usr/bin/cc -DVERSION=\"v1.2.4.g3bad90e.dirty\" -D__HAS_JSON__   -o CMakeFiles/frugen-static.dir/frugen.c.o   -c /root/frugen/frugen.c
[ 75%] Linking C executable frugen-static
/usr/bin/cmake3 -E cmake_link_script CMakeFiles/frugen-static.dir/link.txt --verbose=1
/usr/bin/cc     -rdynamic CMakeFiles/frugen-static.dir/frugen.c.o  -o frugen-static  libfru.a -static -ljson-c -static 
/usr/bin/ld: cannot find -ljson-c
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
make[2]: *** [frugen-static] Error 1
make[2]: Leaving directory `/root/frugen'
make[1]: *** [CMakeFiles/frugen-static.dir/all] Error 2
make[1]: Leaving directory `/root/frugen'
make: *** [all] Error 2

Here's the rpm-qa output from the build VM I tried this on, so we have all package versioning. I can provide any other relevant output as well if needed.

@zetasyanthis zetasyanthis changed the title Linker errors on Centos 7 Linker errors on Centos 7 build Mar 19, 2021
@zetasyanthis
Copy link
Author

Oh, and I should note as a follow-up that I already touched up a different issue that caused this to blow up on that platform previously.

[root@centos7-worker01-aus frugen]# make
Scanning dependencies of target fru-shared
[ 12%] Building C object CMakeFiles/fru-shared.dir/fru.c.o
/root/frugen/fru.c:25:0: warning: "_BSD_SOURCE" redefined [enabled by default]
 #define _BSD_SOURCE
 ^
In file included from /usr/include/stdint.h:25:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/stdint.h:9,
                 from /root/frugen/fru.h:12,
                 from /root/frugen/fru.c:8:
/usr/include/features.h:188:0: note: this is the location of the previous definition
 # define _BSD_SOURCE 1
 ^
/root/frugen/fru.c: In function ‘calc_checksum’:
/root/frugen/fru.c:390:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
  for(int i = 0; i < blk_bytes; i++) {
  ^
/root/frugen/fru.c:390:2: note: use option -std=c99 or -std=gnu99 to compile your code
make[2]: *** [CMakeFiles/fru-shared.dir/fru.c.o] Error 1
make[1]: *** [CMakeFiles/fru-shared.dir/all] Error 2
make: *** [all] Error 2

Diff of that minor touchup, since trying to set c99 mode in CMake (which I don't know at all) caused some more explosions:

diff --git a/fru.c b/fru.c
index 8ca4c04..df39ca3 100644
--- a/fru.c
+++ b/fru.c
@@ -387,7 +387,8 @@ uint8_t calc_checksum(void *blk, size_t blk_bytes)
        uint8_t *data = (uint8_t *)blk;
        uint8_t checksum = 0;
 
-       for(int i = 0; i < blk_bytes; i++) {
+       int i;
+       for(i = 0; i < blk_bytes; i++) {
                checksum += data[i];
        }

@cristgal
Copy link

cristgal commented Mar 24, 2021

Fails on CentOS Stream release 8

# /usr/bin/cc   -rdynamic CMakeFiles/frugen-static.dir/frugen.c.o  -o frugen-static libfru.a -static -ljson-c -static
/usr/bin/ld: cannot find -ljson-c
collect2: error: ld returned 1 exit status

but json-c is installed

# rpm -ql json-c json-c-devel | egrep "\.so|json.h"
/usr/include/json-c/json.h
/usr/lib64/libjson-c.so
/usr/lib64/libjson-c.so.4
/usr/lib64/libjson-c.so.4.0.0

Works on Ubuntu 20.04 - Focal

# dpkg -L libjson-c-dev libjson-c4 | egrep "\.so|json.h"
/usr/include/json-c/json.h
/usr/lib/x86_64-linux-gnu/libjson-c.so
/usr/lib/x86_64-linux-gnu/libjson-c.so.4
/usr/lib/x86_64-linux-gnu/libjson-c.so.4.0.0

# /usr/bin/cc   -rdynamic CMakeFiles/frugen-static.dir/frugen.c.o  -o frugen-static libfru.a -static -ljson-c -static

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants