I have spent 2 days on this problem, and still have no idea how to do it.
All I am trying to do is build a program, or rather function, in C that would take in a compressed lzma file, and extract it on Windows. I am doing it with CLion, with Cygwin 64 3.0.1.
Sound easy? Probably, except for the fact that all method I tried just simple does not work.
Let me get this out of the way first that I am not familiar with Cmake, so that is pretty much why I am asking for advice.
Methods I have tried:
1)
Searching many code on github, I simply see them do
#include <lzma.h>
Nice, just does not work on Windows. When I compile, I got the error:
undefined reference to `lzma_stream_decoder'
undefined reference to `lzma_code'
Googling tell me that I am lacking the library for lzma development, and the solution is simply do a sudo apt, and... you guess it: not for Windows.
2)
Maybe it is a Cmake thing, so let's try to compile with simple gcc first. I grab a simple decompress code with #include <lzma.h>
and tried to compile it on Ubuntu. Awesome, everything went smoothly.
Back to Windows, I opened up the Cygwin terminal. Oh of course In Cygwin, I have downloaded liblzma-devel.
Compile is running great to. BUT when firing up the executable:
cygwin1.dll and cyglzma-5.dll are missing
What the... Even when I specifically downloaded those files and put them to the same folder with the executable, it still fails to start correctly.
3)
Back to Clion/Cmake.
I have looked in to the Lzma SDK and no avail. What code should I write to the Cmake file? I cannot find any guide that says how to make use of this in C, let alone compile it using Cmake.
Googling "Cmake Lzma" lead me to the FindLibLZMA, which I have no idea what they are writing about. I still have no clue what line to put into my CmakeList.txt file, like add_library
or find_package
... nope, nothing.
4)
Finally, Xz Utils... the most extensive Lzma tool as far as I can understand, and of course somehow, it also does not work.
I put the file FindLibLZMA.cmake (which I pull down from github) into a folder called Cmake. Then I added
find_package(LibLZMA REQUIRED)
include_directories(${LIBLZMA_INCLUDE_DIRS})
into the CmakeList.txt file. Then I set the LIBLZMA_INCLUDE_DIR
in the FindLibLZMA.cmake file to the folder include of the Xz Utils for Windows... and u guess it, compilation error:
# LIBLZMA_HAS_AUTO_DECODER - True if lzma_auto_decoder() is found (required).
# LIBLZMA_HAS_EASY_ENCODER - True if lzma_easy_encoder() is found (required).
# LIBLZMA_HAS_LZMA_PRESET - True if lzma_lzma_preset() is found (required).
All these library or something are required, yet where are they? The compiler could not find it, so yeah... again, I am stuck.
I have been trying from yesterday, and I am still stuck.
So please, I am very tired now. Any kind soul would tell me how to make the Lzma library work with Cmake on Windows...Please...Please. Thank you!