Undefined Reference to Symbol 'Timer_Settime@@Glibc_2.3.3

undefined reference to symbol 'timer_settime@@GLIBC_2.3.3

Issue is solved by editing two files, Makefile and Makefile.target by adding

LIBS+=-lz -lrt -lm

Why am i still getting an undefined reference to timer_create() when i have included -lrt?

Libraries have to go after the object files that depend on them on the compiler command line, not at the beginning. So:

gcc -g -Wall -o scheduler scheduler.o worker.o list.o -lpthread -lrt 

Aside from that, you have a number of serious bugs in the source that you need to correct (see the warnings) before your program will work.

Interfacing Haskell and C++

Tried just linking to my answer on your other version of this question but it decided to automatically make it a comment... Not particularly helpful because people who find this thread in the future might just see it as unanswered so I'll paste the full answer instead.

Not sure whether that's actually in your file or whether it's just in the version you put in your question but "// hello.hs" won't compile. Comments are -- in Haskell not //.

Anyway on to the interesting part...

First you need to import the HsFFI.h header file into your C++ code.

#include <iostream>
#include "Hello_stub.h"
#include <HsFFI.h>

Then use ghc to link the files after compiling them. Open a command prompt / terminal and navigate the directory containing your C++ and Haskell files. Then run the following commands:

ghc -c -XForeignFunctionInterface -O hello.hs
g++ -c -O main.cpp -I "C:\Program Files\Haskell Platform\7.10.3\lib\include"
ghc -no-hs-main hello.o main.o -lstdc++

The filepath in the second command is to the directory containing the HsFFI.h file.

Running main then outputs:

Hello from C++
Hello from Haskell

undefined reference to symbol 'dlsym@@GLIBC_2.2.5'

I found out the "-ldl" link option was ignored because it was placed too early in the final c++ link command during make. So if you want to use external .so file and need to use libdl.so, you should configure qemu like this. (under qemu-5.1.0/build directory)

../configure --target-list=aarch64-softmmu --enable-debug --enable-gtk
--extra-ldflags="-Wl,--no-as-needed,-ldl"

The -Wl,--no-as-needed,-ldl part was added. (the others are for my needs). -as-needed is the default and it lists the needed library in the elf file. I tested it with just -ldl but it didn't work, hence the final command.

Undefined reference to timer_create even though -lrt included compile

I think the issue is that the libraries are at the front of the compile line instead at the end, but I am pretty unfamiliar with a Makefile like this.

Well, this is specific to GNU ld linker, not to make itself: ld resolves dependencies in a single pass from left to right, except between -Wl,--start-group and -Wl,--end-group (which intended specially for handling circular dependencies). This means that the libraries must be put after the modules (or another libraries) which use them.

How can I ensure the links come at the end instead of at the beginning?

Consider how it's done with (a simplified version of) the default rule:

%: %.o
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@

Here LDFLAGS are "normal" linker flags which can safely precede the objects list; and LDLIBS is the list of system libraries used by the program.

libpthread.so.0: error adding symbols: DSO missing from command line

You should mention the library on the command line after the object files being compiled:

 gcc -Wstrict-prototypes -Wall -Wno-sign-compare -Wpointer-arith -Wdeclaration-after-statement -Wformat-security -Wswitch-enum -Wunused-parameter -Wstrict-aliasing -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers -Wno-override-init \
-g -O2 -export-dynamic -o utilities/ovs-dpctl utilities/ovs-dpctl.o \
lib/libopenvswitch.a \
/home/jyyoo/src/dpdk/build/lib/librte_eal.a /home/jyyoo/src/dpdk/build/lib/libethdev.a /home/jyyoo/src/dpdk/build/lib/librte_cmdline.a /home/jyyoo/src/dpdk/build/lib/librte_hash.a /home/jyyoo/src/dpdk/build/lib/librte_lpm.a /home/jyyoo/src/dpdk/build/lib/librte_mbuf.a /home/jyyoo/src/dpdk/build/lib/librte_ring.a /home/jyyoo/src/dpdk/build/lib/librte_mempool.a /home/jyyoo/src/dpdk/build/lib/librte_malloc.a \
-lrt -lm -lpthread

Explanation: the linking is dependent on the order of modules. Symbols are first requested, and then linked in from a library that has them. So you have to specify modules that use libraries first, and libraries after them. Like this:

gcc x.o y.o z.o -la -lb -lc

Moreover, in case there's a circular dependency, you should specify the same library on the command line several times. So in case libb needs symbol from libc and libc needs symbol from libb, the command line should be:

gcc x.o y.o z.o -la -lb -lc -lb


Related Topics



Leave a reply



Submit