undefined reference to `pthread_key_create' (linker error)

前端 未结 5 700
庸人自扰
庸人自扰 2020-11-29 11:51

I have downloaded gtest 1.7.0 sources from here:

https://code.google.com/p/googletest/downloads/list

and build the gtest .a files (lib files) on ubuntu 13.10

5条回答
  •  情歌与酒
    2020-11-29 12:47

    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
    

提交回复
热议问题