Undefined Reference to Symbol 'Pthread_Key_Delete@@Glibc_2.2.5

undefined reference to `pthread_key_create' (linker error)

The option -lgtest is attempting to link the dynamic library libgtest.so. You
wish to link the static library /home/user/gtest-1.7.0/lib/.libs/libgtest.a.

Instead of:

g++ main.cpp -I/home/user/gtest-1.7.0/include -L/home/user/gtest-1.7.0/lib/.libs -lgtest -pthread

use:

g++ main.cpp -I/home/user/gtest-1.7.0/include /home/user/gtest-1.7.0/lib/.libs/libgtest.a -pthread

Note that your commandline supplies no name for the resulting executable, which will default
to a.out. If you want it called, e.g. mytest, then do:

g++ -o mytest main.cpp -I/home/user/gtest-1.7.0/include /home/user/gtest-1.7.0/lib/.libs/libgtest.a -pthread

undefined reference to `pthread_getspecific' when using cmake for googletest

There is a problem at link-time.

It is only an assumption: did you try this?

target_link_libraries(test gmock gtest pthread)

instead of your version:

target_link_libraries(test pthread)
target_link_libraries(test gmock)
target_link_libraries(test gtest)

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

glfw3 error: DSO Missing from command line

It looks like the missing symbol is from libdl.

As an added bonus, I'm going to give you a Makefile. Remember to indent with tabs, NOT spaces, otherwise the Makefile won't work.

all: out
clean:
rm -f out *.o
.PHONY: all clean

CXX = g++
CPPFLAGS =
CXXFLAGS = -std=c++11 -Wall -Wextra -g
LIBS = -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -pthread -lXi -ldl
LDFLAGS =

out: main.o
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)

However, it would be a lot easier if you used pkg-config. I don't know off the top of my head the right command (I'm not on Linux now so I can't check), but it will look like this:

packages = glfw3
CPPFLAGS := $(shell pkg-config --cflags $(packages))
LIBS := $(shell pkg-config --libs $(packages))

This way you won't have to even know that you need -ldl, because pkg-config will figure it out for you. This is the standard way of doing things.

Try running pkg-config --libs glfw3 for yourself to see the output. If it's not installed, run sudo apt-get install pkg-config.



Related Topics



Leave a reply



Submit