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

如何解决Antix Linux(Debian12)下Code::Blocks的LD_LIBRARY_PATH问题

在AntiX Linux(Debian 12 Bookworm)上Code::Blocks运行程序失败的问题

我在AntiX Linux(Debian 12 Bookworm)上使用Code::Blocks,运行以下简单的Hello World程序:

#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;
}

该程序在控制台手动运行完全正常,但在Code::Blocks中运行时,Build过程成功,但Run环节报错,输出如下:

-------------- Build: Debug in test (compiler: GNU GCC Compiler)---------------

g++ -L/usr/local/lib/x86_64-linux-gnu -L"-static-libgcc -static-libstdc++" -o bin/Debug/test obj/Debug/main.o   
Output file is bin/Debug/test with size 30.12 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 

-------------- Run: Debug in test (compiler: GNU GCC Compiler)---------------

Checking for existence: /home/Jackie/Documents/test/bin/Debug/test
Set variable: LD_LIBRARY_PATH=.:/usr/local/lib/x86_64-linux-gnu:
Executing: xterm -T test -e /usr/bin/cb_console_runner LD_LIBRARY_PATH=:.:/usr/local/lib/x86_64-linux-gnu /home/Jackie/Documents/test/bin/Debug/test  (in /home/Jackie/Documents/test/.)
Process terminated with status -1 (0 minute(s), 0 second(s))

我试过Code::Blocks论坛里的两种旧方法,但都没解决问题,现在没思路了。


解决方法尝试:

  1. 检查并安装xterm
    在终端执行命令:

    sudo apt install xterm
    

    安装完成后重启Code::Blocks,再次运行程序。

  2. 修改Code::Blocks的终端启动设置
    打开Code::Blocks,依次进入:Settings -> Environment -> General settings -> Terminal to launch console programs
    将默认的xterm -T $TITLE -e替换为系统默认终端调用命令:

    x-terminal-emulator -e
    

    或者AntiX常用的终端:

    lxterminal -e
    

    修改后保存设置,重新运行程序。

  3. 修正编译器链接参数
    看Build命令里的-L"-static-libgcc -static-libstdc++"参数写法错误,-L是指定库路径,而-static-libgcc和-static-libstdc++是链接选项,不应放在-L后:

    • 打开Settings -> Compiler -> Linker settings
    • 在Other linker options中添加:-static-libgcc -static-libstdc++
    • 移除之前错误添加在库路径里的这两个参数,保存设置后重新编译运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 06:17:20