Error gcc - undefined reference to symbol '__getauxval##GLIBC_2.17' - c

Hello everyone.
I am trying to compile simple C code.
#include <stdio.h>
void main()
{
printf("Hello world\n");
}
But I get this error.
$ gcc main.c
/data/data/com.termux/files/usr/bin/ld: /data/data/com.termux/files/usr/bin/../lib/gcc/aarch64-unknown-linux-gnu/10.2.0/libgcc.a(lse-init.o): undefined reference to symbol '__getauxval##GLIBC_2.17'
/data/data/com.termux/files/usr/bin/ld: /data/data/com.termux/files/usr/lib/libc.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
I understand that the error occurs due to the fact that the compidator cannot find the font, but this is not accurate. And the same error occurs in C++.
How do I fix this error?

In short, this error occurs due to the fact that libraries of type libc were not in the common directory.
These libraries:
-rwxr-xr-x 1 10504 10504 1827624 Aug 4 16:27 /lib/conlib/libc-2.32.so
-rw-r--r-- 1 10504 10504 4592750 Aug 4 16:27 /lib/conlib/libc.a
-rw-r--r-- 1 10504 10504 351 Aug 4 16:27 /lib/conlib/libc.so
lrwxrwxrwx 1 10504 10504 18 Aug 4 16:27 /lib/conlib/libc.so.6 -> libc-2.32.so
-rw-r--r-- 1 10504 10504 24964 Aug 4 16:27 /lib/conlib/libc_nonshared.a

Related

rpcgen only one argument is allowed error

I'm writing a simple client-server calculator with rpcgen and am having a compilation error. Here's the .x file (calculadora.x):
union resultado_calculo switch (int err)
{
case 0:
int resultado;
default:
void;
};
program CALCULADORA_PROG
{
version CALCULADORA_VER
{
resultado_calculo Suma (int, int) = 1;
resultado_calculo Resta (int, int) = 2;
resultado_calculo Producto (int, int) = 3;
resultado_calculo Cociente (int, int) = 4;
} = 1;
} = 20000001;
Running rpcgen -NCa calculadora.x creates the following files:
total 40K
drwxr-xr-x 2 groctel groctel 4.0K Mar 23 16:40 .
drwxr-xr-x 3 groctel groctel 4.0K Mar 23 16:10 ..
-rw-r--r-- 1 groctel groctel 1.3K Mar 23 16:27 calculadora_client.c
-rw-r--r-- 1 groctel groctel 1.9K Mar 23 16:22 calculadora_clnt.c
-rw-r--r-- 1 groctel groctel 1.1K Mar 23 15:56 calculadora_server.c
-rw-r--r-- 1 groctel groctel 3.5K Mar 23 16:22 calculadora_svc.c
-rw-r--r-- 1 groctel groctel 1.2K Mar 23 16:23 Makefile.calculadora
-rw-r--r-- 1 groctel groctel 2.7K Mar 23 16:22 calculadora.h
-rw-r--r-- 1 groctel groctel 348 Mar 23 16:22 calculadora.x
Now, I've filled the client and server's templates and run the program several times. I have to compile with make CFLAGS+="-I/usr/include/tirpc -ltirpc" -f Makefile.calculadora to include my system's rpc library but no real problems there. I've also run the program a few times and all the operations run well (./calculadora 3 + 2 returns 5 for example).
However, I went to make the program again today and I'm getting the following output:
➜ make CFLAGS+="-I/usr/include/tirpc -ltirpc" -f Makefile.calculadora
rpcgen calculadora.x
resultado_calculo Suma (int, int) = 1;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
calculadora.x, line 13: only one argument is allowed
make: *** [Makefile.calculadora:32: calculadora_xdr.c] Error 1
I don't understand why the error is appearing now and not before, since the program was running perfectly just yesterday. Here's the Suma function that I'm compiling:
resultado_calculo *
suma_1_svc(int arg1, int arg2, struct svc_req *rqstp)
{
static resultado_calculo result;
xdr_free(xdr_resultado_calculo, &result);
result.resultado_calculo_u.resultado = arg1 + arg2;
return &result;
}
The other functions are the exact same with different operators (-, * and /). What am I doing wrong?
You need to use the -N option to allow multiple arguments. From the documentation:
-N
Use the newstyle of rpcgen. This allows procedures to have multiple arguments. It also uses the style of parameter passing that closely resembles C. So, when passing an argument to a remote procedure you do not have to pass a pointer to the argument but the argument itself. This behaviour is different from the oldstyle of rpcgen generated code. The newstyle is not the default case because of backward compatibility.
Prior to this feature, the way you passed multiple arguments was by packing them into a structure and passing a pointer to the structure.

