ZooKeeper C binding installation - c

I am trying to install the C binding for ZooKeeper while ssh'ed to another computer using a build system: i386-pc-solaris2.11 (I don't know if that is important). Anyways, the computer I ssh'ed to is running a linux based OS.
I ran the following code in the command line:
cd ../zookeeper
cd src
cd c
./configure
make
The terminal inputs above were taken from the Apache website for setting up the C shell client. The error code I am getting is originates from the make:
libtool: link: ( cd ".libs" && rm -f "libzookeeper_mt.la" && ln -s
"../libzookeeper_mt.la" "libzookeeper_mt.la" )
gcc -DHAVE_CONFIG_H -I. -I./include -I./tests -I./generated -
D_POSIX_PTHREAD_SEMANTICS -Wall -Werror -g -O2 -D_GNU_SOURCE -MT cli.o
-MD -MP -MF .deps/cli.Tpo -c -o cli.o `test -f 'src/cli.c' || echo
'./'`src/cli.c
mv -f .deps/cli.Tpo .deps/cli.Po
/bin/sh ./libtool --tag=CC --mode=link gcc -Wall -Werror -g -O2 -
D_GNU_SOURCE -o cli_st cli.o libzookeeper_st.la
libtool: link: gcc -Wall -Werror -g -O2 -D_GNU_SOURCE -o .libs/cli_st
cli.o ./.libs/libzookeeper_st.so -lnsl -lsocket -lm -R/usr/local/lib
gcc -DHAVE_CONFIG_H -I. -I./include -I./tests -I./generated -
D_POSIX_PTHREAD_SEMANTICS -DTHREADED -g -O2 -D_GNU_SOURCE -MT cli_mt-
cli.o -MD -MP -MF .deps/cli_mt-cli.Tpo -c -o cli_mt-cli.o `test -f
'src/cli.c' || echo './'`src/cli.c
mv -f .deps/cli_mt-cli.Tpo .deps/cli_mt-cli.Po
/bin/sh ./libtool --tag=CC --mode=link gcc -DTHREADED -g -O2 -
D_GNU_SOURCE -o cli_mt cli_mt-cli.o libzookeeper_mt.la
libtool: link: gcc -DTHREADED -g -O2 -D_GNU_SOURCE -o .libs/cli_mt
cli_mt-cli.o ./.libs/libzookeeper_mt.so -lnsl -lsocket -lm -lpthread -
R/usr/local/lib
Undefined first referenced
symbol in file
__ .sync_fetch_and_add ./.libs/libzookeeper_mt.so
ld: fatal: symbol referencing errors. No output written to .libs/cli_mt
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `cli_mt'
Current working directory
/workspace/kunalp/mysource/usr/src/kunalp/zookeeperC2/src/c
*** Error code 1
make: Fatal error: Command failed for target `all'
cli_mt:localhost:2181 does not work as the ZooKeeper library is not installed in /usr/local/lib . I do however have zookeeper working in the C client on my local computer, I just need it working on this system.
Please help, this is just the installation of zookeeper on a linux computer. I don't understand linux too well, nor do I understand the error code given to me from this makefile.
EDIT: I figured out that I do not have permissions to change the /usrs/local/lib directory on this server. I tried
distclean && ./configure --prefix=/workspace/kunalp/zookeeper/ --libdir=/workspace/kunalp/zookeeper/lib && make install
to relocate the library directory. This however did not fix the problem, giving me the following error:
/bin/sh ./libtool --tag=CC --mode=link gcc -DTHREADED -g -O2 -
D_GNU_SOURCE -o cli_mt cli_mt-cli.o libzookeeper_mt.la
libtool: link: gcc -DTHREADED -g -O2 -D_GNU_SOURCE -o .libs/cli_mt
cli_mt-cli.o ./.libs/libzookeeper_mt.so -lnsl -lsocket -lm -lpthread -
R/workspace/kunalp/zookeeper/lib
Undefined first referenced
symbol in file
__sync_fetch_and_add ./.libs/libzookeeper_mt.so
ld: fatal: symbol referencing errors. No output written to .libs/cli_mt
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `cli_mt'
Thanks

The Solaris compiler does not have __sync_fetch_and_add. To fix this I had to find an equivalent function in the Solaris compailer: atomic_add() and replace __sync_fetch_and_add with atomic_add() in mt_adaptor.c. This fixed my make command

Related

When I compile simpleleveldb in simplehttp family, here is a ld error but I have no idea about it

I run it on Linux with x86/64 and ubuntu 2204, gcc version 11.2.0, GNU ld version 2.38.
When I run env LIBLEVELDB=/usr/local make in simpleleveldb dir and get this error:
cc -I. -I../simplehttp/.. -I/usr/local/include -I/usr/local/include -Wall -g -O2 -MM -MT simpleleveldb -MF simpleleveldb.deps simpleleveldb.c str_list_set.c
cc -I. -I../simplehttp/.. -I/usr/local/include -I/usr/local/include -Wall -g -O2 -o simpleleveldb simpleleveldb.c str_list_set.c -L. -L../simplehttp -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -levent -ljson-c -lsimplehttp -lleveldb -lm -lstdc++ -lsnappy -lpthread
/usr/bin/ld: /usr/local/lib/libsimplehttp.a(request.o):/home/zhdi/simplehttp/simplehttp/request.h:12: multiple definition of `simplehttp_reqs'; /usr/local/lib/libsimplehttp.a(simplehttp.o):/home/zhdi/simplehttp/simplehttp/request.h:12: first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:26: simpleleveldb] Error 1
before do it I just build simplehttp follow this repo https://github.com/bitly/simplehttp.
Anyone has some idea? thanks!

