GCC undefined reference to `addition' - c

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

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!

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

ZooKeeper C binding installation

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

error: linker command failed with exit code 1 (use -v to see invocation) Compile Failure. Quit

/usr/bin/gcc -DEVAL -std=c11 -O2 -pipe -static -s -o Tutorial Tutorial.c -lm
this command line (right on linux) don't run on macOS,
How can i change this command line?
UPDATE: the command line that doesn't work is
gcc -DEVAL -static -std=c11 -O2 -pipe -s -o main.out $1 -lm -g

Cython and cross-compilation

I have a file test.pyx and a test.c generated by $ cython test.pyx. I want to create a shared object test.so with gcc so that I can import it into Python. Compilation for linux x86-64 with
gcc -Wall -fPIC -I /usr/include/python2.7 -shared -o test.so test.c
Terminates successfully.
I want to compile the same file to a .dll for windows with mingw32. However when I attempt to execute
i586-mingw32msvc-gcc -Wall -fPIC -I /usr/include/python2.7 -shared -o test.dll test.c
I get this error:
test.c:1: warning: -fPIC ignored for target (all code is position independent)
In file included from /usr/include/python2.7/Python.h:58,
from test.c:16:
/usr/include/python2.7/pyport.h:338:24: error: sys/select.h: No such file or directory
Am I doing something wrong?
You do this with it:
<your_compiler> <cython_generated_c_file> -o <your_outputfilename> -fPIE -lpython<python_version>
<cflags> <ldflags>
To get cflags:
python-config --cflags
For ldflags:
python-config --ldflags

Resources