尽管ld找到库并且其中包含所需的函数,但gcc仍然出现未定义引用错误

4
我在许多项目上工作,必须交叉编译一些库,有些是内部的,有些不是。在为我们系统的一个交叉编译应用程序工作时,我必须为我的应用程序导入一些交叉编译的内部库。我在Eclipse中使用autotools进行应用程序开发。无论我是否在Eclipse中,也无论我编译的平台是什么,我的各种版本的gcc都会遇到相同的链接错误。当我编译应用程序时,单独的模块(*.c)编译良好,但当最终gcc命令被发出以将所有内容链接到最终程序中时,我会收到“undefined reference to GetCanMpdConfig”的错误信息。
现在问题来了:链接器实际上找到了文件(我已经通过-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)并且格式正确。同时,我也通过使用nm命令输出来确认它确实包含所需的符号(GetCanMpdConfig):

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命令中的链接顺序正确(在-blah.cpp之后使用-llibname) 2)链接器找到了库(libcanmpdconf.so) 3)库以所在平台的正确格式存在(x86) 4)库包含符号(请参阅nm输出)
就我所知,没有任何理由出现对已经存在于我的库中且链接器可以找到的符号的未定义引用。有人知道我可以尝试排除故障的其他方法或可能存在的问题吗?

通过检查 readelf -a dependencies/canmpdconf/1.0/generic_x86/lib/libcanmpdconf.so 命令的输出来验证共享库文件 libcanmpdconf.so 是否适用于正确的平台。 - Alex Marshall
1个回答

3
你可能面临的问题是IT技术方面的。
extern "C" 

有问题吗?


是的!唉...浪费了太多时间来弄清楚它。你怎么知道的?是我问题中输出的某些内容,还是你随便猜的? - Alex Marshall
我看到你正在编译一个C++文件并链接C文件。链接器给出了缺失函数 "GetCanMpdConfig(CAN_MPD_CONFIG*, unsigned int*)",这表明存在链接问题。如果不是凌晨4点,我会更加确定地给出答案。 - user3344003
我也很累,因為在晚上11點寫完問題後,我花了比我想象中更多的時間來解決問題。我沒有提到我的程序是C++,但庫是用C編譯的,這似乎是一個非常重要的細節。 - Alex Marshall

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接