c++ - gcc undefined reference 即使 ld 找到库并且它包含所需的函数

标签 c++ gcc linker ld

我从事许多项目,我必须为此交叉编译许多库,有些是内部的,有些不是。在为我们的一个系统开发交叉编译的应用程序时,我不得不为我的应用程序导入一些交叉编译的内部库。我正在为 Eclipse 中的应用程序使用 autotools。无论我是否在 Eclipse 中,问题都会发生。不管我编译的平台是什么,它都会发生,所以我的所有不同版本的 gcc 都会遇到相同的链接错误。当我编译应用程序时,各个模块 (*.c) 编译正常,但是当发出最终 gcc 命令将所有内容链接到最终程序时,我收到“对 GetCanMpdConfig 的 undefined reference ”错误。

现在,最重要的是:链接器实际上找到了文件(我已经用 -Wl,--verbose 验证了这一点,让 gcc 打印链接描述文件)。我将您的注意力特别引向有关 -lcanmpdconf 的行:

Making clean in src
make[1]: Entering directory `/home/amarshall3/workspace/can_mpd/src'
test -z "can_mpd" || rm -f can_mpd
rm -f *.o
make[1]: Leaving directory `/home/amarshall3/workspace/can_mpd/src'
make[1]: Entering directory `/home/amarshall3/workspace/can_mpd'
make[1]: Nothing to be done for `clean-am'.
make[1]: Leaving directory `/home/amarshall3/workspace/can_mpd'
Making all in src
make[1]: Entering directory `/home/amarshall3/workspace/can_mpd/src'
i686-linux-gnu-g++ -DPACKAGE_NAME=\"can_mpd\" -DPACKAGE_TARNAME=\"can_mpd\" -DPACKAGE_VERSION=\"1.13\" -DPACKAGE_STRING=\"can_mpd\ 1.13\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPLATFORM=generic_x86 -I.    -DBUILDSTAMP="\"`date '+%F %T'`\"" -I../dependencies/canmpdconf/1.0/generic_x86/include -I../dependencies/mow2monitor/1.0/generic_x86/include -DGENERIC_X86   -g -ggdb -O0 -Wall -Wl,--verbose -MT can_mpd-can_mpd.o -MD -MP -MF .deps/can_mpd-can_mpd.Tpo -c -o can_mpd-can_mpd.o `test -f 'can_mpd.cpp' || echo './'`can_mpd.cpp
mv -f .deps/can_mpd-can_mpd.Tpo .deps/can_mpd-can_mpd.Po
i686-linux-gnu-g++ -DPACKAGE_NAME=\"can_mpd\" -DPACKAGE_TARNAME=\"can_mpd\" -DPACKAGE_VERSION=\"1.13\" -DPACKAGE_STRING=\"can_mpd\ 1.13\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPLATFORM=generic_x86 -I.    -DBUILDSTAMP="\"`date '+%F %T'`\"" -I../dependencies/canmpdconf/1.0/generic_x86/include -I../dependencies/mow2monitor/1.0/generic_x86/include -DGENERIC_X86   -g -ggdb -O0 -Wall -Wl,--verbose -MT can_mpd-mpd_can.o -MD -MP -MF .deps/can_mpd-mpd_can.Tpo -c -o can_mpd-mpd_can.o `test -f 'mpd_can.cpp' || echo './'`mpd_can.cpp
mv -f .deps/can_mpd-mpd_can.Tpo .deps/can_mpd-mpd_can.Po
i686-linux-gnu-g++ -DPACKAGE_NAME=\"can_mpd\" -DPACKAGE_TARNAME=\"can_mpd\" -DPACKAGE_VERSION=\"1.13\" -DPACKAGE_STRING=\"can_mpd\ 1.13\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPLATFORM=generic_x86 -I.    -DBUILDSTAMP="\"`date '+%F %T'`\"" -I../dependencies/canmpdconf/1.0/generic_x86/include -I../dependencies/mow2monitor/1.0/generic_x86/include -DGENERIC_X86   -g -ggdb -O0 -Wall -Wl,--verbose -MT can_mpd-mpd_multiplexing.o -MD -MP -MF .deps/can_mpd-mpd_multiplexing.Tpo -c -o can_mpd-mpd_multiplexing.o `test -f 'mpd_multiplexing.cpp' || echo './'`mpd_multiplexing.cpp
mv -f .deps/can_mpd-mpd_multiplexing.Tpo .deps/can_mpd-mpd_multiplexing.Po
i686-linux-gnu-g++ -DPACKAGE_NAME=\"can_mpd\" -DPACKAGE_TARNAME=\"can_mpd\" -DPACKAGE_VERSION=\"1.13\" -DPACKAGE_STRING=\"can_mpd\ 1.13\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPLATFORM=generic_x86 -I.    -DBUILDSTAMP="\"`date '+%F %T'`\"" -I../dependencies/canmpdconf/1.0/generic_x86/include -I../dependencies/mow2monitor/1.0/generic_x86/include -DGENERIC_X86   -g -ggdb -O0 -Wall -Wl,--verbose -MT can_mpd-serial_can_provider.o -MD -MP -MF .deps/can_mpd-serial_can_provider.Tpo -c -o can_mpd-serial_can_provider.o `test -f 'provider/serial_can_provider.cpp' || echo './'`provider/serial_can_provider.cpp
mv -f .deps/can_mpd-serial_can_provider.Tpo .deps/can_mpd-serial_can_provider.Po
i686-linux-gnu-g++ -DPACKAGE_NAME=\"can_mpd\" -DPACKAGE_TARNAME=\"can_mpd\" -DPACKAGE_VERSION=\"1.13\" -DPACKAGE_STRING=\"can_mpd\ 1.13\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPLATFORM=generic_x86 -I.    -DBUILDSTAMP="\"`date '+%F %T'`\"" -I../dependencies/canmpdconf/1.0/generic_x86/include -I../dependencies/mow2monitor/1.0/generic_x86/include -DGENERIC_X86   -g -ggdb -O0 -Wall -Wl,--verbose -MT can_mpd-komodo_can_provider.o -MD -MP -MF .deps/can_mpd-komodo_can_provider.Tpo -c -o can_mpd-komodo_can_provider.o `test -f 'provider/komodo_can_provider.cpp' || echo './'`provider/komodo_can_provider.cpp
mv -f .deps/can_mpd-komodo_can_provider.Tpo .deps/can_mpd-komodo_can_provider.Po
i686-linux-gnu-gcc -DPACKAGE_NAME=\"can_mpd\" -DPACKAGE_TARNAME=\"can_mpd\" -DPACKAGE_VERSION=\"1.13\" -DPACKAGE_STRING=\"can_mpd\ 1.13\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPLATFORM=generic_x86 -I.     -g -O2 -MT komodo.o -MD -MP -MF .deps/komodo.Tpo -c -o komodo.o `test -f 'can/komodo/komodo.c' || echo './'`can/komodo/komodo.c
mv -f .deps/komodo.Tpo .deps/komodo.Po
i686-linux-gnu-g++ -DBUILDSTAMP="\"`date '+%F %T'`\"" -I../dependencies/canmpdconf/1.0/generic_x86/include -I../dependencies/mow2monitor/1.0/generic_x86/include -DGENERIC_X86   -g -ggdb -O0 -Wall -Wl,--verbose -L../dependencies/canmpdconf/1.0/generic_x86/lib -L../dependencies/mow2monitor/1.0/generic_x86/lib -Wl,--verbose -o can_mpd can_mpd-can_mpd.o can_mpd-mpd_can.o can_mpd-mpd_multiplexing.o can_mpd-serial_can_provider.o can_mpd-komodo_can_provider.o komodo.o   -lcanmpdconf -lmow2monitor -lpthread -ldl 
GNU ld (GNU Binutils for Ubuntu) 2.23.52.20130913
  Supported emulations:
   elf_i386
   i386linux
   elf32_x86_64
   elf_x86_64
   elf_l1om
   elf_k1om
   i386pep
   i386pe