GCC undefined reference to `addition'

I'm trying to link an external library but not linking. Using gcc version:
gcc (MinGW.org GCC Build-2) 9.2.0
Windows 10
Command I'm tried:
gcc -g test.c -Wall -I ../inc/ -L ../lib -l:libFp.a -o test.exe
gcc -g test.c -Wall -I ../inc/ -L ../lib64 -l:libFp.a -o test.exe
gcc -g -Wall -I ../inc/ -L ../lib -l:libFp.a test.c -o test.exe
gcc -g -Wall ../lib/libFp.a test.c -I ../inc/ -o test.exe
Error:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\XXXXXXXX\AppData\Local\Temp\cciWnORn.o: in function `main':
D:\C_Training\utils\XXXXXXXX\testApp/test.c:35: undefined reference to `addition'
collect2.exe: error: ld returned 1 exit status
Folder Hierarchy:
XXXX
==docs
==inc
==lib
--libFp.a
--fP.lib
==lib64
--libFp.a
==src
==testApp [cwd]
--test.c
Tried different solutions from StackOverflow but still same error.
Update: gcc -g -Wall -I ../inc -L ../lib test.c -o test.exe -lFp -Xlinker --verbose command output
Linker Output Verbose

Failed to do 'make' on .c and .s files using Mac

I'm trying to compile a simple project with .c and .s files using my Mac.
When I run 'make' it goes threw on the compilation, and I think it failed when its trying to link (not sure).
Here is the error it shows:
gcc -m32 -g -Wall -c -o main.o main.c
gcc -m32 -g -Wall -c -o numbers.o numbers.c
nasm -g -f macho -w+all -o add.o add.s
gcc -m32 -g -Wall -o run main.o numbers.o add.o
ld: malformed file
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd:4:18: error: unknown enumerated scalar
platform: zippered
^~~~~~~~
file '/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [run] Error 1
and I'll add the makefile as well:
run: main.o numbers.o add.o
gcc -m32 -g -Wall -o run main.o numbers.o add.o
main.o: main.c
gcc -m32 -g -Wall -c -o main.o main.c
numbers.o: numbers.c
gcc -m32 -g -Wall -c -o numbers.o numbers.c
add.o: add.s
nasm -g -f macho -w+all -o add.o add.s
.PHONY: clean
clean:
rm -f *.o run

installing libcerf throws error when entering make

I need to use the erfi function in my C program, so I tried to install the libcerf library, where it is supposed to be contained. I downloaded it, went to the directory and entered ./configure. So far so good. Now when I enter 'make' it gives me the following error:
`localhost:libcerf-1.3 NAME$ make
/Applications/Xcode.app/Contents/Developer/usr/bin/make all-recursive
Making all in lib
/bin/sh ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I.. -pedantic -Wall -Werror -g -O2 -MT w_of_z.lo -MD -MP -MF .deps/w_of_z.Tpo -c -o w_of_z.lo w_of_z.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -pedantic -Wall -Werror-g -O2 -MT w_of_z.lo -MD -MP -MF .deps/w_of_z.Tpo -c w_of_z.c -fno-common -DPIC -o .libs/w_of_z.o
w_of_z.c:79:21: error: unused function 'cpolar' [-Werror,-Wunused-function]
static inline cmplx cpolar(double r, double t)
^
1 error generated.
make[2]: *** [w_of_z.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
There seems to be some problem with an unused function. This confuses me since this is the only way known to me to install libraries and I did not really do anything but the ./configure command. Yet it doesnt work. Additionally, I can't help myself with the output I get. I have tried googling it but could not get any further. I am using a Mac. Any help is appreciated.
Thanks a lot!

Linker errors in a basic Apache module

I am attempting to write a "hello world" module for Apache HTTPD 2.4. I'm receiving some linker errors when building the module, and many Google searches have not revealed a solution.
My questions are:
How can I resolve the ap_hook_handler linker error? I've searched through the Apache Portable Runtime source and headers and have not found it.
Why is there an undefined reference to main? I thought shared objects don't have a main() entry point.
The source code:
// Dependancies: apr-devel apr-util-devel
#include <httpd.h>
#include <http_config.h>
#include <apr_hooks.h>
static int test_handler(request_rec* request)
{
return OK;
}
static void register_hooks(apr_pool_t *pool)
{
ap_hook_handler(test_handler, NULL, NULL, APR_HOOK_LAST);
}
module AP_MODULE_DECLARE_DATA test_module =
{
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
register_hooks
};
The build command:
apxs -lapr-1 -laprutil-1 -c test.c -o mod_test.so
The errors:
apxs -lapr-1 -laprutil-1 -c test.c -o mod_test.so
/usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wformat-security -fno-strict-aliasing -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd -I/usr/include/apr-1 -I/usr/include/apr-1 -c -o test.lo test.c && touch test.slo
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -o test.la -lapr-1 -laprutil-1 -rpath /usr/lib64/httpd/modules -module -avoid-version test.lo -o mod_test.so
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
.libs/test.o: In function `register_hooks':
/root/test/test.c:14: undefined reference to `ap_hook_handler'
collect2: ld returned 1 exit status
apxs:Error: Command failed with rc=65536
The order matters and the filenames have to go last:
apxs -c -o mod_test.so test.c
To install it automatically:
apxs -i -c -o mod_test.so -c test.c
This should work
As Ctx said, the order of parameters really matters. I use the following format of the APXS:
$APACHE/bin/apxs -c -a -i mod_test.c
what compiles, adds and installs the test module. It produces this output:
/usr/local/apr/build-1/libtool --silent --mode=compile gcc -prefer-pic -DLINUX -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I$APACHE_HOME/include -I/usr/local/apr/include/apr-1 -I/usr/local/apr/include/apr-1 -c -o mod_test.lo mod_test.c && touch mod_test.slo
/usr/local/apr/build-1/libtool --silent --mode=link gcc -o mod_test.la -rpath $APACHE_HOME/modules -module -avoid-version mod_test.lo
ar: `u' modifier ignored since `D' is the default (see `U')
$APACHE_HOME/build/instdso.sh SH_LIBTOOL='/usr/local/apr/build-1/libtool' mod_test.la $APACHE_HOME/modules
/usr/local/apr/build-1/libtool --mode=install install mod_test.la $APACHE_HOME/modules/
libtool: install: install .libs/mod_test.so $APACHE_HOME/modules/mod_test.so
libtool: install: install .libs/mod_test.lai $APACHE_HOME/modules/mod_test.la
libtool: install: install .libs/mod_test.a $APACHE_HOME/modules/mod_test.a
libtool: install: chmod 644 $APACHE_HOME/modules/mod_test.a
libtool: install: ranlib $APACHE_HOME/modules/mod_test.a
libtool: finish:
----------------------------------------------------------------------
Libraries have been installed in:
$APACHE_HOME/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 $APACHE_HOME/modules/mod_test.so
[activating module `test' in $APACHE_HOME/conf/httpd.conf]
By providing the -o option you can get rid of undefined reference to main error message.

Resources