为什么链接器找不到 tcl/tk?
Why does the linker failed to find tcl/tk?
我正在用 d 语言 测试官方 tcl/tk 示例,但它在链接步骤失败。我在Linux Mint 19 Cinamon 64bit,我至少安装了
- libtcl8.6
- libtk8.6
此外,我正在使用 DUB 版本 1.14.0,构建于 2019 年 4 月 5 日
我去了 tk 绑定页面并按照 Linux 的步骤操作:binding page :
- 安装 tck/tk 8.6 库
- 代码示例的用法
...
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
但是也没用。
我终于成功了!!!
我创建了几个软链接:
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
编译成功
我正在用 d 语言 测试官方 tcl/tk 示例,但它在链接步骤失败。我在Linux Mint 19 Cinamon 64bit,我至少安装了
- libtcl8.6
- libtk8.6
此外,我正在使用 DUB 版本 1.14.0,构建于 2019 年 4 月 5 日
我去了 tk 绑定页面并按照 Linux 的步骤操作:binding page :
- 安装 tck/tk 8.6 库
- 代码示例的用法
...
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
但是也没用。
我终于成功了!!!
我创建了几个软链接:
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
编译成功