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!
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
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
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!
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.