/usr/bin/ld: cannot find -lruby

I hope build ruby c extension with cmake, but I get /usr/bin/ld: cannot find -llibruby in console, here is my code:
CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
file(GLOB cs *.c)
include_directories($ENV{HOME}/.rbenv/versions/2.2.3/include/ruby-2.2.0/x86_64-linux
$ENV{HOME}/.rbenv/versions/2.2.3/include/ruby-2.2.0)
foreach (c ${cs})
get_filename_component(exe ${c} NAME_WE)
add_executable(${exe} ${cs})
endforeach ()
add_library(mytest SHARED MyTest.c)
link_directories($ENV{HOME}/.rbenv/versions/2.2.3/lib)
find_library(ruby NAMES ruby)
target_link_libraries(mytest ruby)
and here is ruby lib:
roroco#roroco-Zhaoyang-K49 ~/Dropbox/rbs/ro_plans $ lsa ~/.rbenv/versions/2.2.3/lib
total 61424
drwxr-xr-x 4 roroco roroco 4096 Nov 21 23:49 .
drwxr-xr-x 6 roroco roroco 4096 Oct 13 22:10 ..
lrwxrwxrwx 1 roroco roroco 16 Nov 21 23:49 libruby.so -> libruby.so.2.2.0
lrwxrwxrwx 1 roroco roroco 16 Nov 21 23:49 libruby.so.2.2 -> libruby.so.2.2.0
-rwxr-xr-x 1 roroco roroco 13573794 Nov 21 23:49 libruby.so.2.2.0
-rw-r--r-- 1 roroco roroco 49306632 Nov 21 23:47 libruby-static.a
drwxr-xr-x 2 roroco roroco 4096 Nov 21 23:49 pkgconfig
drwxr-xr-x 6 roroco roroco 4096 Oct 13 22:10 ruby

Error compiling kernel module, fatal error: linux/modversions.h: File or directory not found

i'm trying to compile a simple test kernel module but gcc drop me this error:
fatal error: linux/modversions.h: file or directory not found
but in
/usr/src contains the symlink to the linux souce indeed
ls -l /usr/scr/
drwxr-xr-x 2 root root 4096 apr 26 13:31 fglrx-14.9+ga14.201
lrwxrwxrwx 1 root root 39 lug 11 13:36 linux -> /home/nhoya/Scaricati/linux-source-3.16
drwxr-xr-x 2 root root 4096 lug 10 17:49 linux-config-3.16
drwxr-xr-x 4 root root 4096 lug 10 15:57 linux-headers-3.2.0-4-amd64
drwxr-xr-x 4 root root 4096 apr 26 22:24 linux-headers-3.2.0-4-common
lrwxrwxrwx 1 root root 23 giu 24 2012 linux-kbuild-3.2 -> ../lib/linux-kbuild-3.2
-rw-r--r-- 1 root root 81869308 mag 24 20:24 linux-source-3.16.tar.xz
drwxr-xr-x 12 root root 4096 giu 7 23:31 virtualbox-4.3.18
and
locate modversions.h
/home/nhoya/Scaricati/linux-source-3.16/include/config/modversions.h
/usr/src/linux-headers-3.2.0-4-amd64/include/config/modversions.h
So, i really don't understand the problem... this is the module source
#define __KERNEL__
#define MODULE
#include <linux/modversions.h>
#include <linux/module.h>
#include <linux/tty.h>
int init_mod()
{
console_print("test\n");
return 0;
}
void cleanup_mod()
{
console_print("fine test\n");
}

How to link shared library in Makefile

