When GCC compiles, undefined reference to appears

1. Under folder A, there is a folder B
2. Generate static libraries in folder B, assuming that the ld.a, source code is written in C
3. The .CPP file in folder A, a function that references the source code in folder B, and links to the static library at compile time
4. Compile the code in file A with gPP, but there will be an error:

    main.cpp:(.text+0x120e): undefined reference to `OpenConf()"

5. Looking at the symbols of the static library ld.a, it is found that OpenConf exists

    0000000000000c00   276 FUNC    GLOBAL DEFAULT    1 OpenConf

6. Execute the command: objdump-d-r main.o related information:

    120d:    e8 00 00 00 00           callq  1212 <main+0x22e>
    120e: R_X86_64_PLT32    _Z8OpenConfv-0x4

7. Execute command: readelf-r main.o related information:

    00000000120e  00d500000004 R_X86_64_PLT32    0000000000000000 _Z8OpenConfv - 4
    
    
When

compiles, the link to the library does not report an error, which is correct. Now do not know how to debug, how to find errors?


when using C library functions in CPP, did you add extern "C" {}? Otherwise, the link will not be found.

Menu