-1

I met a c++ compile error that almost drives me mad these days. The output info is (/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: undefined reference to symbol '__libc_start_main@@GLIBC_2.2.5' //lib/x86_64-linux-gnu/libc.so.6: error adding symbols: DSO missing from command line

it's not undefined reference to `main', to be careful.)

The basic case is very simple. library B depends on library C. excutable A depends on library B, and thus depends on library C. Below is my code, it's very simple as well.

**c.h**
void kk();

**c.cpp**
#include <iostream>
using namespace std;

void kk()
{
    cout<<"111"<<endl;
} 

**b.h**
#include "c.h"
void pp();

**b.cpp**
#include "b.h"
void pp()
{
    kk();
}

**a.cpp**
#include "b.h"
int main()
{
    pp();
}

And This is my Compiling process: make c && b respectively to be a shared library, and build a through linking against them.

1. g++ -fpic -shared c.cpp -o libc.so
2. g++ -fpic -shared b.cpp -o libb.so
3. g++ a.cpp -o a -lb -lc -L. 

Besides,I tried many ways to solve this problem. None worked. And I found that in the fianl step, If I do not link library c, the output is the same.It seems that I failed to link c finally,But I just did it, who knows the reason. The g++ version??

caiyi.zcy
  • 1
  • 1
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Sep 27 '21 at 03:05
  • @Ken White The information of this link is too general. I have known multiple ways of undefined reference, including this one I asked today. But I do just linked the bottom library, The output info seems to tell me I did not. I also tried others' compiling procedure of the same case,But error still occurs,It finally makes doubt about g++ version. – caiyi.zcy Sep 27 '21 at 03:29
  • No, it's not. This site isn't for providing individual, specific information for every single question. That wouldn't be possible. It's your responsibility to take the information from that post and figure out how to apply it to your specific situation. – Ken White Sep 27 '21 at 03:31
  • I don't think my case belong to one of above link, to be frank..... – caiyi.zcy Sep 27 '21 at 03:34

1 Answers1

0

Your libc.so conflicts with the one installed by glibc. You would need to change to use another name

nhatnq
  • 1,173
  • 7
  • 16
  • Thanks!!!!I have never thought the name conflicts!!The problem almost drives me mad!!IBut I still has a problem. Since I have assign the directory where to search the library(-L.)。 Why g++ still use the libc.so from /usr/lib,not the one I produced?What's the search sequence? – caiyi.zcy Sep 27 '21 at 04:33
  • The standard one would be never used leading to the original issue. You cannot link the two libraries with the same name – nhatnq Sep 27 '21 at 04:39