I am trying to make the following makefile on olaris SPARC
CC=/usr/sfw/bin/gcc
INCPATH=/export/home/compkvar/compile/inc
LIBPATH=/export/home/compkvar/compile/lib
SOURCEPATH=/export/home/compkvar/compile/src
.c.o:
$(CC) -c $< $(INCPATH) -I.
PSOURCE = driver.c
driver : driver.o
$(CC) -I$(INCPATH) -L$(LIBPATH) -o driver driver.c -lprivate
all : driver
clean :
rm driver.o driver
but i got error the following ;
/usr/sfw/bin/gcc -I/export/home/compkvar/compile/inc -L/export/home/compkvar/compile/lib -o driver driver.c -lprivate
Undefined first referenced
symbol in file
isinf /export/home/compkvar/compile/lib/libprivate.so
ld: fatal: Symbol referencing errors. No output written to driver
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `driver'
libprivate.so shared library is exist under '/export/home/compkvar/compile/lib' path but it couldn't found:
bash-3.00$ pwd
/export/home/compkvar/compile/lib
bash-3.00$ ls -latr
total 14116
drwxr-xr-x 2 compkvar other 512 Sep 12 15:34 .
drwxr-xr-x 5 compkvar other 512 Sep 12 15:34 ..
-rwxrwxrwx 1 compkvar other 761180 Sep 12 15:43 libprivate.so
-rwxrwxrwx 1 compkvar other 2275492 Sep 12 15:43 libPricingFunctions.so
-rwxrwxrwx 1 compkvar other 1104576 Sep 12 15:43 libprfUtilities.a
-rwxrwxrwx 1 compkvar other 2275492 Sep 12 15:43 libPricingFunctions.so.1
-rwxrwxrwx 1 compkvar other 761180 Sep 12 15:43 libprivate.so.1
bash-3.00$
Thanks in advance.
isinf is part of math library. Try including -lm.
$(CC) -I$(INCPATH) -L$(LIBPATH) -o driver driver.c -lprivate -lm

GCC: Linking a dylib on Mac Os

gcc is unable to find a dynamic library if I don't specify its path explicitly. First of all I'm using libmemcached which I've got installed with brew.
17:27:14 shell% ls -la /usr/local/lib/libmemcached*
lrwxr-xr-x 1 user wheel 55 Sep 2 12:42 /usr/local/lib/libmemcached.11.dylib -> ../Cellar/libmemcached/1.0.17/lib/libmemcached.11.dylib
lrwxr-xr-x 1 user wheel 48 Sep 2 12:42 /usr/local/lib/libmemcached.a -> ../Cellar/libmemcached/1.0.17/lib/libmemcached.a
lrwxr-xr-x 1 user wheel 52 Sep 2 12:42 /usr/local/lib/libmemcached.dylib -> ../Cellar/libmemcached/1.0.17/lib/libmemcached.dylib
lrwxr-xr-x 1 user wheel 58 Sep 2 12:42 /usr/local/lib/libmemcachedutil.2.dylib -> ../Cellar/libmemcached/1.0.17/lib/libmemcachedutil.2.dylib
lrwxr-xr-x 1 user wheel 52 Sep 2 12:42 /usr/local/lib/libmemcachedutil.a -> ../Cellar/libmemcached/1.0.17/lib/libmemcachedutil.a
lrwxr-xr-x 1 user wheel 56 Sep 2 12:42 /usr/local/lib/libmemcachedutil.dylib -> ../Cellar/libmemcached/1.0.17/lib/libmemcachedutil.dylib
My hellomemcached.c looks like this:
#include <libmemcached/memcached.h>
int main ()
{
memcached_return_t rc;
memcached_server_st* servers = NULL;
memcached_st* memcached;
// initialize the memcached structure
memcached = memcached_create(NULL);
if (!memcached)
return 0;
}
The compilation with the following command ends with success:
gcc -arch x86_64 /usr/local/lib/libmemcached.dylib -I/usr/local/include -o hellomemcached hellomemcached.c
But if I try to compile it with a path to the folder, which contains the library:
gcc -arch x86_64 -L/usr/local/lib -I/usr/local/include -o hellomemcached hellomemcached.c
I get an error:
Undefined symbols for architecture x86_64:
"_memcached_create", referenced from:
_main in ccYCwHa6.o
ld: symbol(s) not found for architecture x86_64
Apparently it can't find the library in that case. What I'm doing wrong?
Add -lmemcached at the very end when compiling.

Resources