【问题标题】:Why does the linker failed to find tcl/tk?为什么链接器找不到 tcl/tk?
【发布时间】:2019-04-20 03:20:17
【问题描述】:

我正在测试 d 语言 的官方 tcl/tk 示例,但在链接步骤中失败。我在 Linux Mint 19 Cinamon 64bit 上,我至少已经安装了

  • libtcl8.6
  • libtk8.6

另外,我使用的是 DUB 版本 1.14.0,构建于 2019 年 4 月 5 日

我去了 tk 绑定页面并按照 Linux 的步骤操作:binding page

  1. tck/tk 8.6 库的安装
  2. 代码示例的使用
...

class Application : TkdApplication                       // Extend TkdApplication.
{
    private void exitCommand(CommandArgs args)           // Create a callback.
    {
        this.exit();                                     // Exit the application.
    }

    override protected void initInterface()              // Initialise user interface.
    {
        auto frame = new Frame(2, ReliefStyle.groove)    // Create a frame.
            .pack(10);                                   // Place the frame.

        auto label = new Label(frame, "Hello World!")    // Create a label.
            .pack(10);                                   // Place the label.

        auto exitButton = new Button(frame, "Exit")      // Create a button.
            .setCommand(&this.exitCommand)               // Use the callback.
            .pack(10);                                   // Place the button.
    }
}

...

编译输出

$ dub
Performing "debug" build using /usr/bin/dmd for x86_64.
x11 1.0.21: target for configuration "tcltk-import" is up to date.
tcltk 8.6.5: target for configuration "library" is up to date.
tkd 1.1.10: target for configuration "library" is up to date.
hello-user ~master: building configuration "application"...
Linking...
/usr/bin/ld : ne peut trouver -ltcl
/usr/bin/ld : ne peut trouver -ltk
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
/usr/bin/dmd failed with exit code 1.

ne peut trouver”的意思是“找不到”。

这是我的 dub.json

{
    "authors": [
        "laurent bernabe"
    ],
    "copyright": "Copyleft 2019, Laurent Bernabe",
    "description": "Simple user greeting",
    "license": "MIT",
    "name": "hello-user",
    "dependencies": {
        "tkd": "~>1.1.10"
    },
    "postGenerateCommands-windows-x86": [
        "copy $TCLTK_PACKAGE_DIR\\dist\\x86\\tcl86t.dll build\\tcl86t.dll /y",
        "copy $TCLTK_PACKAGE_DIR\\dist\\x86\\tk86t.dll build\\tk86t.dll /y",
        "xcopy $TCLTK_PACKAGE_DIR\\dist\\library build\\library /i /e /y"
    ],
    "postGenerateCommands-windows-x86_64": [
        "copy $TCLTK_PACKAGE_DIR\\dist\\x86_64\\tcl86t.dll build\\tcl86t.dll /y",
        "copy $TCLTK_PACKAGE_DIR\\dist\\x86_64\\tk86t.dll build\\tk86t.dll /y",
        "xcopy $TCLTK_PACKAGE_DIR\\dist\\library build\\library /i /e /y"
    ]
}

同时,我刚刚发现 libtcl8.6.a 和 libtk8.6.a 都在 /usr/lib/x86_64-linux-gnu 下。我试过设置

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu

但它也没有工作。

【问题讨论】:

  • 你提到的链接是关于DWT的,它是SWT移植到D的。DWT不需要TK,它依赖于GTK...你应该更新链接以指向TKD项目。
  • @DejanLekic 谢谢你指出我:我编辑我的问题。

标签: ubuntu tcl d tk


【解决方案1】:

我终于成功了!!!

我创建了几个软链接:

sudo ln -s /usr/lib/x86_64-linux-gnu/libtcl8.6.a /usr/lib/libtcl.a
sudo ln -s /usr/lib/x86_64-linux-gnu/libtk8.6.a /usr/lib/libtk.a
sudo ln -s /usr/lib/x86_64-linux-gnu/libtcl8.6.so /usr/lib/libtcl.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libtk8.6.so /usr/lib/libtk.so

这样运行dub就编译成功了。

【讨论】:

  • 那么……使用-L/usr/lib/x86_64-linux-gnu -ltk8.6 -ltcl8.6?
  • 谢谢。事实上,我还不习惯链接器选项:你的解决方案更好。
猜你喜欢
  • 2010-12-18
  • 1970-01-01
  • 1970-01-01
  • 2017-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-02
相关资源
最近更新 更多