dlang调用其他文件中的函数失败 [英] dlang call to function in other file fails

查看:96
本文介绍了dlang调用其他文件中的函数失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试使用D代码
调用其他文件中的函数的问题。我的问题是我收到错误消息,我不理解服务器中的$ b $b。d

I'm testing to make calls to functions in other files using D code My problem is that I receive errors I don't understand in server.d

import std.stdio;
extern (D) void otherFunction();
main(){
otherFunction();}

以及在客户端中。 d

and in client.d

import std.stdio;
void otherFunction(){ writeln("hello world");}

dmd服务器.d呈现此输出错误

"dmd server.d" renders this output error

Undefined symbols for architecture x86_64:
  "_D6server13otherFunctionFZv", referenced from:
      __Dmain in server.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: linker exited with status 1

有什么主意我打不通吗?
哦,我在OS X 10.9上
并且只要函数与main()
/ a

Any ideas why I can't make the call? Oh I'm on OS X 10.9 And the call work as long as the function is in the same file as main() /a

推荐答案

D像C ++一样会破坏所有符号名称。
除非模块名称匹配1:1(您不应该这样做),否则诸如函数之类的符号将不匹配。

D like C++ mangles all symbol names. Unless the module name matches 1:1 (which you shouldn't do) then a symbol such as a function won't match up.

如果确实非常需要此功能,请切换到 extern(C),它会按您的预期工作。

If you really really need this, switch over to extern(C) which work as you're expecting.

这篇关于dlang调用其他文件中的函数失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