Yes, you can do this.
Check this for a start point: Compiling libraries without main class - Compilation - Haxe programming language cookbook
Also, here is additional information:
HXCPP can create C++ libs as well with -D static_link and -D dll_export
Hope it helps!