You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

g++代码修改未被gdb/链接器识别的技术求助

环境信息
  • Win 11-64 Pro v24H2
  • Cygwin 3.7.0-0.116
  • g++ 15.1.1
  • gdb 15.2
编译、链接与调试命令

编译目标文件:

g++ -c -g -std=c++11 -o obj/SlipReader.o SlipReader.cpp

生成DLL及导入库:

g++ -shared -o cygslip.dll \
    -Wl,--out-implib=libslip.dll.a \
    -Wl,--export-all-symbols \
    -Wl,--enable-auto-import *.o

生成测试可执行文件:

g++ /usr/local/lib/cygslip.dll *.o -o SlipTest.exe

启动调试:

gdb SlipTest.exe
代码场景说明

SlipReader.h第622行声明SlipReaderCell* reader;用于后续调用,针对currentCell()函数有四种代码场景:

  • 场景1(原代码):SlipReader.h第716行
    SlipCell& currentCell() const {return currentCell(); }
    
    存在无限递归问题。
  • 场景2:修改SlipReader.h第716行
    SlipCell& currentCell() const {return reader->currentCell(); }
    
  • 场景3:在SlipReader.h中插入空行/注释后,上述修改代码位于第719行,内容与场景2一致。
  • 场景4:将函数实现移至cpp文件
    • 头文件SlipReader.h第718行仅声明:SlipCell& currentCell() const;
    • 实现文件SlipReader.cpp第67行:
      SlipCell& currentCell() const {return reader->currentCell(); }
      
问题现象
  1. 场景1、2、3:gdb调试时始终显示场景1的无限递归代码,完全不识别场景2、3的修改,最终因递归调用失败。
  2. 场景4:触发链接器错误:
    /usr/lib/gcc/x86_64-pc-cygwin/15/../../../../x86_64-pc-cygwin/bin/ld: SlipReader.o: in function `std::allocator<char>::~allocator()':
    /cygdrive/e/home/skidmarks/Projects/SLIP/gSlip/SlipReader.cpp:67: multiple definition of `slip::SlipReader::currentCell() const'; SlipHeader.o:/cygdrive/e/home/skidmarks/Projects/SLIP/gSlip/SlipReader.h:716: first defined here
    
    错误信息存在多处异常:
    • 代码中未使用std::allocator
    • SlipReader.h第716行是函数声明而非定义
    • SlipHeader.o并未参与当前编译链接流程
    • 错误行号与实际代码位置不符

已执行重新编译、链接操作,但调试信息及错误提示的行号始终未更新,求解决办法。

内容的提问来源于stack exchange,提问作者lostbits

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 21:18:09