0

I have the following problem. I'm trying to build tiny smb client on the base of the "libdsm" project. I have built necessary libraries (libdsm.a and libtasn1.a). My smb client sees these static libraries but linker informs me that I have undefined reference. This message is clear for me and I have verified that linked static library exists etc. I have no idea why it is happened. Are there any reasons why linker tells it? Which tools could I use to analyze this problem deeper? Below I show readelf information for built library

File: libdsm.a(md4.o)
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          15128 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           64 (bytes)
  Number of section headers:         23
  Section header string table index: 20


   17: 0000000000000000    97 FUNC    GLOBAL DEFAULT    1 smb_session_new
    18: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND calloc
    19: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND smb_buffer_init
    20: 0000000000000070    93 FUNC    GLOBAL DEFAULT    1 smb_session_destroy
    21: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND smb_session_share_clear
    22: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND asn1_delete_structure
    23: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND smb_buffer_free
    24: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND free
    25: 00000000000000d0   141 FUNC    GLOBAL DEFAULT    1 smb_session_set_creds
    26: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND __strndup
    27: 0000000000000160   463 FUNC    GLOBAL DEFAULT    1 smb_session_connect
    28: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND smb_transport_nbt

and object file of my tiny smb client:

ELF Header:


Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          2744 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           64 (bytes)
  Number of section headers:         15
  Section header string table index: 12


Symbol table '.symtab' contains 26 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
    12: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _Z15smb_session_newv
    13: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND inet_aton
    14: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _Z19smb_session_connectP1
    15: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _Z21smb_session_set_creds
    16: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _Z17smb_session_loginP11s
    17: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND puts
    18: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _Z16smb_tree_connectP11sm
    19: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _Z9smb_fopenP11smb_sessio
    20: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _Z9smb_freadP11smb_sessio
    21: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _Z10smb_fcloseP11smb_sess
    22: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _Z19smb_tree_disconnectP1
    23: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _Z19smb_session_destroyP1

I hope that this additional information will be useful.

alk
  • 69,737
  • 10
  • 105
  • 255
Roman Kazmin
  • 931
  • 6
  • 18
  • 1
    Please copy paste the error messages you get, and copy/paste the command line you used at the linking stage that produced those error messages. (You might just have a problem with the order of linking, which will be a lot easier to diagnose when we can see the same thing that you see on your screen) – nos Dec 29 '17 at 13:12
  • In general libs go last on GCC's command line. – alk Dec 29 '17 at 13:14
  • g++ -m64 -Wl,-O1 -o tinysmbclient main.o -L/usr/lib/x86_64-linux-gnu -lQtGui -lQtCore -lpthread main.o: In function `main': main.cpp:(.text.startup+0x1c): undefined reference to `smb_session_new()' main.cpp:(.text.startup+0x4d): undefined reference to `smb_session_connect(smb_session*, char const*, unsigned int, int)' – Roman Kazmin Dec 29 '17 at 13:17
  • Here is qt pro file: INCLUDEPATH += ../../3pp/samba/libdsm/include ../../3pp/samba/libtasn1-4.9/lib SOURCES += main.cpp – Roman Kazmin Dec 29 '17 at 13:20
  • So you want to link a C library to a C++ program? – alk Dec 29 '17 at 13:20
  • You might like to [read this](https://stackoverflow.com/q/12066279/694576). (see the accepted answer) – alk Dec 29 '17 at 13:22
  • yes. Also I forgot add LIBS += ../../3pp/samba/target/unix/libdsm.a ../../3pp/samba/target/unix/libtasn1.a in the pro file - but it didn't help. – Roman Kazmin Dec 29 '17 at 13:22

1 Answers1

0

alk, thank you for your advice. After renaming main.cpp to main.c all are Ok. For me it doesn't matter compile my client as c or c++ program.

Roman Kazmin
  • 931
  • 6
  • 18