GNU ld (GNU Binutils for Ubuntu) 2.23.52.20130913
  Supported emulations:
   elf_i386
   i386linux
   elf32_x86_64
   elf_x86_64
   elf_l1om
   elf_k1om
   i386pep
   i386pe
using internal linker script:
==================================================
/* Script for -z combreloc: combine and sort reloc sections */
OUTPUT_FORMAT("elf32-i386", "elf32-i386",
          "elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_start)
SEARCH_DIR("/usr/i686-linux-gnu/lib32"); SEARCH_DIR("=/usr/local/lib32"); SEARCH_DIR("=/lib32"); SEARCH_DIR("=/usr/lib32"); SEARCH_DIR("=/usr/local/lib/i386-linux-gnu"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib/i386-linux-gnu"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib/i386-linux-gnu"); SEARCH_DIR("=/usr/lib");
SECTIONS
{
  /* Read-only sections, merged into text segment: */
  PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x08048000)); . = SEGMENT_START("text-segment", 0x08048000) + SIZEOF_HEADERS;
  .interp         : { *(.interp) }
  .note.gnu.build-id : { *(.note.gnu.build-id) }
  .hash           : { *(.hash) }
  .gnu.hash       : { *(.gnu.hash) }
  .dynsym         : { *(.dynsym) }
  .dynstr         : { *(.dynstr) }
  .gnu.version    : { *(.gnu.version) }
  .gnu.version_d  : { *(.gnu.version_d) }
  .gnu.version_r  : { *(.gnu.version_r) }
  .rel.dyn        :
    {
      *(.rel.init)
      *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
      *(.rel.fini)
      *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
      *(.rel.data.rel.ro .rel.data.rel.ro.* .rel.gnu.linkonce.d.rel.ro.*)
      *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
      *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
      *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
      *(.rel.ctors)
      *(.rel.dtors)
      *(.rel.got)
      *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
      *(.rel.ifunc)
    }
  .rel.plt        :
    {
      *(.rel.plt)
      PROVIDE_HIDDEN (__rel_iplt_start = .);
      *(.rel.iplt)
      PROVIDE_HIDDEN (__rel_iplt_end = .);
    }
  .init           :
  {
    KEEP (*(SORT_NONE(.init)))
  }
  .plt            : { *(.plt) *(.iplt) }
  .text           :
  {
    *(.text.unlikely .text.*_unlikely .text.unlikely.*)
    *(.text.exit .text.exit.*)
    *(.text.startup .text.startup.*)
    *(.text.hot .text.hot.*)
    *(.text .stub .text.* .gnu.linkonce.t.*)
    /* .gnu.warning sections are handled specially by elf32.em.  */
    *(.gnu.warning)
  }
  .fini           :
  {
    KEEP (*(SORT_NONE(.fini)))
  }
  PROVIDE (__etext = .);
  PROVIDE (_etext = .);
  PROVIDE (etext = .);
  .rodata         : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
  .rodata1        : { *(.rodata1) }
  .eh_frame_hdr : { *(.eh_frame_hdr) }
  .eh_frame       : ONLY_IF_RO { KEEP (*(.eh_frame)) }
  .gcc_except_table   : ONLY_IF_RO { *(.gcc_except_table
  .gcc_except_table.*) }
  /* These sections are generated by the Sun/Oracle C++ compiler.  */
  .exception_ranges   : ONLY_IF_RO { *(.exception_ranges
  .exception_ranges*) }
  /* Adjust the address for the data segment.  We want to adjust up to
     the same address within the page on the next page up.  */
  . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
  /* Exception handling  */
  .eh_frame       : ONLY_IF_RW { KEEP (*(.eh_frame)) }
  .gcc_except_table   : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
  .exception_ranges   : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) }
  /* Thread Local Storage sections  */
  .tdata      : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
  .tbss       : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
  .preinit_array     :
  {
    PROVIDE_HIDDEN (__preinit_array_start = .);
    KEEP (*(.preinit_array))
    PROVIDE_HIDDEN (__preinit_array_end = .);
  }
  .init_array     :
  {
    PROVIDE_HIDDEN (__init_array_start = .);
    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
    KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
    PROVIDE_HIDDEN (__init_array_end = .);
  }
  .fini_array     :
  {
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
    KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
    PROVIDE_HIDDEN (__fini_array_end = .);
  }
  .ctors          :
  {
    /* gcc uses crtbegin.o to find the start of
       the constructors, so we make sure it is
       first.  Because this is a wildcard, it
       doesn't matter if the user does not
       actually link against crtbegin.o; the
       linker won't look for a file to match a
       wildcard.  The wildcard also means that it
       doesn't matter which directory crtbegin.o
       is in.  */
    KEEP (*crtbegin.o(.ctors))
    KEEP (*crtbegin?.o(.ctors))
    /* We don't want to include the .ctor section from
       the crtend.o file until after the sorted ctors.
       The .ctor section from the crtend file contains the
       end of ctors marker and it must be last */
    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
    KEEP (*(SORT(.ctors.*)))
    KEEP (*(.ctors))
  }
  .dtors          :
  {
    KEEP (*crtbegin.o(.dtors))
    KEEP (*crtbegin?.o(.dtors))
    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
    KEEP (*(SORT(.dtors.*)))
    KEEP (*(.dtors))
  }
  .jcr            : { KEEP (*(.jcr)) }
  .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
  .dynamic        : { *(.dynamic) }
  .got            : { *(.got) *(.igot) }
  . = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 12 ? 12 : 0, .);
  .got.plt        : { *(.got.plt)  *(.igot.plt) }
  .data           :
  {
    *(.data .data.* .gnu.linkonce.d.*)
    SORT(CONSTRUCTORS)
  }
  .data1          : { *(.data1) }
  _edata = .; PROVIDE (edata = .);
  . = .;
  __bss_start = .;
  .bss            :
  {
   *(.dynbss)
   *(.bss .bss.* .gnu.linkonce.b.*)
   *(COMMON)
   /* Align here to ensure that the .bss section occupies space up to
      _end.  Align after .bss to ensure correct alignment even if the
      .bss section disappears because there are no input sections.
      FIXME: Why do we need it? When there is no .bss section, we don't
      pad the .data section.  */
   . = ALIGN(. != 0 ? 32 / 8 : 1);
  }
  . = ALIGN(32 / 8);
  . = SEGMENT_START("ldata-segment", .);
  . = ALIGN(32 / 8);
  _end = .; PROVIDE (end = .);
  . = DATA_SEGMENT_END (.);
  /* Stabs debugging sections.  */
  .stab          0 : { *(.stab) }
  .stabstr       0 : { *(.stabstr) }
  .stab.excl     0 : { *(.stab.excl) }
  .stab.exclstr  0 : { *(.stab.exclstr) }
  .stab.index    0 : { *(.stab.index) }
  .stab.indexstr 0 : { *(.stab.indexstr) }
  .comment       0 : { *(.comment) }
  /* DWARF debug sections.
     Symbols in the DWARF debugging sections are relative to the beginning
     of the section so we begin them at 0.  */
  /* DWARF 1 */
  .debug          0 : { *(.debug) }
  .line           0 : { *(.line) }
  /* GNU DWARF 1 extensions */
  .debug_srcinfo  0 : { *(.debug_srcinfo) }
  .debug_sfnames  0 : { *(.debug_sfnames) }
  /* DWARF 1.1 and DWARF 2 */
  .debug_aranges  0 : { *(.debug_aranges) }
  .debug_pubnames 0 : { *(.debug_pubnames) }
  /* DWARF 2 */
  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
  .debug_abbrev   0 : { *(.debug_abbrev) }
  .debug_line     0 : { *(.debug_line .debug_line.* .debug_line_end ) }
  .debug_frame    0 : { *(.debug_frame) }
  .debug_str      0 : { *(.debug_str) }
  .debug_loc      0 : { *(.debug_loc) }
  .debug_macinfo  0 : { *(.debug_macinfo) }
  /* SGI/MIPS DWARF 2 extensions */
  .debug_weaknames 0 : { *(.debug_weaknames) }
  .debug_funcnames 0 : { *(.debug_funcnames) }
  .debug_typenames 0 : { *(.debug_typenames) }
  .debug_varnames  0 : { *(.debug_varnames) }
  /* DWARF 3 */
  .debug_pubtypes 0 : { *(.debug_pubtypes) }
  .debug_ranges   0 : { *(.debug_ranges) }
  /* DWARF Extension.  */
  .debug_macro    0 : { *(.debug_macro) }
  .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
  /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
}


