Haxe-创建C ++独立可执行文件 [英] Haxe - Create a C++ Stand-alone executable

查看:179
本文介绍了Haxe-创建C ++独立可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个haxe程序,试图与远程服务器通信.我能够成功编译到C ++目标.可执行文件在我的系统上运行得很好.但是,当我尝试在另一个Windows框上运行该命令时,它失败并显示以下错误

I have written a haxe program that tries to communicate with a remote server. I was able to compile to the C++ target successfully. The executable runs just fine on my system. However, when I try to run the same on another windows box, it fails with the following error

错误:无法加载模块std @ socket_init__0

然后,我安装了haxe和hxcpp,它们就像一个咒语一样工作.我能够运行该exe.我现在知道对hxcpp有依赖性.

I then installed haxe and hxcpp which worked like a charm. I was able to run the exe. I understand now that there is dependency on hxcpp.

那还是不能解决我的问题,因为我想创建一个独立的应用程序.经过一番研究后,我发现了一个文件(ExampleMain.CPP),其中包含以下说明,我认为这可以解决我的问题.但是,我是新手,不太了解.有人可以带我走过去吗?谢谢

That still did not solve my problem as I want to create a stand-alone application. After some research I found a file (ExampleMain.CPP) with the following instructions that I think might solve my problem. However, I am a novice and do not quite follow. Can some one walk me through with this? Thanks

ExampleMain.CPP

这是示例主线,可用于链接静态版本. 首先,您需要使用以下命令构建标准库的静态版本:

This is an example mainline that can be used to link a static version. First you need to build the static version of the standard libs, with:

运行时$ cd $ HXCPP

haxelib运行hxcpp BuildLibs.xml -Dstatic_link

然后使用(请注意:"static_link"之前的多余空间)应用程序的静态版本:

Then the static verion of your application with (note: extra space before 'static_link'):

haxe -main YourMain -cpp cpp -D static_link

然后,您需要将以上库与此主程序(或修改后的版本)链接. 您可以选择创建一个VisualStudio项目,然后从中添加库. $ HXCPP/bin/Windows/(std,regexp,zlib).lib和您的应用程序库.

You then need to link the above libraries with this (or a modified version) main. You may choose to create a VisualStudio project, and add the libraries from $HXCPP/bin/Windows/(std,regexp,zlib).lib and your application library.

还请注意,如果使用-debug标志进行编译,则库将具有不同的名称.

Note also, that if you compile with the -debug flag, your library will have a different name.

从Windows的命令行链接(仅调试版本才需要user32.lib):

Linking from the command line for windows (user32.lib only required for debug version):

cl ExampleMain.cpp cpp/YourMain.lib $ HXCPP/bin/Windows/std.lib $ HXCPP/bin/Windows/zlib.lib $ HXCPP/bin/Windows/regexp .lib user32.lib

在其他操作系统上,compile + link命令将有所不同.这是Mac版的一个:

From other OSs, the compile+link command will be different. Here is one for mac:

g ++ ExampleMain.cpp cpp/Test-debug.a $ HXCPP/bin/Mac/regexp.a $ HXCPP/bin/Mac/std.a $ HXCPP/bin/Mac /zlib.a

如果您希望添加这3个静态库(例如nme),则将 需要使用"-Dstatic_link"编译它们.同样标记,然后将其称为"register_prims" 初始化调用.包含额外的静态库将需要该库 在链接行中,并且可能需要链接其他依赖项. 另请注意,静态链接可能会涉及许可问题 第三方库.

If you wish to add other static libraries besides these 3 (eg, nme) you will need to compile these with the "-Dstatic_link" flag too, and call their "register_prims" init call. The inclusion of the extra static library will require the library in the link line, and may requires additional dependencies to be linked. Also note, that there may be licensing implications with static linking thirdparty libraries.

推荐答案

我不确定,但是看来您正在采取hxcpp为您执行的相同的额外步骤.当您编译独立应用程序时,它实际上是独立的,并且本身并不依赖于hxcpp-但是它依赖于您可能使用过的hxcpp中的标准库.例如,如前所述,如果您使用正则表达式,则将需要hxcpp具有的regexp.dll. haxe标准库位于std.dll中,而zlib如果您使用的是zip压缩包,则为zlib.

I'm not sure, but it seems that you are taking the same extra steps hxcpp does for you already. When you compile your standalone application it is actually standalone and doesn't have a dependency on hxcpp per se - but it has a dependency on the standard libraries within hxcpp you may have used. For instance, if you use regular expressions, you will need the regexp.dll that hxcpp has for it, as you noted. The haxe standard library is in the std.dll and the zlib is if you used compression from the zip packages.

如果我没记错的话,默认是动态引用这些组件.为了使您的应用程序像您建议的那样独立,您只需要将这些dll复制到二进制文件中即可.

If I am not mistaken, the default is to reference these components dynamically. In order for your application to be standalone as you suggest, you simply have to copy these dll's alongside your binary.

如果要从haxe代码自动静态链接到这些库组件,只需import

If you want to link to these library components statically, automatically from your haxe code, just import the types from the cpp.link package. This instructs hxcpp to automatically bring its libraries as part of the compilation, linking it statically into your binary instead of dynamically. No extra steps are necessary!

简短答案:将import cpp.link.StaticStd;和链接包中的任何其他库组件添加到您的代码中.只要导入,它就可以在任何地方,它将被链接进来.

Short answer: add import cpp.link.StaticStd; and any other library components in the link package somewhere to your code. It can be anywhere as long as it's imported, it will be linked in.

这篇关于Haxe-创建C ++独立可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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