[SOLVED]How to use local & global haxelib at the same time?

When I have the .haxelib directory under the project and install some libraries into this repository, I just can’t reference the global library in hxml file and causing some compilation errors.
Is there a way to use both local and global libraries at the same time?
Or there is a way to list dependencies with one-click installation similar to the npm package.json file?which is very convenient for open source projects to share with others for deployment
:thinking:

With haxelib, you can set up links in the local repository to the global libraries using the haxelib dev command, for example:

haxelib dev library-name /global/library/path

Make sure you run this command within your project directory, where the .haxelib directory is found.

If you are unsure what the path is, you can run:

haxelib libpath library-name

This command will tell you where exactly the global install of the library is located, and then you can paste the path into the dev command above.

For easier library installation across systems, you can specify the library versions in your .hxml file, for example:

-lib format:3.5.0

And then install all the libraries required to build the hxml by running haxelib install build.hxml or whatever your hxml is called. For more information see: Per project setup - Haxelib Documentation

However, you may also want to consider the lix project, which gives a more npm like experience for keeping track of library versions: GitHub - lix-pm/lix.client: A dependable package manager for your Haxe projects

1 Like

Thanks for your answer, it was very helpful to me! :grin:
It seems that in haxe 4.2.5, I had to run haxelib libpath library-name --global to print the global library path, and before that, I manually entered the lib path and get compile error for misunderstood the format of the library path. Finally anyway, after a while of fumbling I was able to configure the project library path correctly and successfully compiled!
At the same time, I found that when there is a ./haxelib directory in the project, I have to manually set all the global library path referenced by the project. It looks like it’s not very convenient to use both local and global libraries in a project. Next I’ll check out the lix-pm project

1 Like

Ah yes, for some reason I missed out the --global flag, but it is needed here otherwise haxelib will look in the local .haxelib folder.
Yes, mixing local and global versions is a bit complicated, I would definitely recommend specifying versions in your .hxml or using lix instead.

Thanks for your advice, I will try to use lix :+1:

1 Like