==================================================
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o succeeded
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crti.o succeeded
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crti.o
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/crtbegin.o succeeded
/usr/lib/gcc/i686-linux-gnu/4.8/crtbegin.o
attempt to open can_mpd-can_mpd.o succeeded
can_mpd-can_mpd.o
attempt to open can_mpd-mpd_can.o succeeded
can_mpd-mpd_can.o
attempt to open can_mpd-mpd_multiplexing.o succeeded
can_mpd-mpd_multiplexing.o
attempt to open can_mpd-serial_can_provider.o succeeded
can_mpd-serial_can_provider.o
attempt to open can_mpd-komodo_can_provider.o succeeded
can_mpd-komodo_can_provider.o
attempt to open komodo.o succeeded
komodo.o
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libcanmpdconf.so succeeded
-lcanmpdconf (../dependencies/canmpdconf/1.0/generic_x86/lib/libcanmpdconf.so)
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libmow2monitor.so failed
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libmow2monitor.a failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libmow2monitor.so succeeded
-lmow2monitor (../dependencies/mow2monitor/1.0/generic_x86/lib/libmow2monitor.so)
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libpthread.so failed
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libpthread.a failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libpthread.so failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libpthread.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libpthread.so failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libpthread.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libpthread.so succeeded
opened script file /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libpthread.so
opened script file /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libpthread.so
attempt to open /lib/i386-linux-gnu/libpthread.so.0 succeeded
/lib/i386-linux-gnu/libpthread.so.0
attempt to open /usr/lib/i386-linux-gnu/libpthread_nonshared.a succeeded
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libdl.so failed
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libdl.a failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libdl.so failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libdl.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libdl.so failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libdl.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libdl.so succeeded
-ldl (/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libdl.so)
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libstdc++.so failed
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libstdc++.a failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libstdc++.so failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libstdc++.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libstdc++.so succeeded
-lstdc++ (/usr/lib/gcc/i686-linux-gnu/4.8/libstdc++.so)
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libm.so failed
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libm.a failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libm.so failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libm.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libm.so failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libm.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libm.so succeeded
-lm (/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libm.so)
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libgcc_s.so failed
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libgcc_s.a failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libgcc_s.so failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libgcc_s.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libgcc_s.so succeeded
-lgcc_s (/usr/lib/gcc/i686-linux-gnu/4.8/libgcc_s.so)
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libgcc.so failed
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libgcc.a failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libgcc.so failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libgcc.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libgcc.so failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libgcc.a succeeded
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libc.so failed
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libc.a failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libc.so failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libc.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libc.so failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libc.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libc.so succeeded
opened script file /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libc.so
opened script file /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libc.so
attempt to open /lib/i386-linux-gnu/libc.so.6 succeeded
/lib/i386-linux-gnu/libc.so.6
attempt to open /usr/lib/i386-linux-gnu/libc_nonshared.a succeeded
(/usr/lib/i386-linux-gnu/libc_nonshared.a)elf-init.oS
(/usr/lib/i386-linux-gnu/libc_nonshared.a)atexit.oS
attempt to open /lib/i386-linux-gnu/ld-linux.so.2 succeeded
/lib/i386-linux-gnu/ld-linux.so.2
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libgcc_s.so failed
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libgcc_s.a failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libgcc_s.so failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libgcc_s.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libgcc_s.so succeeded
-lgcc_s (/usr/lib/gcc/i686-linux-gnu/4.8/libgcc_s.so)
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libgcc.so failed
attempt to open ../dependencies/canmpdconf/1.0/generic_x86/lib/libgcc.a failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libgcc.so failed
attempt to open ../dependencies/mow2monitor/1.0/generic_x86/lib/libgcc.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libgcc.so failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libgcc.a succeeded
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/crtend.o succeeded
/usr/lib/gcc/i686-linux-gnu/4.8/crtend.o
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crtn.o succeeded
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crtn.o
ld-linux.so.2 needed by /lib/i386-linux-gnu/libpthread.so.0
found ld-linux.so.2 at /lib/i386-linux-gnu/ld-linux.so.2
libm.so.6 needed by /usr/lib/gcc/i686-linux-gnu/4.8/libstdc++.so
found libm.so at /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libm.so
make[1]: Leaving directory `/home/amarshall3/workspace/can_mpd/src'
can_mpd-can_mpd.o: In function `main':
/home/amarshall3/workspace/can_mpd/src/can_mpd.cpp:180: undefined reference to  `GetCanMpdConfig(CAN_MPD_CONFIG*, unsigned int*)'
collect2: error: ld returned 1 exit status
make[1]: *** [can_mpd] Error 1
make: *** [all-recursive] Error 1

我还验证了该库适用于正确的平台 (x86),因此格式正确。我还验证了它确实包含所需的符号 (GetCanMpdConfig) 以及 nm 的输出:

0000305c B __bss_start
0000305c b completed.6608
         w __cxa_finalize@@GLIBC_2.1.3
00000940 t deregister_tm_clones
000009d0 t __do_global_dtors_aux
00002e88 t __do_global_dtors_aux_fini_array_entry
00003058 d __dso_handle
00002ee4 d _DYNAMIC
0000305c D _edata
00003060 B _end
         U __errno_location@@GLIBC_2.0
00002ea0 d Errors
         U fclose@@GLIBC_2.1
         U fgets@@GLIBC_2.0
00001184 T _fini
         U fopen@@GLIBC_2.1
         U __fprintf_chk@@GLIBC_2.3.4
00000a20 t frame_dummy
00002e84 t __frame_dummy_init_array_entry
000014e8 r __FRAME_END__
00000ef0 T GetCanMpdConfError
00000b60 T GetCanMpdConfig
00000a60 T GetCanMpdConfVersion
         U GetConfigFilePath
00003000 d _GLOBAL_OFFSET_TABLE_
         w __gmon_start__
00002ec0 d Handlers
000007c4 T _init
         w _ITM_deregisterTMCloneTable
         w _ITM_registerTMCloneTable
00002e8c d __JCR_END__
00002e8c d __JCR_LIST__
         w _Jv_RegisterClasses
00000f20 T read_provider_type
000010c0 T read_serial_baud
00001010 T read_serial_device
00000980 t register_tm_clones
00000a80 T SetCanMpdConfig
         U __stack_chk_fail@@GLIBC_2.4
00001170 t __stack_chk_fail_local
         U strchr@@GLIBC_2.0
         U strlen@@GLIBC_2.0
         U strncmp@@GLIBC_2.0
         U strncpy@@GLIBC_2.0
         U strtol@@GLIBC_2.0
0000305c d __TMC_END__
00000f90 T write_provider_type
00001110 T write_serial_baud
00001060 T write_serial_device
00000930 t __x86.get_pc_thunk.bx
00000f18 t __x86.get_pc_thunk.cx
         U __xstat@@GLIBC_2.0

总结一下: 1) gcc 命令中的链接顺序是正确的(-llibname 在-o blah.cpp 之后) 2)链接器找到库(libcanmpdconf.so) 3) 库的格式适合平台 (x86) 4) 库包含符号(见 nm 输出)

据我所知,应该没有理由对链接器可以找到的明确存在于我的库中的任何符号有一个 undefined reference 。有没有人知道我可以尝试解决此问题或可能有什么问题的任何其他方法?

最佳答案

你会不会遇到一个

extern "C" 

问题?

关于c++ - gcc undefined reference 即使 ld 找到库并且它包含所需的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22601051/

相关文章:

c - C89 中的 {0} 初始值设定项的标准如何?

c - Makefile 和 "relocation has invalid symbol index"错误

linux - 静态库中的填充函数

c++ - 从 Linux-Windows 交叉编译,stdio 具有 undefined reference (对 __imp___acrt_iob_func)

c++ - 错误消息 : "Resource ExperimentFrame.res not found"

c++ - 如何使用 C++ 创建文件的拷贝

c++ - WM_VSCROLL 后滚动条向后移动

c++ - 声明一个指向 void* 二维数组的指针

c++ - 在/正在为 GCC 开发中是否有 `clang++:-Wunused-lambda-capture` 等效警告?

c++ - 在 Visual Studio C++ 2008 Express 中使用 Boost Asio 构建应用程序时出现链接器错误